4#include "RootCnvSvc/Util.h"
5#ifdef DEFECT_NO_STRINGSTREAM
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 )
33 int envEnd = toExpand->find( closeDel.c_str(), envStart );
36 int afterBracket = envStart + opLen;
38 if ( !( ( envStart == -1 ) || ( envEnd == -1 ) ) )
40 std::string envVariable = toExpand->substr( afterBracket, ( envEnd - afterBracket ) );
41 const char* path = ::getenv( envVariable.c_str() );
45 toExpand->replace( envStart, ( envEnd + clLen - envStart ), path );
46 if ( nSuccess > -1 ) nSuccess++;
50 std::cerr <<
"Util::expandEnvVar unable to translate " << envVariable << std::endl;
51 throw Untranslatable( envVariable );
55 envStart = toExpand->find( openDel.c_str() );
61 const std::string& closeDel ) {
62 unsigned opLen = openDel.size();
63 unsigned clLen = closeDel.size();
65 int valStart = toCatch->find( openDel.c_str(), pos );
66 while ( valStart != -1 )
68 int valEnd = toCatch->find( closeDel.c_str(), valStart );
71 int afterBracket = valStart + opLen;
75 std::string valStr = toCatch->substr( afterBracket, ( valEnd - afterBracket ) );
76 toCatch->erase( valStart, ( valEnd + clLen - valStart ) );
77 return atoi( valStr );
81 std::cerr <<
"Util::can't find the close delimiter " << closeDel << std::endl;
82 throw Untranslatable( *toCatch );
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 );
141 if ( nItem != 1 ) {
throw WrongType( inStr,
"double" ); }
148 int nItem = sscanf( inStr.c_str(),
"%d %1s", &val, junk );
149 if ( nItem != 1 ) {
throw WrongType( inStr,
"int" ); }
154 std::vector<std::string>& tokens,
bool clear ) {
155 if ( clear ) tokens.clear();
157 std::string::size_type j;
158 while ( ( j = input.find_first_of( delimiters ) ) != std::string::npos )
160 if ( j != 0 ) tokens.push_back( input.substr( 0, j ) );
161 input = input.substr( j + 1 );
163 tokens.push_back( input );
167 std::vector<std::string> names;
169 return *( names.end() - 1 );
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 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 int catchOptionVal(std::string *toCatch, const int ops=0, const std::string &openDel=std::string("#("), const std::string &closeDel=std::string(")"))
static const char * itoa(int val, std::string &outStr)