Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Mar 10, 2006, 4:52:21 AM (18 years ago)
Author:
bensch
Message:

orxonox/trunk: new SubString class

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/std/src/lib/util/helper_functions.cc

    r7203 r7211  
    2727 * @return returns the bool, if BOOL was correct otherwise defaultValue
    2828 */
    29 bool isBool(const char* BOOL, bool defaultValue)
     29bool isBool(const std::string& BOOL, bool defaultValue)
    3030{
    31   if (BOOL == NULL)
     31  if (BOOL.empty())
    3232    return defaultValue;
    33   if(!strcmp(BOOL, "1") || !strcasecmp( BOOL, "true") )
     33  if(BOOL[0] == '1' || BOOL == "true" )
    3434    return true;
    35   else if (!strcmp(BOOL, "0") || !strcasecmp( BOOL, "false"))
     35  else if (BOOL[0] == '0' || BOOL == "false")
    3636    return false;
    3737  else
    3838    return defaultValue;
    39 
    4039}
    4140
     
    4746 * @return returns the contained int, if INT was correct otherwise defaultValue
    4847 */
    49 int isInt(const char* INT, int defaultValue)
     48int isInt(const std::string& INT, int defaultValue)
    5049{
    51   if (INT == NULL)
     50  if (INT.empty())
    5251    return defaultValue;
    5352  char* endPtr = NULL;
    5453
    55   int result = strtol(INT, &endPtr, 10);
     54  int result = strtol(INT.c_str(), &endPtr, 10);
    5655
    57   if ( endPtr >= INT && endPtr < INT + strlen(INT))
     56  if ( endPtr >= INT.c_str() && endPtr < INT.c_str()+ INT.size())
    5857    return defaultValue;
    5958  else
     
    6867 * @return returns the contained float, if FLOAT was correct otherwise defaultValue
    6968 */
    70 float isFloat(const char* FLOAT, float defaultValue)
     69float isFloat(const std::string& FLOAT, float defaultValue)
    7170{
    72   if (FLOAT == NULL)
     71  if (FLOAT.empty())
    7372    return defaultValue;
    7473  char* endPtr = NULL;
    75   double result = strtod(FLOAT, &endPtr);
     74  double result = strtod(FLOAT.c_str(), &endPtr);
    7675
    77   if ( endPtr >= FLOAT && endPtr < FLOAT + strlen(FLOAT))
     76  if ( endPtr >= FLOAT.c_str() && endPtr < FLOAT.c_str() + FLOAT.size())
    7877    return defaultValue;
    7978  else
     
    8887 * @return returns the contained string (char-array), if STRING was correct otherwise defaultValue
    8988 */
    90 const char* isCString(const char* STRING, const char* defaultValue)
     89const char* isCString(const std::string& STRING, const char* defaultValue)
    9190{
    92   if (STRING != NULL && strlen(STRING) > 0)
    93     return STRING;
     91  if (STRING.size() > 0)
     92    return STRING.c_str();
    9493  else
    9594    return defaultValue;
     
    102101 * @return returns the contained string (char-array), if STRING was correct otherwise defaultValue
    103102 */
    104 std::string isString(const char* STRING, const std::string& defaultValue)
     103std::string isString(const std::string& STRING, const std::string& defaultValue)
    105104{
    106   if (STRING != NULL && strlen(STRING) > 0)
     105  if (STRING.size() > 0)
    107106    return STRING;
    108107  else
Note: See TracChangeset for help on using the changeset viewer.