24 if (line.length() > 0) rtn.
append(
before(line, comment));
36 const size_t len = input.
length();
37 for (
size_t p=0; p<len; ++p) {
38 const bool isEnd = p==len-1;
39 if( input[p]==
'\n' || input[p]==
'\0' || input[p]==
'\r' || isEnd )
43 subString( input, begin, p+(isEnd?(input[len-1]==
'\n'?0:1):0) )
60 for (
int i=0; i<lines.
length(); i++)
62 if (lines[i].length() == 0)
continue;
64 if (tokens.
length() == 0)
continue;
76 if (line.length() > 0) line[0] =
'\0';
78 if (is.eof())
return false;
79 if (is.getline(c, 499))
81 line = std::string(c);
90 unsigned int start = 0;
92 while(start < str.length())
96 if (wordStart > start)
103 if (start-stop == 0)
return rtn;
104 std::string sub =
subString(str, start, stop);
114 unsigned int start = 0;
116 while(start < str.length())
120 if (start-stop == 0)
return rtn;
121 std::string sub =
subString(str, start, stop);
134 for (
int i=iStart; i<tokens.
length(); i++)
137 if (i < (tokens.
length()-1)) rtn +=
" ";
154 std::string tmp(big);
159 for (
unsigned int i=1; i<big.length(); i++)
161 if (big[i]==
'(') parenDepth++;
162 if (big[i]==
')') parenDepth--;
165 tmp[localCount]=
'\0';
169 if (big[i]==
',' && parenDepth==0)
171 tmp[localCount]=
'\0';
177 tmp[localCount] = big[i];
188 for (
unsigned int i=0; i<(str.length()-offset); i++)
190 if (str[i+offset]==
' ' || str[i+offset]==
'\t' || str[i+offset]==
'\n')
195 return static_cast<int>(str.length());
201 for (
unsigned int i=0; i<(str.length()-offset); i++)
203 if (!(str[i+offset]==
' ' || str[i+offset]==
'\t' || str[i+offset]==
'\n'))
208 return static_cast<int>(str.length());
218 "mismatched variable tables in varTableSubstitute");
220 std::string line = rawLine;
221 for (
int i=0; i<varNames.
length(); i++)
230 const std::string& varName,
231 const std::string& varValue)
233 std::string line = rawLine;
236 while (
find(line, varName) >= 0)
238 std::string b =
before(line, varName);
239 std::string a =
after(line, varName);
240 line = b + varValue + a;
258 std::runtime_error,
"String::before: arg is null pointer");
260 char* p = std::strstr((
char*) str.c_str(), (
char*) sub.c_str());
261 if (p==0)
return str;
262 int subLen =
static_cast<int>(p-str.c_str());
263 std::string rtn(str.c_str(), subLen);
271 std::runtime_error,
"String::after: arg is null pointer");
274 char* p = std::strstr((
char*) str.c_str(), (
char*) sub.c_str()) ;
276 if (p==0)
return std::string();
278 p+= std::strlen(sub.c_str());
279 return std::string(p);
285 char* p = std::strstr((
char*) str.c_str(), (
char*) sub.c_str());
287 return static_cast<int>(p-str.c_str());
293 for (
unsigned int i=0; i<str.length(); i++)
295 unsigned char c = str[i];
296 if (c >= 33 && c <= 126)
307 std::string rtn = str;
308 for (
unsigned int i=0; i<rtn.length(); i++)
310 unsigned char c = rtn[i];
311 if (c < 33 || c > 126)
313 if (c !=
'\t' && c !=
'\n'&& c !=
'\r' && c !=
'\f' && c !=
' ')
324 const std::string& end, std::string& front,
327 front =
before(str, begin);
328 std::string middle =
before(
after(str, begin), end);
329 back =
after(str, end);
336 return std::string(str.c_str()+begin, end-begin);
343 "StrUtils::readFromStream isn't implemented yet");
360 for (
unsigned int i=0; i<rtn.length(); i++)
362 rtn[i] = toupper(rtn[i]);
370 return std::atof(s.c_str());
376 return std::atoi(s.c_str());
382 ,
const std::string &linePrefix
383 ,
const std::string &lines
388 for(
int i = 0; i < static_cast<int>(linesArray.size()); ++i )
390 os << linePrefix << linesArray[i] <<
"\n";
398 std::string::size_type pos=0;
399 bool spacesLeft =
true;
402 pos = stringToClean.find(
" ");
403 if(pos != string::npos){
404 stringToClean.erase(pos,1);
410 return stringToClean;
void reserve(size_type n)
static std::string removeAllSpaces(std::string stringToClean)
Removes all the spaces in a string.
Array< T > & append(const T &x)
Add a new entry at the end of the array.
static int findNextNonWhitespace(const std::string &str, int offset)
static std::string allCaps(const std::string &str)
Converts a std::string to all upper case.
static Array< Array< std::string > > tokenizeFile(std::istream &is, char comment)
Tokenize a file into whitespace-delimited tokens.
static std::string after(const std::string &str, const std::string &sub)
Find the substring after a specified substring. For example, before("abcdefghij", "gh") returns "ij"...
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
Macro for throwing an exception with breakpointing to ease debugging.
static Array< std::string > splitIntoLines(const std::string &input)
Split an input std::string that contains newlines into an array of strings, one for each line...
static std::ostream & printLines(std::ostream &os, const std::string &linePrefix, const std::string &lines)
Print lines with prefix first.
static bool readLine(std::istream &is, std::string &line)
Read a single line into a std::string.
static double atof(const std::string &str)
Returns the double value of a std::string.
A std::string utilities class for Teuchos.
static std::string between(const std::string &str, const std::string &begin, const std::string &end, std::string &front, std::string &back)
Returns the std::string between two delimiting strings, and returns by reference the strings before a...
static std::string varSubstitute(const std::string &rawLine, const std::string &varName, const std::string &varValue)
static std::string subString(const std::string &str, int begin, int end)
Returns the substring between two positions.
static std::string reassembleFromTokens(const Array< std::string > &tokens, int iStart=0)
static std::string before(const std::string &str, const std::string &sub)
Find the substring before a specified substring. For example, before("abcdefghij", "gh") returns "abcdef".
static std::string varTableSubstitute(const std::string &rawLine, const Array< std::string > &varNames, const Array< std::string > &varValues)
void resize(size_type new_size, const value_type &x=value_type())
static bool isWhite(const std::string &str)
Returns true if a std::string consists entirely of whitespace.
static std::string fixUnprintableCharacters(const std::string &str)
Convert unprintable non-null characters to whitespace.
int length() const
Return number of elements in the array.
static std::string readFromStream(std::istream &is)
static Array< std::string > stringTokenizer(const std::string &str)
static Array< std::string > readFile(std::istream &is, char comment)
Read a file, putting each line into a std::string.
static int atoi(const std::string &str)
Returns the int value of a std::string.
static Array< std::string > getTokensPlusWhitespace(const std::string &str)
static void splitList(const std::string &bigstring, Array< std::string > &elements)
static int findNextWhitespace(const std::string &str, int offset)
static int find(const std::string &str, const std::string &sub)
Find the position at which a substring first occurs. For example, find("abcdefghij", "gh") returns 6.