13#ifndef STRINGPARSING_HPP_
14#define STRINGPARSING_HPP_
47 int const minimumNumberOfDigits,
50 char const paddingChar =
'0' );
61 int const minimumNumberOfChars,
98 std::string
const& secondString );
107 char const charToBeReplaced,
108 char const charToBePutIn );
109 static std::string
const&
112 stringToInt( std::string
const& stringToInterpret );
117 double& doubleToSet );
122 static std::vector< int >
130 std::string
const& charSet );
133 std::string
const& charSet );
138 std::string*
const remainderString = NULL );
150 std::string
const& delimiterOfSubstring,
151 std::string*
const remainderString = NULL );
156 std::string
const& charsToTrim );
163 std::string
const& charsToTrim );
178 std::string*
const remainderString = NULL,
197 char const& divisionChar );
210 std::string
const& separatorString );
215 std::string
const& separatorString );
220 std::string
const& separatorString );
292 inputInt = -inputInt;
294 int numberOfDigits( 1 );
295 int tenToNumberOfDigits( 10 );
296 while( inputInt >= tenToNumberOfDigits )
298 tenToNumberOfDigits *= 10;
301 return numberOfDigits;
306 int const minimumNumberOfChars,
307 std::string
const prefixForPositiveNumbers,
308 std::string
const prefixForNegativeNumbers )
323 std::string returnString(
"" );
324 if( 0 < numberofSpaces )
326 returnString.append( (
size_t)numberofSpaces,
339 for(
int charCounter( stringToTransform.size() - 1 );
344 if( (
'A' <= stringToTransform[ charCounter ] )
346 (
'Z' >= stringToTransform[ charCounter ] ) )
357 for(
int charCounter( stringToTransform.size() - 1 );
362 if( (
'a' <= stringToTransform[ charCounter ] )
364 (
'z' >= stringToTransform[ charCounter ] ) )
374 char const charToBeReplaced,
375 char const charToBePutIn )
377 for(
int charCounter( stringToTransform.size() - 1 );
383 if( charToBeReplaced == stringToTransform[ charCounter ] )
385 stringToTransform[ charCounter ] = charToBePutIn;
390 inline std::string
const&
393 if( std::string::npos != fileName.find_last_of(
"/" ) )
395 std::string mkdirCommand(
"mkdir -p " );
396 mkdirCommand.append( fileName,
398 fileName.find_last_of(
"/" ) );
399 int systemReturn( system( mkdirCommand.c_str() ) );
400 if( -1 == systemReturn )
404 <<
"BOL::error! StringParser::ensureDirectoryExists( "
405 << fileName <<
" ) got a -1 from system(...); however, I have no"
406 <<
" idea what to do about it.";
407 std::cout << std::endl;
416 int returnValue( 0 );
417 std::stringstream( stringToInterpret ) >> returnValue;
425 std::stringstream( stringToInterpret ) >> returnValue;
431 std::string
const& charSet )
433 return ( std::string::npos != charSet.find( queryChar ) );
438 std::string
const& charSet )
441 return ( queryString.empty()
443 ( std::string::npos != queryString.find_first_not_of( charSet ) ) );
448 std::string
const& delimiterOfSubstring,
449 std::string*
const remainderString )
454 stringVector[ 0 ].assign( delimiterOfSubstring );
462 std::string
const& charsToTrim )
469 startOfReturnString( stringToTrim.find_first_not_of( charsToTrim ) );
470 if( std::string::npos == startOfReturnString )
472 return std::string(
"" );
476 return std::string( ( stringToTrim.begin() + startOfReturnString ),
477 stringToTrim.end() );
483 std::string
const& charsToTrim )
489 size_t endOfReturnString( stringToTrim.find_last_not_of( charsToTrim ) );
490 if( endOfReturnString == std::string::npos )
496 return std::string( stringToTrim.begin(),
497 ( stringToTrim.begin() + endOfReturnString + 1 ) );
503 std::string
const& charsToTrim )
511 startOfReturnString( stringToTrim.find_first_not_of( charsToTrim ) );
512 if( startOfReturnString == std::string::npos )
518 return std::string( ( stringToTrim.begin() + startOfReturnString ),
519 ( stringToTrim.begin()
520 + stringToTrim.find_last_not_of( charsToTrim )
528 std::string
const& divisionCharSet )
536 size_t wordStart( stringToParse.find_first_not_of( divisionCharSet ) );
538 while( std::string::npos != wordStart )
542 wordEnd = stringToParse.find_first_of( divisionCharSet,
544 destinationArray.
newEnd().assign( stringToParse.substr( wordStart,
545 ( wordEnd - wordStart ) ) );
546 if( std::string::npos != wordEnd )
548 wordStart = stringToParse.find_first_not_of( divisionCharSet,
553 wordStart = std::string::npos;
561 char const& divisionChar )
573 std::string
const& separatorString )
577 if( 0 < stringsToJoin.
getSize() )
579 std::string returnString( stringsToJoin.
getFront() );
580 for(
int stringIndex( 1 );
581 stringsToJoin.
getSize() > stringIndex;
584 returnString.append( separatorString );
585 returnString.append( stringsToJoin[ stringIndex ] );
591 return std::string(
"" );
597 std::vector< std::string* >
const& stringsToJoin,
598 std::string
const& separatorString )
602 if( !(stringsToJoin.empty()) )
604 std::string returnString( *(stringsToJoin.front()) );
605 for( std::vector< std::string* >::const_iterator
606 stringIterator( stringsToJoin.begin() + 1 );
607 stringsToJoin.end() > stringIterator;
610 returnString.append( separatorString );
611 returnString.append( *(*stringIterator) );
617 return std::string(
"" );
623 std::list< std::string* >
const& stringsToJoin,
624 std::string
const& separatorString )
628 if( !(stringsToJoin.empty()) )
630 std::list< std::string* >::const_iterator
631 stringIterator( stringsToJoin.begin() );
632 std::string returnString( *(*stringIterator) );
634 while( stringsToJoin.end() != stringIterator )
636 returnString.append( separatorString );
637 returnString.append( *(*stringIterator) );
644 return std::string(
"" );
650 char const paddingCharForInts,
651 int const numberOfMantissaDigits,
652 int const numberOfExponentDigits,
653 std::string
const prefixForPositiveNumbers,
654 std::string
const prefixForNegativeNumbers,
655 std::string
const positiveExponentPrefix,
656 std::string
const negativeExponentPrefix,
657 std::string
const exponentCharacter )
678 return intToString( inputInt,
679 minimumNumberOfDigitsForInts,
680 prefixForPositiveNumbers,
681 prefixForNegativeNumbers,
682 paddingCharForInts );
690 return doubleToString( inputDouble,
691 numberOfMantissaDigits,
692 numberOfExponentDigits,
693 prefixForPositiveNumbers,
694 prefixForNegativeNumbers,
695 positiveExponentPrefix,
696 negativeExponentPrefix,
std::string prefixForPositiveNumbers
StringParser(int const minimumNumberOfDigitsForInts=6, char const paddingCharForInts='0', int const numberOfMantissaDigits=6, int const numberOfExponentDigits=2, std::string const prefixForPositiveNumbers="+", std::string const prefixForNegativeNumbers="-", std::string const positiveExponentPrefix="+", std::string const negativeExponentPrefix="-", std::string const exponentCharacter="E")
static void transformToLowercase(std::string &stringToTransform)
StringParser & setDefaults(int const minimumNumberOfDigitsForInts=6, char const paddingCharForInts='0', int const numberOfMantissaDigits=6, int const numberOfExponentDigits=2, std::string const prefixForPositiveNumbers="+", std::string const prefixForNegativeNumbers="-", std::string const positiveExponentPrefix="+", std::string const negativeExponentPrefix="-", std::string const exponentCharacter="E")
static std::string firstWordOf(std::string const &stringToParse, std::string *const remainderString=NULL, std::string const &separatorChars=whitespaceChars)
static std::string const uppercaseAlphabetChars
static std::string const lowercaseAlphabetChars
std::string positiveExponentPrefix
static std::string const whitespaceAndNewlineChars
static bool stringsMatchIgnoringCase(std::string const &firstString, std::string const &secondString)
static std::vector< int > stringToIntVector(std::string stringToInterpret)
static std::string const digitChars
static bool isOnlyCharsIn(std::string const &queryString, std::string const &charSet)
static int intForSingleDigit(char const singleDigitAsChar)
std::string negativeExponentPrefix
static std::string const whitespaceChars
int numberOfMantissaDigits
static std::string trimFromBack(std::string const &stringToTrim, std::string const &charsToTrim)
static bool stringIsDouble(std::string const &stringToInterpret, double &doubleToSet)
static std::string const newlineChars
static std::string trimFromFrontAndBack(std::string const &stringToTrim, std::string const &charsToTrim=whitespaceAndNewlineChars)
static double stringToDouble(std::string const &stringToInterpret)
static std::string intToString(int inputInt, int const minimumNumberOfDigits, std::string const prefixForPositiveNumbers="+", std::string const prefixForNegativeNumbers="-", char const paddingChar='0')
static void transformToUppercase(std::string &stringToTransform)
static char const lowercaseMinusUppercase
static char charForSingleDigit(int const singleDigitAsInt)
int minimumNumberOfDigitsForInts
std::string prefixForNegativeNumbers
static int numberOfDigitsInInt(int inputInt)
static bool charIsIn(char const queryChar, std::string const &charSet)
static std::string positiveIntToString(int positiveInt)
int numberOfExponentDigits
std::string exponentCharacter
static std::string doubleToString(double inputDouble, int const numberOfMantissaDigits, int const numberOfExponentDigits, std::string const prefixForPositiveNumbers="+", std::string const prefixForNegativeNumbers="-", std::string const positiveExponentPrefix="+", std::string const negativeExponentPrefix="-", std::string const exponentCharacter="E")
static std::string joinWithSeparator(VectorlikeArray< std::string > const &stringsToJoin, std::string const &separatorString)
static void substituteCharacterWith(std::string &stringToTransform, char const charToBeReplaced, char const charToBePutIn)
static std::string trimFromFront(std::string const &stringToTrim, std::string const &charsToTrim)
static std::string const & ensureDirectoryExists(std::string const &fileName)
static void fillNumberOfDigitsAndTenTo(int const positiveInt)
static std::string intToSpacePaddedString(int inputInt, int const minimumNumberOfChars, std::string const prefixForPositiveNumbers="+", std::string const prefixForNegativeNumbers="-")
static std::string substringToFirst(std::string const &stringToParse, VectorlikeArray< std::string > const &delimitersOfSubstring, std::string *const remainderString=NULL)
static int stringToInt(std::string const &stringToInterpret)
static void parseByChar(std::string const &stringToParse, VectorlikeArray< std::string > &destinationArray, std::string const &divisionCharSet=whitespaceChars)
static double const notANumber