5#ifdef DEFECT_NO_STRINGSTREAM
23 const std::string& openDel,
24 const std::string& closeDel) {
25 unsigned opLen = openDel.size();
26 unsigned clLen = closeDel.size();
30 int envStart = toExpand->find(openDel.c_str());
31 while (envStart != -1) {
33 int envEnd = toExpand->find(closeDel.c_str(),envStart);
36 int afterBracket = envStart + opLen;
38 if (!( (envStart==-1) || (envEnd==-1) ))
40 std::string envVariable =
41 toExpand->substr(afterBracket,(envEnd-afterBracket));
42 const char * path = ::getenv(envVariable.c_str());
45 toExpand->replace(envStart,(envEnd+clLen-envStart), path);
46 if (nSuccess > -1) nSuccess++;
49 std::cerr <<
"Util::expandEnvVar unable to translate "
50 << envVariable << std::endl;
51 throw Untranslatable(envVariable);
55 envStart = toExpand->find(openDel.c_str());
62 const std::string& openDel,
63 const std::string& closeDel) {
64 unsigned opLen = openDel.size();
65 unsigned clLen = closeDel.size();
67 int valStart = toCatch->find(openDel.c_str(),pos);
68 while (valStart != -1) {
69 int valEnd = toCatch->find(closeDel.c_str(),valStart);
72 int afterBracket = valStart + opLen;
75 std::string valStr = toCatch->substr(afterBracket,(valEnd-afterBracket));
76 toCatch->erase(valStart,(valEnd+clLen-valStart));
80 std::cerr <<
"Util::can't find the close delimiter "
81 << closeDel << std::endl;
88 const char*
Util::itoa(
int val, std::string &outStr) {
96 static char outCharPtr[20];
98#ifdef DEFECT_NO_STRINGSTREAM
101 std::ostrstream locStream(a,100);
103 std::ostringstream locStream;
107#ifdef DEFECT_NO_STRINGSTREAM
108 locStream << std::ends;
110 outStr = locStream.str();
111 strcpy(outCharPtr, outStr.c_str());
127#ifdef DEFECT_NO_STRINGSTREAM
128 std::istrstream locStream(inStr.c_str());
130 std::istringstream locStream(inStr);
133 if (!locStream) {
return 0;}
140 int nItem = sscanf(inStr.c_str(),
"%lg %1s", &val, junk);
142 throw WrongType(inStr,
"double");
151 int nItem = sscanf(inStr.c_str(),
"%d %1s", &val, junk);
153 throw WrongType(inStr,
"int");
159 std::vector<std::string>& tokens,
bool clear) {
160 if (clear) tokens.clear();
162 std::string::size_type j;
163 while ( (j = input.find_first_of(delimiters)) != std::string::npos ) {
164 if (j != 0) tokens.push_back(input.substr(0, j));
165 input = input.substr(j+1);
167 tokens.push_back(input);
171 std::vector<std::string> names;
173 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)