Wt examples  3.7.1
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>
#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

◆ getLanguageFromFileExtension()

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

Definition at line 63 of file SourceView.C.

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

◆ readFileToString()

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

Definition at line 83 of file SourceView.C.

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

◆ tempFileName()

std::string tempFileName ( )

Definition at line 48 of file SourceView.C.

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

Generated on Tue Dec 15 2020 for the C++ Web Toolkit (Wt) by doxygen 1.8.13