31 int const minimumNumberOfDigits,
32 std::string
const prefixForPositiveNumbers,
33 std::string
const prefixForNegativeNumbers,
34 char const paddingChar )
44 if( 0 >= minimumNumberOfDigits )
48 <<
"BOL::warning! StringParser::intToString( "
49 << inputInt <<
", " << minimumNumberOfDigits <<
", "
51 <<
" ) could not fit the integer into the given size!";
53 return std::string(
"please_give_a_positive_number_of_digits" );
64 int numberOfZeroesToInsert( minimumNumberOfDigits
65 - (
int)(unpaddedIntAsString.size()) );
68 if( 0 < numberOfZeroesToInsert )
70 returnString.append( (
size_t)numberOfZeroesToInsert,
73 returnString.append( unpaddedIntAsString );
79 int const numberOfMantissaDigits,
80 int const numberOfExponentDigits,
81 std::string
const prefixForPositiveNumbers,
82 std::string
const prefixForNegativeNumbers,
83 std::string
const positiveExponentPrefix,
84 std::string
const negativeExponentPrefix,
85 std::string
const exponentCharacter )
109 <<
"BOL::warning! StringParser::doubleToString( "
114 <<
" ) could not fit the double into the given size!";
116 return std::string(
"please_give_a_positive_number_of_digits" );
119 double formattedMantissa( inputDouble );
120 if( 0.0 > inputDouble )
123 formattedMantissa = -inputDouble;
125 if( 0.0 == formattedMantissa )
127 returnString.append(
"0." );
135 else if( 0.0 < formattedMantissa )
139 int tenToDigitsMinusOneAsInt( 1 );
140 for(
int mantissaDigitCount( 1 );
142 ++mantissaDigitCount )
144 tenToDigitsMinusOneAsInt *= 10;
146 double tenToDigitsMinusOneAsDouble( (
double)tenToDigitsMinusOneAsInt );
147 double tenToDigits( 10.0 * tenToDigitsMinusOneAsDouble );
148 int formattedExponent( 0 );
149 while( tenToDigits <= formattedMantissa )
151 formattedMantissa *= 0.1;
154 while( tenToDigitsMinusOneAsDouble > formattedMantissa )
156 formattedMantissa *= 10.0;
163 int mantissaTimesTenToSomePowerAsInt( (
int)formattedMantissa );
164 if( 0.5 <= ( formattedMantissa
165 - (
double)mantissaTimesTenToSomePowerAsInt ) )
167 ++mantissaTimesTenToSomePowerAsInt;
169 if( mantissaTimesTenToSomePowerAsInt
170 >= ( 10 * tenToDigitsMinusOneAsInt) )
174 mantissaTimesTenToSomePowerAsInt
175 = ( mantissaTimesTenToSomePowerAsInt / 10 );
179 mantissaTimesTenToSomePowerAsInt ) );
180 returnString.append( 1,
181 mantissaTimesTenToSomePowerAsString[ 0 ] );
182 returnString.append( 1,
184 returnString.append( mantissaTimesTenToSomePowerAsString,
186 ( mantissaTimesTenToSomePowerAsString.size() - 1 ) );
191 if( 0 > formattedExponent )
194 formattedExponent = -formattedExponent;
203 - (
int)(exponentIntAsString.size()) );
204 if( 0 < exponentZeroesToPrepend )
206 returnString.append( exponentZeroesToPrepend,
209 returnString.append( exponentIntAsString );
221 std::string
const& secondString )
225 if( firstString.size() != secondString.size() )
230 for(
int charCounter( firstString.size() - 1 );
237 if( ( secondString[ charCounter ] != firstString[ charCounter ] )
239 !( ( firstString[ charCounter ] >=
'A' )
241 ( firstString[ charCounter ] <=
'Z' )
243 ( secondString[ charCounter ]
244 == ( firstString[ charCounter ]
247 !( ( firstString[ charCounter ] >=
'a' )
249 ( firstString[ charCounter ] <=
'z' )
251 ( secondString[ charCounter ]
252 == ( firstString[ charCounter ]
264 double& doubleToSet )
270 size_t charPosition( stringToInterpret.find_first_not_of(
272 if( charPosition == std::string::npos )
276 if( ( stringToInterpret[ charPosition ] ==
'+' )
278 ( stringToInterpret[ charPosition ] ==
'-' ) )
280 if( charPosition == ( stringToInterpret.size() - 1 ) )
286 charPosition = stringToInterpret.find_first_not_of(
digitChars,
288 if( ( charPosition != std::string::npos )
290 ( stringToInterpret[ charPosition ] ==
'.' ) )
292 charPosition = stringToInterpret.find_first_not_of(
digitChars,
293 ( charPosition + 1 ) );
295 if( ( charPosition < ( stringToInterpret.size() - 2 ) )
297 ( ( stringToInterpret[ charPosition ] ==
'e' )
299 ( stringToInterpret[ charPosition ] ==
'E' ) ) )
302 if( ( stringToInterpret[ charPosition ] ==
'+' )
304 ( stringToInterpret[ charPosition ] ==
'-' ) )
308 charPosition = stringToInterpret.find_first_not_of(
digitChars,
314 if( charPosition == std::string::npos )
331 std::vector< int > returnVector;
334 if( !(indicesString.empty()) )
336 std::stringstream streamToParse( indicesString );
337 double parsedIntAsDouble;
338 while( streamToParse.good() )
340 streamToParse >> parsedIntAsDouble;
341 returnVector.push_back( (
int)parsedIntAsDouble );
350 std::string*
const remainderString )
362 delimiterPosition( stringToParse.find( delimitersOfSubstring[ 0 ] ) );
363 size_t comparisonPosition;
364 for(
int stringIndex( delimitersOfSubstring.
getLastIndex() );
369 = stringToParse.find( delimitersOfSubstring[ stringIndex ] );
370 if( comparisonPosition < delimiterPosition )
372 delimiterPosition = comparisonPosition;
378 if( std::string::npos == delimiterPosition )
380 if( NULL != remainderString )
382 remainderString->assign(
"" );
384 return stringToParse;
388 std::string returnString( stringToParse.begin(),
389 ( stringToParse.begin() + delimiterPosition ) );
390 if( NULL != remainderString )
392 remainderString->assign( ( stringToParse.begin() + delimiterPosition ),
393 stringToParse.end() );
401 std::string*
const remainderString,
402 std::string
const& separatorChars )
408 size_t wordStart( stringToParse.find_first_not_of( separatorChars ) );
409 if( std::string::npos == wordStart )
411 if( NULL != remainderString )
413 remainderString->assign(
"" );
415 return std::string(
"" );
419 size_t wordEnd( stringToParse.find_first_of( separatorChars,
421 std::string returnString( stringToParse.substr( wordStart,
422 ( wordEnd - wordStart ) ) );
423 if( NULL != remainderString )
425 wordStart = stringToParse.find_first_not_of( separatorChars,
427 if( std::string::npos != wordStart )
429 remainderString->assign( stringToParse.substr( wordStart ) );
433 remainderString->assign(
"" );
442 char const paddingCharForInts,
443 int const numberOfMantissaDigits,
444 int const numberOfExponentDigits,
445 std::string
const prefixForPositiveNumbers,
446 std::string
const prefixForNegativeNumbers,
447 std::string
const positiveExponentPrefix,
448 std::string
const negativeExponentPrefix,
449 std::string
const exponentCharacter ) :
450 minimumNumberOfDigitsForInts( minimumNumberOfDigitsForInts ),
451 paddingCharForInts( paddingCharForInts ),
452 numberOfMantissaDigits( numberOfMantissaDigits ),
453 numberOfExponentDigits( numberOfExponentDigits ),
454 prefixForPositiveNumbers( prefixForPositiveNumbers ),
455 prefixForNegativeNumbers( prefixForNegativeNumbers ),
456 positiveExponentPrefix( positiveExponentPrefix ),
457 negativeExponentPrefix( negativeExponentPrefix ),
458 exponentCharacter( exponentCharacter )
472 switch( singleDigitAsInt )
502 switch( singleDigitAsChar )
546 int numberOfDigits( 1 );
547 int tenToNumberOfDigits( 10 );
548 while( positiveInt >= tenToNumberOfDigits )
550 tenToNumberOfDigits *= 10;
553 std::string digitBuffer(
"" );
555 while( 0 < positiveInt )
557 tenToNumberOfDigits = ( tenToNumberOfDigits / 10 );
559 while( tenToNumberOfDigits <= positiveInt )
561 positiveInt -= tenToNumberOfDigits;
566 for(
int zeroesToPushBack( numberOfDigits - digitBuffer.size() );
567 0 < zeroesToPushBack;
570 digitBuffer.push_back(
'0' );
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 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 int intForSingleDigit(char const singleDigitAsChar)
std::string negativeExponentPrefix
static std::string const whitespaceChars
int numberOfMantissaDigits
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 char const lowercaseMinusUppercase
static char charForSingleDigit(int const singleDigitAsInt)
std::string prefixForNegativeNumbers
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 void substituteCharacterWith(std::string &stringToTransform, char const charToBeReplaced, char const charToBePutIn)
static std::string substringToFirst(std::string const &stringToParse, VectorlikeArray< std::string > const &delimitersOfSubstring, std::string *const remainderString=NULL)
static double const notANumber
static std::string const nanString