/home/koen/project/wt/public-git/wt/examples/wt-homepage/SourceView.C File Reference

#include "SourceView.h"
#include <iostream>
#include <fstream>
#include <sstream>
#include <boost/algorithm/string.hpp>
#include <boost/filesystem/operations.hpp>
#include <boost/filesystem/convenience.hpp>
#include <Wt/WApplication>
#include <Wt/WText>
#include <Wt/WImage>

Go to the source code of this file.

Functions

std::string tempFileName ()
std::string getLanguageFromFileExtension (const std::string &fileName)
std::string readFileToString (const std::string &fileName)


Function Documentation

std::string getLanguageFromFileExtension ( const std::string &  fileName  ) 

Definition at line 61 of file SourceView.C.

00062 {
00063   if (boost::iends_with(fileName, ".h")
00064       || boost::iends_with(fileName, ".C")
00065       || boost::iends_with(fileName, ".cpp"))
00066     return "cpp";
00067   else if (boost::iends_with(fileName, ".xml"))
00068     return "xml";
00069   else if (boost::iends_with(fileName, ".html"))
00070     return "html";
00071   else if (boost::iends_with(fileName, ".java")) 
00072     return "java";
00073   else if (boost::iends_with(fileName, ".js")) 
00074     return "javascript";
00075   else if (boost::iends_with(fileName, ".css")) 
00076     return "css";
00077   else
00078     return std::string();
00079 } 

std::string readFileToString ( const std::string &  fileName  ) 

Definition at line 81 of file SourceView.C.

00082 {
00083   std::size_t outputFileSize = (std::size_t)fs::file_size(fileName);
00084   std::fstream file (fileName.c_str(), std::ios::in | std::ios::binary);
00085   char* memblock = new char [outputFileSize];
00086   file.read(memblock, outputFileSize);
00087   file.close();
00088   std::string data = std::string(memblock, outputFileSize);
00089   delete [] memblock;
00090   return data;
00091 }

std::string tempFileName (  ) 

Definition at line 46 of file SourceView.C.

00047 {
00048 #ifndef WIN32
00049   char spool[20];
00050   strcpy(spool, "/tmp/wtXXXXXX");
00051 
00052   int i = mkstemp(spool);
00053   close(i);
00054 #else
00055   char spool[2 * L_tmpnam];
00056   tmpnam(spool);
00057 #endif
00058   return std::string(spool);
00059 }


Generated on Thu May 20 18:14:56 2010 for Wt by doxygen 1.5.6