Menu

[6d9522]: / examples / mist_gen / src / Common.cpp  Maximize  Restore  History

Download this file

51 lines (38 with data), 1.2 kB

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
// Implementation of common and utility stuff
#include <sstream>
#include <cassert>
#include "Common.h"
using namespace std;
///////////////////////////////////////////////////////////////////////
// Strings
const string lineString = "line";
// Whitespace characters
extern const string whitespaceList = " \t\n\r\v\a\b\f";
// Names of the "document" and "block" groups
extern const string documentGroupName = "document";
extern const string blockGroupName = "block";
///////////////////////////////////////////////////////////////////////
void
trimString(std::string& s)
{
if (s.length() == 0) {
return;
}
string::size_type beg = s.find_first_not_of(whitespaceList);
if (beg == string::npos) {
// the string consists entirely of whitespace characters
s.clear();
return;
}
string::size_type end = s.find_last_not_of(whitespaceList);
string t(s, beg, end - beg + 1);
s.swap(t);
return;
}
std::string
formatErrorMessage(int lineNumber, const std::string & text)
{
ostringstream err;
err << lineString << " " << lineNumber << ": " << text;
return err.str();
}