Wt examples  4.10.4
Functions
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.h>
#include <Wt/WText.h>
#include <Wt/WImage.h>

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

◆ getLanguageFromFileExtension()

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

Definition at line 65 of file SourceView.C.

66 {
67  if (boost::iends_with(fileName, ".h")
68  || boost::iends_with(fileName, ".C")
69  || boost::iends_with(fileName, ".cpp"))
70  return "cpp";
71  else if (boost::iends_with(fileName, ".xml"))
72  return "xml";
73  else if (boost::iends_with(fileName, ".html"))
74  return "html";
75  else if (boost::iends_with(fileName, ".java"))
76  return "java";
77  else if (boost::iends_with(fileName, ".js"))
78  return "javascript";
79  else if (boost::iends_with(fileName, ".css"))
80  return "css";
81  else
82  return std::string();
83 }

◆ readFileToString()

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

Definition at line 85 of file SourceView.C.

86 {
87  std::size_t outputFileSize = (std::size_t)fs::file_size(fileName);
88  std::fstream file (fileName.c_str(), std::ios::in | std::ios::binary);
89  char* memblock = new char [outputFileSize];
90  file.read(memblock, (std::streamsize)outputFileSize);
91  file.close();
92  std::string data = std::string(memblock, outputFileSize);
93  delete [] memblock;
94  return data;
95 }

◆ tempFileName()

std::string tempFileName ( )

Definition at line 50 of file SourceView.C.

51 {
52 #ifndef WT_WIN32
53  char spool[20];
54  strcpy(spool, "/tmp/wtXXXXXX");
55 
56  int i = mkstemp(spool);
57  close(i);
58 #else
59  char spool[2 * L_tmpnam];
60  tmpnam(spool);
61 #endif
62  return std::string(spool);
63 }