a Code for the Combination of Indirect and Direct Constraints on High Energy Physics Models Logo
BOL::StringParser Class Reference

#include <StringParser.hpp>

Detailed Description

Definition at line 32 of file StringParser.hpp.

Public Member Functions

std::string doubleToString (double inputDouble) const
 
std::string intToString (int inputInt) const
 
StringParsersetDefaults (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")
 
 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")
 
 ~StringParser ()
 

Static Public Member Functions

static bool charIsIn (char const queryChar, std::string const &charSet)
 
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 const & ensureDirectoryExists (std::string const &fileName)
 
static std::string firstWordOf (std::string const &stringToParse, std::string *const remainderString=NULL, std::string const &separatorChars=whitespaceChars)
 
static std::string intToSpacePaddedString (int inputInt, int const minimumNumberOfChars, std::string const prefixForPositiveNumbers="+", std::string const prefixForNegativeNumbers="-")
 
static std::string intToString (int inputInt, int const minimumNumberOfDigits, std::string const prefixForPositiveNumbers="+", std::string const prefixForNegativeNumbers="-", char const paddingChar='0')
 
static bool isOnlyCharsIn (std::string const &queryString, std::string const &charSet)
 
static std::string joinWithSeparator (std::list< std::string * > const &stringsToJoin, std::string const &separatorString)
 
static std::string joinWithSeparator (std::vector< std::string * > const &stringsToJoin, std::string const &separatorString)
 
static std::string joinWithSeparator (VectorlikeArray< std::string > const &stringsToJoin, std::string const &separatorString)
 
static int numberOfDigitsInInt (int inputInt)
 
static void parseByChar (std::string const &stringToParse, VectorlikeArray< std::string > &destinationArray, char const &divisionChar)
 
static void parseByChar (std::string const &stringToParse, VectorlikeArray< std::string > &destinationArray, std::string const &divisionCharSet=whitespaceChars)
 
static bool stringIsDouble (std::string const &stringToInterpret, double &doubleToSet)
 
static bool stringsMatchIgnoringCase (std::string const &firstString, std::string const &secondString)
 
static double stringToDouble (std::string const &stringToInterpret)
 
static int stringToInt (std::string const &stringToInterpret)
 
static std::vector< int > stringToIntVector (std::string stringToInterpret)
 
static void substituteCharacterWith (std::string &stringToTransform, char const charToBeReplaced, char const charToBePutIn)
 
static std::string substringToFirst (std::string const &stringToParse, std::string const &delimiterOfSubstring, std::string *const remainderString=NULL)
 
static std::string substringToFirst (std::string const &stringToParse, VectorlikeArray< std::string > const &delimitersOfSubstring, std::string *const remainderString=NULL)
 
static void transformToLowercase (std::string &stringToTransform)
 
static void transformToUppercase (std::string &stringToTransform)
 
static std::string trimFromBack (std::string const &stringToTrim, std::string const &charsToTrim)
 
static std::string trimFromFront (std::string const &stringToTrim, std::string const &charsToTrim)
 
static std::string trimFromFrontAndBack (std::string const &stringToTrim, std::string const &charsToTrim=whitespaceAndNewlineChars)
 

Static Public Attributes

static std::string const digitChars
 
static std::string const lowercaseAlphabetChars
 
static std::string const newlineChars
 
static std::string const uppercaseAlphabetChars
 
static std::string const whitespaceAndNewlineChars
 
static std::string const whitespaceChars
 

Static Protected Member Functions

static char charForSingleDigit (int const singleDigitAsInt)
 
static void fillNumberOfDigitsAndTenTo (int const positiveInt)
 
static int intForSingleDigit (char const singleDigitAsChar)
 
static std::string positiveIntToString (int positiveInt)
 

Protected Attributes

std::string exponentCharacter
 
int minimumNumberOfDigitsForInts
 
std::string negativeExponentPrefix
 
int numberOfExponentDigits
 
int numberOfMantissaDigits
 
char paddingCharForInts
 
std::string positiveExponentPrefix
 
std::string prefixForNegativeNumbers
 
std::string prefixForPositiveNumbers
 

Static Protected Attributes

static char const lowercaseMinusUppercase
 

Constructor & Destructor Documentation

◆ StringParser()

BOL::StringParser::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" 
)

Definition at line 441 of file StringParser.cpp.

◆ ~StringParser()

BOL::StringParser::~StringParser ( )

Definition at line 463 of file StringParser.cpp.

464 {
465 // does nothing.
466 }

Member Function Documentation

◆ charForSingleDigit()

char BOL::StringParser::charForSingleDigit ( int const  singleDigitAsInt)
staticprotected

Definition at line 470 of file StringParser.cpp.

471 {
472 switch( singleDigitAsInt )
473 {
474 case 0:
475 return '0';
476 case 1:
477 return '1';
478 case 2:
479 return '2';
480 case 3:
481 return '3';
482 case 4:
483 return '4';
484 case 5:
485 return '5';
486 case 6:
487 return '6';
488 case 7:
489 return '7';
490 case 8:
491 return '8';
492 case 9:
493 return '9';
494 default:
495 return '?';
496 }
497 }

◆ charIsIn()

bool BOL::StringParser::charIsIn ( char const  queryChar,
std::string const &  charSet 
)
inlinestatic

Definition at line 430 of file StringParser.hpp.

432 {
433 return ( std::string::npos != charSet.find( queryChar ) );
434 }

◆ doubleToString() [1/2]

std::string BOL::StringParser::doubleToString ( double  inputDouble) const
inline

Definition at line 686 of file StringParser.hpp.

689 {
690 return doubleToString( inputDouble,
698 }
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")

◆ doubleToString() [2/2]

std::string BOL::StringParser::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

Definition at line 78 of file StringParser.cpp.

102 {
103 if( ( 0 >= numberOfMantissaDigits )
104 ||
105 ( 0 >= numberOfExponentDigits ) )
106 {
107 std::cout
108 << std::endl
109 << "BOL::warning! StringParser::doubleToString( "
110 << inputDouble << ", " << numberOfMantissaDigits << ", "
114 << " ) could not fit the double into the given size!";
115 // report a warning message.
116 return std::string( "please_give_a_positive_number_of_digits" );
117 }
118 std::string returnString( prefixForPositiveNumbers );
119 double formattedMantissa( inputDouble );
120 if( 0.0 > inputDouble )
121 {
122 returnString.assign( prefixForNegativeNumbers );
123 formattedMantissa = -inputDouble;
124 }
125 if( 0.0 == formattedMantissa )
126 {
127 returnString.append( "0." );
128 returnString.append( ( numberOfMantissaDigits - 1 ),
129 '0' );
130 returnString.append( exponentCharacter );
131 returnString.append( positiveExponentPrefix );
132 returnString.append( numberOfExponentDigits,
133 '0' );
134 }
135 else if( 0.0 < formattedMantissa )
136 // at this point any negative numbers will now be positive, so any
137 // that fail this comparison should be NaN.
138 {
139 int tenToDigitsMinusOneAsInt( 1 );
140 for( int mantissaDigitCount( 1 );
141 numberOfMantissaDigits > mantissaDigitCount;
142 ++mantissaDigitCount )
143 {
144 tenToDigitsMinusOneAsInt *= 10;
145 }
146 double tenToDigitsMinusOneAsDouble( (double)tenToDigitsMinusOneAsInt );
147 double tenToDigits( 10.0 * tenToDigitsMinusOneAsDouble );
148 int formattedExponent( 0 );
149 while( tenToDigits <= formattedMantissa )
150 {
151 formattedMantissa *= 0.1;
152 ++formattedExponent;
153 }
154 while( tenToDigitsMinusOneAsDouble > formattedMantissa )
155 {
156 formattedMantissa *= 10.0;
157 --formattedExponent;
158 }
159 /* now formattedMantissa is between tenToDigitsMinusOneAsDouble &
160 * tenToDigits, & hence has numberOfMantissaCharacters digits before the
161 * decimal point. however, now we have to round correctly:
162 */
163 int mantissaTimesTenToSomePowerAsInt( (int)formattedMantissa );
164 if( 0.5 <= ( formattedMantissa
165 - (double)mantissaTimesTenToSomePowerAsInt ) )
166 {
167 ++mantissaTimesTenToSomePowerAsInt;
168 }
169 if( mantissaTimesTenToSomePowerAsInt
170 >= ( 10 * tenToDigitsMinusOneAsInt) )
171 // if rounding pushed mantissaTimesTenToSomePowerAsInt into having too
172 // many digits...
173 {
174 mantissaTimesTenToSomePowerAsInt
175 = ( mantissaTimesTenToSomePowerAsInt / 10 );
176 ++formattedExponent;
177 }
178 std::string mantissaTimesTenToSomePowerAsString( positiveIntToString(
179 mantissaTimesTenToSomePowerAsInt ) );
180 returnString.append( 1,
181 mantissaTimesTenToSomePowerAsString[ 0 ] );
182 returnString.append( 1,
183 '.' );
184 returnString.append( mantissaTimesTenToSomePowerAsString,
185 1,
186 ( mantissaTimesTenToSomePowerAsString.size() - 1 ) );
187 formattedExponent += ( numberOfMantissaDigits - 1 );
188 // this accounts for all the multiplication to get the mantissa as an
189 // int of the appropriate length.
190 returnString.append( exponentCharacter );
191 if( 0 > formattedExponent )
192 {
193 returnString.append( negativeExponentPrefix );
194 formattedExponent = -formattedExponent;
195 }
196 else
197 {
198 returnString.append( positiveExponentPrefix );
199 }
200 std::string
201 exponentIntAsString( positiveIntToString( formattedExponent ) );
202 int exponentZeroesToPrepend( numberOfExponentDigits
203 - (int)(exponentIntAsString.size()) );
204 if( 0 < exponentZeroesToPrepend )
205 {
206 returnString.append( exponentZeroesToPrepend,
207 '0' );
208 }
209 returnString.append( exponentIntAsString );
210 }
211 else
212 // if it failed the comparison, it should be a NaN.
213 {
214 returnString.assign( UsefulStuff::nanString );
215 }
216 return returnString;
217 }
static std::string positiveIntToString(int positiveInt)
static std::string const nanString
Definition: UsefulStuff.hpp:29

◆ ensureDirectoryExists()

std::string const & BOL::StringParser::ensureDirectoryExists ( std::string const &  fileName)
inlinestatic

Definition at line 391 of file StringParser.hpp.

392 {
393 if( std::string::npos != fileName.find_last_of( "/" ) )
394 {
395 std::string mkdirCommand( "mkdir -p " );
396 mkdirCommand.append( fileName,
397 0,
398 fileName.find_last_of( "/" ) );
399 int systemReturn( system( mkdirCommand.c_str() ) );
400 if( -1 == systemReturn )
401 {
402 std::cout
403 << std::endl
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;
408 }
409 }
410 return fileName;
411 }

◆ fillNumberOfDigitsAndTenTo()

static void BOL::StringParser::fillNumberOfDigitsAndTenTo ( int const  positiveInt)
staticprotected

◆ firstWordOf()

std::string BOL::StringParser::firstWordOf ( std::string const &  stringToParse,
std::string *const  remainderString = NULL,
std::string const &  separatorChars = whitespaceChars 
)
static

Definition at line 400 of file StringParser.cpp.

407 {
408 size_t wordStart( stringToParse.find_first_not_of( separatorChars ) );
409 if( std::string::npos == wordStart )
410 {
411 if( NULL != remainderString )
412 {
413 remainderString->assign( "" );
414 }
415 return std::string( "" );
416 }
417 else
418 {
419 size_t wordEnd( stringToParse.find_first_of( separatorChars,
420 wordStart ) );
421 std::string returnString( stringToParse.substr( wordStart,
422 ( wordEnd - wordStart ) ) );
423 if( NULL != remainderString )
424 {
425 wordStart = stringToParse.find_first_not_of( separatorChars,
426 wordEnd );
427 if( std::string::npos != wordStart )
428 {
429 remainderString->assign( stringToParse.substr( wordStart ) );
430 }
431 else
432 {
433 remainderString->assign( "" );
434 }
435 }
436 return returnString;
437 }
438 }

◆ intForSingleDigit()

int BOL::StringParser::intForSingleDigit ( char const  singleDigitAsChar)
staticprotected

Definition at line 500 of file StringParser.cpp.

501 {
502 switch( singleDigitAsChar )
503 {
504 case '0':
505 return 0;
506 case '1':
507 return 1;
508 case '2':
509 return 2;
510 case '3':
511 return 3;
512 case '4':
513 return 4;
514 case '5':
515 return 5;
516 case '6':
517 return 6;
518 case '7':
519 return 7;
520 case '8':
521 return 8;
522 case '9':
523 return 9;
524 case 'A':
525 return 10;
526 case 'B':
527 return 11;
528 case 'C':
529 return 12;
530 case 'D':
531 return 13;
532 case 'E':
533 return 14;
534 case 'F':
535 return 15;
536 default:
537 return (int)(UsefulStuff::notANumber);
538 }
539 }
static double const notANumber
Definition: UsefulStuff.hpp:28

◆ intToSpacePaddedString()

std::string BOL::StringParser::intToSpacePaddedString ( int  inputInt,
int const  minimumNumberOfChars,
std::string const  prefixForPositiveNumbers = "+",
std::string const  prefixForNegativeNumbers = "-" 
)
inlinestatic

Definition at line 305 of file StringParser.hpp.

316 {
317 int
318 numberofSpaces( minimumNumberOfChars - numberOfDigitsInInt( inputInt ) );
319 if( 0 > inputInt )
320 {
321 --numberofSpaces;
322 }
323 std::string returnString( "" );
324 if( 0 < numberofSpaces )
325 {
326 returnString.append( (size_t)numberofSpaces,
327 ' ' );
328 }
329 returnString.append( intToString( inputInt,
330 1,
333 return returnString;
334 }
static std::string intToString(int inputInt, int const minimumNumberOfDigits, std::string const prefixForPositiveNumbers="+", std::string const prefixForNegativeNumbers="-", char const paddingChar='0')
static int numberOfDigitsInInt(int inputInt)

◆ intToString() [1/2]

std::string BOL::StringParser::intToString ( int  inputInt) const
inline

Definition at line 674 of file StringParser.hpp.

◆ intToString() [2/2]

std::string BOL::StringParser::intToString ( int  inputInt,
int const  minimumNumberOfDigits,
std::string const  prefixForPositiveNumbers = "+",
std::string const  prefixForNegativeNumbers = "-",
char const  paddingChar = '0' 
)
static

Definition at line 30 of file StringParser.cpp.

43 {
44 if( 0 >= minimumNumberOfDigits )
45 {
46 std::cout
47 << std::endl
48 << "BOL::warning! StringParser::intToString( "
49 << inputInt << ", " << minimumNumberOfDigits << ", "
51 << " ) could not fit the integer into the given size!";
52 // report a warning message.
53 return std::string( "please_give_a_positive_number_of_digits" );
54 }
55 std::string returnString( prefixForPositiveNumbers );
56 if( 0 > inputInt )
57 {
58 returnString.assign( prefixForNegativeNumbers );
59 inputInt = -inputInt;
60 }
61 // now the '+' or '-' or whatever is substituting has been inserted &
62 // inputInt is positive semi-definite.
63 std::string unpaddedIntAsString( positiveIntToString( inputInt ) );
64 int numberOfZeroesToInsert( minimumNumberOfDigits
65 - (int)(unpaddedIntAsString.size()) );
66 // if numberOfZeroesToInsert is negative, then the number was longer than
67 // the minimum output string length specified.
68 if( 0 < numberOfZeroesToInsert )
69 {
70 returnString.append( (size_t)numberOfZeroesToInsert,
71 paddingChar );
72 }
73 returnString.append( unpaddedIntAsString );
74 return returnString;
75 }

◆ isOnlyCharsIn()

bool BOL::StringParser::isOnlyCharsIn ( std::string const &  queryString,
std::string const &  charSet 
)
inlinestatic

Definition at line 437 of file StringParser.hpp.

440 {
441 return ( queryString.empty()
442 ||
443 ( std::string::npos != queryString.find_first_not_of( charSet ) ) );
444 }

◆ joinWithSeparator() [1/3]

std::string BOL::StringParser::joinWithSeparator ( std::list< std::string * > const &  stringsToJoin,
std::string const &  separatorString 
)
inlinestatic

Definition at line 622 of file StringParser.hpp.

627 {
628 if( !(stringsToJoin.empty()) )
629 {
630 std::list< std::string* >::const_iterator
631 stringIterator( stringsToJoin.begin() );
632 std::string returnString( *(*stringIterator) );
633 ++stringIterator;
634 while( stringsToJoin.end() != stringIterator )
635 {
636 returnString.append( separatorString );
637 returnString.append( *(*stringIterator) );
638 ++stringIterator;
639 }
640 return returnString;
641 }
642 else
643 {
644 return std::string( "" );
645 }
646 }

◆ joinWithSeparator() [2/3]

std::string BOL::StringParser::joinWithSeparator ( std::vector< std::string * > const &  stringsToJoin,
std::string const &  separatorString 
)
inlinestatic

Definition at line 596 of file StringParser.hpp.

601 {
602 if( !(stringsToJoin.empty()) )
603 {
604 std::string returnString( *(stringsToJoin.front()) );
605 for( std::vector< std::string* >::const_iterator
606 stringIterator( stringsToJoin.begin() + 1 );
607 stringsToJoin.end() > stringIterator;
608 ++stringIterator )
609 {
610 returnString.append( separatorString );
611 returnString.append( *(*stringIterator) );
612 }
613 return returnString;
614 }
615 else
616 {
617 return std::string( "" );
618 }
619 }

◆ joinWithSeparator() [3/3]

std::string BOL::StringParser::joinWithSeparator ( VectorlikeArray< std::string > const &  stringsToJoin,
std::string const &  separatorString 
)
inlinestatic

Definition at line 571 of file StringParser.hpp.

576 {
577 if( 0 < stringsToJoin.getSize() )
578 {
579 std::string returnString( stringsToJoin.getFront() );
580 for( int stringIndex( 1 );
581 stringsToJoin.getSize() > stringIndex;
582 ++stringIndex )
583 {
584 returnString.append( separatorString );
585 returnString.append( stringsToJoin[ stringIndex ] );
586 }
587 return returnString;
588 }
589 else
590 {
591 return std::string( "" );
592 }
593 }

◆ numberOfDigitsInInt()

int BOL::StringParser::numberOfDigitsInInt ( int  inputInt)
inlinestatic

Definition at line 287 of file StringParser.hpp.

289 {
290 if( 0 > inputInt )
291 {
292 inputInt = -inputInt;
293 }
294 int numberOfDigits( 1 );
295 int tenToNumberOfDigits( 10 );
296 while( inputInt >= tenToNumberOfDigits )
297 {
298 tenToNumberOfDigits *= 10;
299 ++numberOfDigits;
300 }
301 return numberOfDigits;
302 }

◆ parseByChar() [1/2]

void BOL::StringParser::parseByChar ( std::string const &  stringToParse,
VectorlikeArray< std::string > &  destinationArray,
char const &  divisionChar 
)
inlinestatic

Definition at line 559 of file StringParser.hpp.

563 {
564 parseByChar( stringToParse,
565 destinationArray,
566 std::string( 1,
567 divisionChar ) );
568 }
static void parseByChar(std::string const &stringToParse, VectorlikeArray< std::string > &destinationArray, std::string const &divisionCharSet=whitespaceChars)

◆ parseByChar() [2/2]

void BOL::StringParser::parseByChar ( std::string const &  stringToParse,
VectorlikeArray< std::string > &  destinationArray,
std::string const &  divisionCharSet = whitespaceChars 
)
inlinestatic

Definition at line 526 of file StringParser.hpp.

535 {
536 size_t wordStart( stringToParse.find_first_not_of( divisionCharSet ) );
537 size_t wordEnd( 0 );
538 while( std::string::npos != wordStart )
539 // if there are any more chars in stringToParse that are not in
540 // divisionCharSet, we have at least one substring to add.
541 {
542 wordEnd = stringToParse.find_first_of( divisionCharSet,
543 wordStart );
544 destinationArray.newEnd().assign( stringToParse.substr( wordStart,
545 ( wordEnd - wordStart ) ) );
546 if( std::string::npos != wordEnd )
547 {
548 wordStart = stringToParse.find_first_not_of( divisionCharSet,
549 wordEnd );
550 }
551 else
552 {
553 wordStart = std::string::npos;
554 }
555 }
556 }

◆ positiveIntToString()

std::string BOL::StringParser::positiveIntToString ( int  positiveInt)
staticprotected

Definition at line 542 of file StringParser.cpp.

545 {
546 int numberOfDigits( 1 );
547 int tenToNumberOfDigits( 10 );
548 while( positiveInt >= tenToNumberOfDigits )
549 {
550 tenToNumberOfDigits *= 10;
551 ++numberOfDigits;
552 }
553 std::string digitBuffer( "" );
554 int digitInt;
555 while( 0 < positiveInt )
556 {
557 tenToNumberOfDigits = ( tenToNumberOfDigits / 10 );
558 digitInt = 0;
559 while( tenToNumberOfDigits <= positiveInt )
560 {
561 positiveInt -= tenToNumberOfDigits;
562 ++digitInt;
563 }
564 digitBuffer.push_back( charForSingleDigit( digitInt ) );
565 }
566 for( int zeroesToPushBack( numberOfDigits - digitBuffer.size() );
567 0 < zeroesToPushBack;
568 --zeroesToPushBack )
569 {
570 digitBuffer.push_back( '0' );
571 }
572 return digitBuffer;
573 }
static char charForSingleDigit(int const singleDigitAsInt)

◆ setDefaults()

StringParser & BOL::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" 
)
inline

◆ stringIsDouble()

bool BOL::StringParser::stringIsDouble ( std::string const &  stringToInterpret,
double &  doubleToSet 
)
static

Definition at line 263 of file StringParser.cpp.

269 {
270 size_t charPosition( stringToInterpret.find_first_not_of(
272 if( charPosition == std::string::npos )
273 {
274 return false;
275 }
276 if( ( stringToInterpret[ charPosition ] == '+' )
277 ||
278 ( stringToInterpret[ charPosition ] == '-' ) )
279 {
280 if( charPosition == ( stringToInterpret.size() - 1 ) )
281 {
282 return false;
283 }
284 ++charPosition;
285 }
286 charPosition = stringToInterpret.find_first_not_of( digitChars,
287 charPosition );
288 if( ( charPosition != std::string::npos )
289 &&
290 ( stringToInterpret[ charPosition ] == '.' ) )
291 {
292 charPosition = stringToInterpret.find_first_not_of( digitChars,
293 ( charPosition + 1 ) );
294 }
295 if( ( charPosition < ( stringToInterpret.size() - 2 ) )
296 &&
297 ( ( stringToInterpret[ charPosition ] == 'e' )
298 ||
299 ( stringToInterpret[ charPosition ] == 'E' ) ) )
300 {
301 ++charPosition;
302 if( ( stringToInterpret[ charPosition ] == '+' )
303 ||
304 ( stringToInterpret[ charPosition ] == '-' ) )
305 {
306 ++charPosition;
307 }
308 charPosition = stringToInterpret.find_first_not_of( digitChars,
309 charPosition );
310 }
311 charPosition
312 = stringToInterpret.find_first_not_of( whitespaceAndNewlineChars,
313 charPosition );
314 if( charPosition == std::string::npos )
315 {
316 doubleToSet = stringToDouble( stringToInterpret );
317 return true;
318 }
319 return false;
320 }
static std::string const whitespaceAndNewlineChars
static std::string const digitChars
static double stringToDouble(std::string const &stringToInterpret)

◆ stringsMatchIgnoringCase()

bool BOL::StringParser::stringsMatchIgnoringCase ( std::string const &  firstString,
std::string const &  secondString 
)
static

Definition at line 220 of file StringParser.cpp.

224 {
225 if( firstString.size() != secondString.size() )
226 // if the strings don't match in size, they obviously do not match.
227 {
228 return false;
229 }
230 for( int charCounter( firstString.size() - 1 );
231 0 <= charCounter ;
232 --charCounter )
233 // go through each character in the string:
234 {
235 // if the strings do not match at this char, check to see if they are
236 // letters that just differ in case:
237 if( ( secondString[ charCounter ] != firstString[ charCounter ] )
238 &&
239 !( ( firstString[ charCounter ] >= 'A' )
240 &&
241 ( firstString[ charCounter ] <= 'Z' )
242 &&
243 ( secondString[ charCounter ]
244 == ( firstString[ charCounter ]
246 &&
247 !( ( firstString[ charCounter ] >= 'a' )
248 &&
249 ( firstString[ charCounter ] <= 'z' )
250 &&
251 ( secondString[ charCounter ]
252 == ( firstString[ charCounter ]
254 {
255 return false;
256 }
257 }
258 // if this point is reached, all the characters matched:
259 return true;
260 }
static char const lowercaseMinusUppercase

◆ stringToDouble()

double BOL::StringParser::stringToDouble ( std::string const &  stringToInterpret)
inlinestatic

Definition at line 422 of file StringParser.hpp.

423 {
424 double returnValue( UsefulStuff::notANumber );
425 std::stringstream( stringToInterpret ) >> returnValue;
426 return returnValue;
427 }

◆ stringToInt()

int BOL::StringParser::stringToInt ( std::string const &  stringToInterpret)
inlinestatic

Definition at line 414 of file StringParser.hpp.

415 {
416 int returnValue( 0 );
417 std::stringstream( stringToInterpret ) >> returnValue;
418 return returnValue;
419 }

◆ stringToIntVector()

std::vector< int > BOL::StringParser::stringToIntVector ( std::string  stringToInterpret)
static

Definition at line 323 of file StringParser.cpp.

324 {
325 substituteCharacterWith( stringToInterpret,
326 ',',
327 ' ' );
328 substituteCharacterWith( stringToInterpret,
329 ';',
330 ' ' );
331 std::vector< int > returnVector;
332 std::string indicesString( trimFromFrontAndBack( stringToInterpret,
334 if( !(indicesString.empty()) )
335 {
336 std::stringstream streamToParse( indicesString );
337 double parsedIntAsDouble;
338 while( streamToParse.good() )
339 {
340 streamToParse >> parsedIntAsDouble;
341 returnVector.push_back( (int)parsedIntAsDouble );
342 }
343 }
344 return returnVector;
345 }
static std::string trimFromFrontAndBack(std::string const &stringToTrim, std::string const &charsToTrim=whitespaceAndNewlineChars)
static void substituteCharacterWith(std::string &stringToTransform, char const charToBeReplaced, char const charToBePutIn)

◆ substituteCharacterWith()

void BOL::StringParser::substituteCharacterWith ( std::string &  stringToTransform,
char const  charToBeReplaced,
char const  charToBePutIn 
)
inlinestatic

Definition at line 373 of file StringParser.hpp.

376 {
377 for( int charCounter( stringToTransform.size() - 1 );
378 0 <= charCounter;
379 --charCounter )
380 // go through each character in the string:
381 {
382 // if it's charToBeReplaced, replace it with charToBePutIn:
383 if( charToBeReplaced == stringToTransform[ charCounter ] )
384 {
385 stringToTransform[ charCounter ] = charToBePutIn;
386 }
387 }
388 }

◆ substringToFirst() [1/2]

std::string BOL::StringParser::substringToFirst ( std::string const &  stringToParse,
std::string const &  delimiterOfSubstring,
std::string *const  remainderString = NULL 
)
inlinestatic

Definition at line 447 of file StringParser.hpp.

452 {
453 VectorlikeArray< std::string > stringVector( 1 );
454 stringVector[ 0 ].assign( delimiterOfSubstring );
455 return substringToFirst( stringToParse,
456 stringVector,
457 remainderString );
458 }
static std::string substringToFirst(std::string const &stringToParse, VectorlikeArray< std::string > const &delimitersOfSubstring, std::string *const remainderString=NULL)

◆ substringToFirst() [2/2]

std::string BOL::StringParser::substringToFirst ( std::string const &  stringToParse,
VectorlikeArray< std::string > const &  delimitersOfSubstring,
std::string *const  remainderString = NULL 
)
static

Definition at line 348 of file StringParser.cpp.

360 {
361 size_t
362 delimiterPosition( stringToParse.find( delimitersOfSubstring[ 0 ] ) );
363 size_t comparisonPosition;
364 for( int stringIndex( delimitersOfSubstring.getLastIndex() );
365 0 < stringIndex;
366 --stringIndex )
367 {
368 comparisonPosition
369 = stringToParse.find( delimitersOfSubstring[ stringIndex ] );
370 if( comparisonPosition < delimiterPosition )
371 {
372 delimiterPosition = comparisonPosition;
373 }
374 }
375
376 // now delimiterPosition marks the position of the first of any of the
377 // strings in delimitersOfSubstring which were found in stringToParse.
378 if( std::string::npos == delimiterPosition )
379 {
380 if( NULL != remainderString )
381 {
382 remainderString->assign( "" );
383 }
384 return stringToParse;
385 }
386 else
387 {
388 std::string returnString( stringToParse.begin(),
389 ( stringToParse.begin() + delimiterPosition ) );
390 if( NULL != remainderString )
391 {
392 remainderString->assign( ( stringToParse.begin() + delimiterPosition ),
393 stringToParse.end() );
394 }
395 return returnString;
396 }
397 }

◆ transformToLowercase()

void BOL::StringParser::transformToLowercase ( std::string &  stringToTransform)
inlinestatic

Definition at line 337 of file StringParser.hpp.

338 {
339 for( int charCounter( stringToTransform.size() - 1 );
340 0 <= charCounter;
341 --charCounter )
342 // go through each character in the string:
343 {
344 if( ( 'A' <= stringToTransform[ charCounter ] )
345 &&
346 ( 'Z' >= stringToTransform[ charCounter ] ) )
347 // if it's an uppercase character, replace it with its lowercase:
348 {
349 stringToTransform[ charCounter ] += lowercaseMinusUppercase;
350 }
351 }
352 }

◆ transformToUppercase()

void BOL::StringParser::transformToUppercase ( std::string &  stringToTransform)
inlinestatic

Definition at line 355 of file StringParser.hpp.

356 {
357 for( int charCounter( stringToTransform.size() - 1 );
358 0 <= charCounter;
359 --charCounter )
360 // go through each character in the string:
361 {
362 if( ( 'a' <= stringToTransform[ charCounter ] )
363 &&
364 ( 'z' >= stringToTransform[ charCounter ] ) )
365 // if it's a lowercase character, replace it with its uppercase:
366 {
367 stringToTransform[ charCounter ] -= lowercaseMinusUppercase;
368 }
369 }
370 }

◆ trimFromBack()

std::string BOL::StringParser::trimFromBack ( std::string const &  stringToTrim,
std::string const &  charsToTrim 
)
inlinestatic

Definition at line 482 of file StringParser.hpp.

488 {
489 size_t endOfReturnString( stringToTrim.find_last_not_of( charsToTrim ) );
490 if( endOfReturnString == std::string::npos )
491 {
492 return "";
493 }
494 else
495 {
496 return std::string( stringToTrim.begin(),
497 ( stringToTrim.begin() + endOfReturnString + 1 ) );
498 }
499 }

◆ trimFromFront()

std::string BOL::StringParser::trimFromFront ( std::string const &  stringToTrim,
std::string const &  charsToTrim 
)
inlinestatic

Definition at line 461 of file StringParser.hpp.

467 {
468 size_t
469 startOfReturnString( stringToTrim.find_first_not_of( charsToTrim ) );
470 if( std::string::npos == startOfReturnString )
471 {
472 return std::string( "" );
473 }
474 else
475 {
476 return std::string( ( stringToTrim.begin() + startOfReturnString ),
477 stringToTrim.end() );
478 }
479 }

◆ trimFromFrontAndBack()

std::string BOL::StringParser::trimFromFrontAndBack ( std::string const &  stringToTrim,
std::string const &  charsToTrim = whitespaceAndNewlineChars 
)
inlinestatic

Definition at line 502 of file StringParser.hpp.

509 {
510 size_t
511 startOfReturnString( stringToTrim.find_first_not_of( charsToTrim ) );
512 if( startOfReturnString == std::string::npos )
513 {
514 return "";
515 }
516 else
517 {
518 return std::string( ( stringToTrim.begin() + startOfReturnString ),
519 ( stringToTrim.begin()
520 + stringToTrim.find_last_not_of( charsToTrim )
521 + 1 ) );
522 }
523 }

Member Data Documentation

◆ digitChars

std::string const BOL::StringParser::digitChars
static

Definition at line 40 of file StringParser.hpp.

◆ exponentCharacter

std::string BOL::StringParser::exponentCharacter
protected

Definition at line 281 of file StringParser.hpp.

◆ lowercaseAlphabetChars

std::string const BOL::StringParser::lowercaseAlphabetChars
static

Definition at line 38 of file StringParser.hpp.

◆ lowercaseMinusUppercase

char const BOL::StringParser::lowercaseMinusUppercase
staticprotected

Definition at line 258 of file StringParser.hpp.

◆ minimumNumberOfDigitsForInts

int BOL::StringParser::minimumNumberOfDigitsForInts
protected

Definition at line 273 of file StringParser.hpp.

◆ negativeExponentPrefix

std::string BOL::StringParser::negativeExponentPrefix
protected

Definition at line 280 of file StringParser.hpp.

◆ newlineChars

std::string const BOL::StringParser::newlineChars
static

Definition at line 36 of file StringParser.hpp.

◆ numberOfExponentDigits

int BOL::StringParser::numberOfExponentDigits
protected

Definition at line 276 of file StringParser.hpp.

◆ numberOfMantissaDigits

int BOL::StringParser::numberOfMantissaDigits
protected

Definition at line 275 of file StringParser.hpp.

◆ paddingCharForInts

char BOL::StringParser::paddingCharForInts
protected

Definition at line 274 of file StringParser.hpp.

◆ positiveExponentPrefix

std::string BOL::StringParser::positiveExponentPrefix
protected

Definition at line 279 of file StringParser.hpp.

◆ prefixForNegativeNumbers

std::string BOL::StringParser::prefixForNegativeNumbers
protected

Definition at line 278 of file StringParser.hpp.

◆ prefixForPositiveNumbers

std::string BOL::StringParser::prefixForPositiveNumbers
protected

Definition at line 277 of file StringParser.hpp.

◆ uppercaseAlphabetChars

std::string const BOL::StringParser::uppercaseAlphabetChars
static

Definition at line 39 of file StringParser.hpp.

◆ whitespaceAndNewlineChars

std::string const BOL::StringParser::whitespaceAndNewlineChars
static

Definition at line 37 of file StringParser.hpp.

◆ whitespaceChars

std::string const BOL::StringParser::whitespaceChars
static

Definition at line 35 of file StringParser.hpp.


The documentation for this class was generated from the following files: