4#include "facilities/Util.h"
10 std::string name = std::string(
"${GLAST_EXT}/xerces");
11 std::string nameAgain = std::string(
"${GLAST_EXT}/xerces");
12 std::string oDelim = std::string (
"${");
13 std::string cDelim = std::string (
"}");
16 std::cout <<
"Test expandEnvVar: " << std::endl;
19 std::cout <<
"Translated name (right delimiters) is "
22 std::cout <<
"Translated name (wrong delimiters) is "
23 << nameAgain << std::endl;
26 std::cout <<
"Failed to completely translate " << name << std::endl;
32 std::string multi = std::string(
"$(FACILITIESROOT)/$(SRC)");
37 std::cout <<
"Translated name is " << multi << std::endl;
38 std::cout << ntrans <<
" variables were translated." << std::endl;
41 std::cout <<
"Failed to completely translate " << multi << std::endl;
44 std::cout << std::endl <<
"Test itoa " << std::endl;
48 std::cout <<
"My String is " << intStr << std::endl;
51 std::string unixname(
"/a/path/myUnixFile.txt");
52 std::string wname(
"C:\\a\\longer\\path\\myWindowsFile.txt");
54 std::vector<std::string> tokens;
57 std::cout << std::endl <<
"Test stringTokenize and basename" << std::endl;
60 std::cout <<
"Processing string " << unixname << std::endl;
61 for (i = 0; i < tokens.size(); i++) {
62 std::cout <<
"Token " << i <<
" is: " << tokens[i] << std::endl;
69 std::cout <<
"Processing string " << wname << std::endl;
70 for (i = 0; i < tokens.size(); i++) {
71 std::cout <<
"Token " << i <<
" is: " << tokens[i] << std::endl;
77 std::cout << std::endl <<
"Test keyValueTokenize " << std::endl;
78 std::string input1(
"apple=green,lemon=yellow,blueberry=blue");
79 std::cout <<
"Input string: '" << input1 <<
"'" << std::endl;
80 std::map<std::string,std::string> maptokens;
82 std::map<std::string,std::string>::const_iterator tokens_itr=maptokens.begin();
83 while (tokens_itr!=maptokens.end()) {
84 std::cout <<
"Token key " <<(*tokens_itr).first <<
" and value: "
85 << (*tokens_itr).second << std::endl;
89 std::cout <<
"appending to previous map:"<<std::endl;
90 std::string input2(
"apple2/green2,lemon2/yellow2,blueberry2/blue2");
91 std::cout <<
"New string is '" << input2 <<
"'" << std::endl;
93 tokens_itr=maptokens.begin();
94 while (tokens_itr!=maptokens.end()) {
95 std::cout <<
"Token key " <<(*tokens_itr).first <<
" and value: "
96 << (*tokens_itr).second << std::endl;
100 std::cout <<
"clearing the map first:"<<std::endl;
102 tokens_itr=maptokens.begin();
103 while (tokens_itr!=maptokens.end()) {
104 std::cout <<
"Token key " <<(*tokens_itr).first <<
" and value: "
105 << (*tokens_itr).second << std::endl;
109 std::cout <<
"Use a multi-character pairDelimiter argument " << std::endl;
110 std::string input3(
"apple2:=green2 lemon2:=yellow2 blueberry2:=blue2");
111 std::cout <<
"input is: '" << input3 <<
"'" << std::endl;
113 tokens_itr=maptokens.begin();
114 while (tokens_itr!=maptokens.end()) {
115 std::cout <<
"Token key " <<(*tokens_itr).first <<
" and value: "
116 << (*tokens_itr).second << std::endl;
122 std::cout << std::endl <<
"Test stringToDouble " << std::endl;
123 std::string okDouble(
"3.14159");
124 std::string badDouble(
"3.garbage56");
130 std::cout <<
"Converted (string) " << okDouble <<
" to (double) "
131 << result << std::endl;
134 std::cout <<
"Failed with exception " << ex.
getMsg()
140 std::cout <<
"Converted (string) " << badDouble <<
" to (double) "
141 << result << std::endl;
144 std::cout <<
"Failed with exception " << ex.
getMsg()
149 std::cout << std::endl <<
"Test stringToInt " << std::endl;
151 std::string okInt(
"33550");
152 std::string badInt1(
"3garbage56");
153 std::string badInt2(
"garbage356");
159 std::cout <<
"Converted (string) " << okInt <<
" to (int) "
160 << intResult << std::endl;
163 std::cout <<
"Failed with exception " << ex.
getMsg()
169 std::cout <<
"Converted (string) " << badInt1 <<
" to (int) "
170 << intResult << std::endl;
173 std::cout <<
"Failed with exception " << ex.
getMsg()
179 std::cout <<
"Converted (string) " << badInt2 <<
" to (int) "
180 << intResult << std::endl;
183 std::cout <<
"Failed with exception " << ex.
getMsg()
188 std::cout << std::endl <<
"Test trimTrailing " << std::endl;
189 std::string string1(
"ends with 2 blanks ");
190 std::string string2(
"ends with newline\n");
191 std::string string3(
"no trailing whitespace");
194 std::cout <<
"Trimmed " << nTrimmed <<
" from string1; has new value : "
195 << string1 <<
"*EOS*" << std::endl;
198 std::cout <<
"Trimmed " << nTrimmed <<
" from string2; has new value : "
199 << string2 <<
"*EOS" << std::endl;
202 std::cout <<
"Trimmed " << nTrimmed <<
" from string3; has new value : "
203 << string3 <<
"*EOS" << std::endl;
Exception class used by expandEnvVar.
static double stringToDouble(const std::string &InStr)
static int expandEnvVar(std::string *toExpand, const std::string &openDel=std::string("$("), const std::string &closeDel=std::string(")"))
static void stringTokenize(std::string input, const std::string &delimiters, std::vector< std::string > &tokens, bool clear=true)
static std::string basename(const std::string &path)
static int stringToInt(const std::string &InStr)
static void keyValueTokenize(std::string input, const std::string &delimiters, std::map< std::string, std::string > &tokenMap, const std::string &pairDelimiter=std::string("="), bool clear=true)
static const char * itoa(int val, std::string &outStr)
static unsigned trimTrailing(std::string *toTrim)
Exception class used when converting from string to numeric type.