Wt examples  4.11.3
Functions
SourceView.C File Reference
#include "SourceView.h"
#include <iostream>
#include <fstream>
#include <sstream>
#include <stdlib.h>
#include <boost/algorithm/string.hpp>
#include <boost/version.hpp>
#include <boost/filesystem/convenience.hpp>
#include <boost/filesystem/operations.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 71 of file SourceView.C.

72 {
73  if (boost::iends_with(fileName, ".h")
74  || boost::iends_with(fileName, ".C")
75  || boost::iends_with(fileName, ".cpp"))
76  return "cpp";
77  else if (boost::iends_with(fileName, ".xml"))
78  return "xml";
79  else if (boost::iends_with(fileName, ".html"))
80  return "html";
81  else if (boost::iends_with(fileName, ".java"))
82  return "java";
83  else if (boost::iends_with(fileName, ".js"))
84  return "javascript";
85  else if (boost::iends_with(fileName, ".css"))
86  return "css";
87  else
88  return std::string();
89 }

◆ readFileToString()

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

Definition at line 91 of file SourceView.C.

92 {
93  std::size_t outputFileSize = (std::size_t)fs::file_size(fileName);
94  std::fstream file (fileName.c_str(), std::ios::in | std::ios::binary);
95  char* memblock = new char [outputFileSize];
96  file.read(memblock, (std::streamsize)outputFileSize);
97  file.close();
98  std::string data = std::string(memblock, outputFileSize);
99  delete [] memblock;
100  return data;
101 }

◆ tempFileName()

std::string tempFileName ( )

Definition at line 56 of file SourceView.C.

57 {
58 #ifndef WT_WIN32
59  char spool[20];
60  strcpy(spool, "/tmp/wtXXXXXX");
61 
62  int i = mkstemp(spool);
63  close(i);
64 #else
65  char spool[2 * L_tmpnam];
66  tmpnam(spool);
67 #endif
68  return std::string(spool);
69 }