4#ifdef DEFECT_NO_STRINGSTREAM
22 const std::string& openDel,
23 const std::string& closeDel) {
24 unsigned opLen = openDel.size();
25 unsigned clLen = closeDel.size();
29 int envStart = toExpand->find(openDel.c_str());
30 while (envStart != -1) {
32 int envEnd = toExpand->find(closeDel.c_str(),envStart);
35 int afterBracket = envStart + opLen;
37 if (!( (envStart==-1) || (envEnd==-1) ))
39 std::string envVariable =
40 toExpand->substr(afterBracket,(envEnd-afterBracket));
41 const char * path = ::getenv(envVariable.c_str());
44 toExpand->replace(envStart,(envEnd+clLen-envStart), path);
45 if (nSuccess > -1) nSuccess++;
48 std::cerr <<
"Util::expandEnvVar unable to translate "
49 << envVariable << std::endl;
50 throw Untranslatable(envVariable);
54 envStart = toExpand->find(openDel.c_str());
61 const std::string& openDel,
62 const std::string& closeDel) {
63 unsigned opLen = openDel.size();
64 unsigned clLen = closeDel.size();
66 int valStart = toCatch->find(openDel.c_str(),pos);
67 while (valStart != -1) {
68 int valEnd = toCatch->find(closeDel.c_str(),valStart);
71 int afterBracket = valStart + opLen;
74 std::string valStr = toCatch->substr(afterBracket,(valEnd-afterBracket));
75 toCatch->erase(valStart,(valEnd+clLen-valStart));
79 std::cerr <<
"Util::can't find the close delimiter "
80 << closeDel << std::endl;
87 const char*
Util::itoa(
int val, std::string &outStr) {
95 static char outCharPtr[20];
97#ifdef DEFECT_NO_STRINGSTREAM
100 std::ostrstream locStream(a,100);
102 std::ostringstream locStream;
106#ifdef DEFECT_NO_STRINGSTREAM
107 locStream << std::ends;
109 outStr = locStream.str();
110 strcpy(outCharPtr, outStr.c_str());
126#ifdef DEFECT_NO_STRINGSTREAM
127 std::istrstream locStream(inStr.c_str());
129 std::istringstream locStream(inStr);
132 if (!locStream) {
return 0;}
139 int nItem = sscanf(inStr.c_str(),
"%lg %1s", &val, junk);
141 throw WrongType(inStr,
"double");
150 int nItem = sscanf(inStr.c_str(),
"%d %1s", &val, junk);
152 throw WrongType(inStr,
"int");
158 std::vector<std::string>& tokens,
bool clear) {
159 if (clear) tokens.clear();
161 std::string::size_type j;
162 while ( (j = input.find_first_of(delimiters)) != std::string::npos ) {
163 if (j != 0) tokens.push_back(input.substr(0, j));
164 input = input.substr(j+1);
166 tokens.push_back(input);
170 std::vector<std::string> names;
172 return *(names.end() - 1);
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 int catchOptionVal(std::string *toCatch, const int ops=0, const std::string &openDel=std::string("#("), const std::string &closeDel=std::string(")"))
static int atoi(const std::string &InStr)
converts an std::string to an integer
static std::string basename(const std::string &path)
static int stringToInt(const std::string &InStr)
static const char * itoa(int val, std::string &outStr)