Newer
Older
* Copyright (c) 2012, OpenGeoSys Community (http://www.opengeosys.com)
* Distributed under a Modified BSD License.
* See accompanying file LICENSE.txt or
* http://www.opengeosys.com/LICENSE.txt
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
*/
#include "StringTools.h"
std::list<std::string> splitString(const std::string &str, char delim)
{
std::list<std::string> strList;
std::stringstream ss(str);
std::string item;
while(getline(ss, item, delim)) {
strList.push_back(item);
}
return strList;
}
std::string replaceString(const std::string &searchString, const std::string &replaceString, std::string stringToReplace)
{
std::string::size_type pos = stringToReplace.find(searchString, 0);
int intLengthSearch = searchString.length();
while (std::string::npos != pos) {
stringToReplace.replace(pos, intLengthSearch, replaceString);
pos = stringToReplace.find(searchString, 0);
}
return stringToReplace;
}
void trim(std::string &str, char ch)
{
std::string::size_type pos = str.find_last_not_of(ch);
if(pos != std::string::npos)
{
str.erase(pos + 1);
pos = str.find_first_not_of(ch);
if(pos != std::string::npos) str.erase(0, pos);
}
else str.erase(str.begin(), str.end());
}
#ifdef MSVC
void correctScientificNotation(std::string filename, size_t precision)
{
std::ifstream stream;
std::ofstream outputStream;
stream.open(filename.c_str());
std::string tmpFilename = filename + ".tmp";
outputStream.open(tmpFilename.c_str());
if (!stream)
{
std::cout << "correctScientificNotation: fstream is not open" << std::endl;
return;
}
std::string line;
// Iterate over lines in stream
while (getline(stream, line))
{
std::string word;
std::istringstream iss(line);
// Iterate over all words in line
while (iss >> word)
{
// Search for e+0
std::size_t exponentPosition = word.find("e+0", precision);
if (exponentPosition == std::string::npos)
// If not found search for e-0
exponentPosition = word.find("e-0", precision);
if (exponentPosition != std::string::npos)
{
std::size_t wordSize = word.size();
std::size_t exponentSize = wordSize - exponentPosition;
if(exponentSize > 4)
{
// Erase the leading zero considering trailing characters
int i = wordSize - 1;
while (!isdigit(word[i]))
--i;
size_t erasePos = wordSize - 3 - (wordSize - 1 - i);
std::string eraseString = word.substr(erasePos, 1);
if (eraseString.find("0") != std::string::npos)
word.erase(erasePos, 1);
}
}
outputStream << word << " ";
}
outputStream << std::endl;
}
stream.close();
outputStream.close();
remove(filename.c_str());
rename(tmpFilename.c_str(), filename.c_str());
}
#endif