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

Wt examples 3.3.0

- Main Page
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

Functions
/home/koen/project/wt/public-git/wt/examples/wt-homepage/SourceView.C File Reference
`#include "SourceView.h"`
`#include <iostream>`
`#include <fstream>`
`#include <sstream>`
`#include <stdlib.h>`
`#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 63 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, ".js"))
        return "javascript";
      else if (boost::iends_with(fileName, ".css"))
        return "css";
      else
        return std::string();
    }

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

Definition at line 83 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, (std::streamsize)outputFileSize);
      file.close();
      std::string data = std::string(memblock, outputFileSize);
      delete [] memblock;
      return data;
    }

std::string tempFileName | ( |  | ) |

Definition at line 48 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);
    }