StringUtils.H File Reference

Some assorted utilities to deal with strings. More...

Go to the source code of this file.

Functions

bool popNextToken (std::string &in, std::string &token, bool returnFalseOnSemiColon=false)
bool popUntilSemicolon (std::string &in, std::string &popped)
Array< std::string > splitIntoArray (const std::string &in)
Array< Array< std::string > > readDelimitedData (const std::string &csvString, const std::string &delimiter, bool removeQuotes=true)
std::string joinIntoString (const Array< std::string > &in, const std::string &delimiter=std::string(" "))
std::string convertNewlinesAndTabsToSpaces (std::string input)
 Converts DOS and UNIX style newlines and tab characters to spaces.
std::string intToString (int i)
int stringToInt (const std::string &in)
std::string realToString (double r)
double stringToReal (const std::string &in)
int iMinNonNeg (int i1, int i2)
std::string spacesString (int num)
 Returns a string containing num spaces in it.
int numSubstringOccurances (const std::string &str, const std::string &substr)
 Returns the number of occurances of substr in str.
int findNth (const std::string &str, const std::string &substr, const int n)
template<class T>
Array< T > insertIntoArray (Array< T > inputArray, T newElement, int insertBeforeElementNum)
bool getXMLField (const std::string &input, const std::string &fieldName, Table< std::string, std::string > &propertiesAndValues, std::string &fieldData, std::string &leftoverInput)
std::string writeXMLField (const std::string &fieldName, const Table< std::string, std::string > &propertiesAndValues, const std::string &fieldData)
char ** stringArrayTo2DCharArray (const Array< std::string > &a)
void delete2DCharArray (char **ptr, int size)


Detailed Description

Some assorted utilities to deal with strings.

Author:
Daniel Keefe (dfk) Daniel Keefe (dfk)
2004-01-28 2004-01-28

Function Documentation

std::string convertNewlinesAndTabsToSpaces ( std::string  input  ) 

Converts DOS and UNIX style newlines and tab characters to spaces.

void delete2DCharArray ( char **  ptr,
int  size 
)

int findNth ( const std::string &  str,
const std::string &  substr,
const int  n 
)

Like std::string.find() but returns the n-th occurance of substr rather than the first one.

bool getXMLField ( const std::string &  input,
const std::string &  fieldName,
Table< std::string, std::string > &  propertiesAndValues,
std::string &  fieldData,
std::string &  leftoverInput 
)

Here's my interpretation of XML for the mini parser and generator stuff below.. <fieldname1 property1="value1" property2="value2">fielddata1, fielddata2 </fieldname1> <fieldname2> <subfield1>blah</subfield1> </fieldname2> etc..

getXMLField returns datastructures based on this description. Returns false if the fieldName is not found in input. If there is more than one occurance of a field named fieldName in input, this returns data from the first one. leftOverInput is everything in input that comes after the end of the field.

int iMinNonNeg ( int  i1,
int  i2 
)

returns the minimum of i1 and i2 that is also >=0. if both are negative, returns a large positive number.

template<class T>
Array<T> insertIntoArray ( Array< T >  inputArray,
newElement,
int  insertBeforeElementNum 
) [inline]

This isn't so much a string utility as an Array utility. You can use this with an Array of strings, or any other Array.

std::string intToString ( int  i  ) 

std::string joinIntoString ( const Array< std::string > &  in,
const std::string &  delimiter = std::string(" ") 
)

returns a string of that is the concatanation of all elements in the array separated by the specified delimiter

int numSubstringOccurances ( const std::string &  str,
const std::string &  substr 
)

Returns the number of occurances of substr in str.

bool popNextToken ( std::string &  in,
std::string &  token,
bool  returnFalseOnSemiColon = false 
)

Pops off the next token in the string where a token is separated by a space, a tab, a newline, a comma, or a semicolon. if the last parameter is set then this returns false if it is the last item in the string OR if there is a semicolon immediately following the token, otherwise it returns false when there are no more tokens in the string.

bool popUntilSemicolon ( std::string &  in,
std::string &  popped 
)

pops off the everything in the string until a semicolon is reached. after the call, in is what's left of the string. returns true if a semicolon was found, false otherwise

Array< Array< std::string > > readDelimitedData ( const std::string &  csvString,
const std::string &  delimiter,
bool  removeQuotes = true 
)

Reads comma, tab, etc.. separated data into a 2D array of strings. csvString should is normally read from a file. Each entry of a line of the file should be separated by the delimiter string. If removeQuotes is true than quotes around entries are removed before appending them to the 2D array that is returned.

std::string realToString ( double  r  ) 

std::string spacesString ( int  num  ) 

Returns a string containing num spaces in it.

Array<std::string> splitIntoArray ( const std::string &  in  ) 

returns an array of tokens that are separated according to the criteria outlined in popNextToken above.

char** stringArrayTo2DCharArray ( const Array< std::string > &  a  ) 

int stringToInt ( const std::string &  in  ) 

double stringToReal ( const std::string &  in  ) 

std::string writeXMLField ( const std::string &  fieldName,
const Table< std::string, std::string > &  propertiesAndValues,
const std::string &  fieldData 
)

fielddata can include a call to writeXMLField to make a subfield, this gets formatted as described in the getXMLField() function description.


Generated on Wed Jan 26 06:31:20 2011 for IS3D by  doxygen 1.5.6