Functions

/build/buildd/witty-3.1.2/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.

{
  if (boost::iends_with(fileName, ".h")
      || boost::iends_with(fileName, ".C")
      || boost::iends_with(fileName, ".cpp"))
    return "cpp";
  else if (boost::iends_with(fileName, ".xml"))
    return "xml";
  else if (boost::iends_with(fileName, ".html"))
    return "html";
  else if (boost::iends_with(fileName, ".java")) 
    return "java";
  else if (boost::iends_with(fileName, ".css")) 
    return "css";
  else
    return std::string();
} 
std::string readFileToString ( const std::string &  fileName )

Definition at line 79 of file SourceView.C.

{
  std::size_t outputFileSize = (std::size_t)fs::file_size(fileName);
  std::fstream file (fileName.c_str(), std::ios::in | std::ios::binary);
  char* memblock = new char [outputFileSize];
  file.read(memblock, outputFileSize);
  file.close();
  std::string data = std::string(memblock, outputFileSize);
  delete [] memblock;
  return data;
}
std::string tempFileName (  )

Definition at line 46 of file SourceView.C.

{
#ifndef WIN32
  char spool[20];
  strcpy(spool, "/tmp/wtXXXXXX");

  int i = mkstemp(spool);
  close(i);
#else
  char spool[2 * L_tmpnam];
  tmpnam(spool);
#endif
  return std::string(spool);
}

Generated on Sat Dec 4 2010 06:32:31 for Wt by doxygen 1.7.2