Changeset 7211 in orxonox.OLD for branches/std/src/lib/util/helper_functions.cc
- Timestamp:
- Mar 10, 2006, 4:52:21 AM (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/std/src/lib/util/helper_functions.cc
r7203 r7211 27 27 * @return returns the bool, if BOOL was correct otherwise defaultValue 28 28 */ 29 bool isBool(const char*BOOL, bool defaultValue)29 bool isBool(const std::string& BOOL, bool defaultValue) 30 30 { 31 if (BOOL == NULL)31 if (BOOL.empty()) 32 32 return defaultValue; 33 if( !strcmp(BOOL, "1") || !strcasecmp( BOOL, "true"))33 if(BOOL[0] == '1' || BOOL == "true" ) 34 34 return true; 35 else if ( !strcmp(BOOL, "0") || !strcasecmp( BOOL, "false"))35 else if (BOOL[0] == '0' || BOOL == "false") 36 36 return false; 37 37 else 38 38 return defaultValue; 39 40 39 } 41 40 … … 47 46 * @return returns the contained int, if INT was correct otherwise defaultValue 48 47 */ 49 int isInt(const char*INT, int defaultValue)48 int isInt(const std::string& INT, int defaultValue) 50 49 { 51 if (INT == NULL)50 if (INT.empty()) 52 51 return defaultValue; 53 52 char* endPtr = NULL; 54 53 55 int result = strtol(INT , &endPtr, 10);54 int result = strtol(INT.c_str(), &endPtr, 10); 56 55 57 if ( endPtr >= INT && endPtr < INT + strlen(INT))56 if ( endPtr >= INT.c_str() && endPtr < INT.c_str()+ INT.size()) 58 57 return defaultValue; 59 58 else … … 68 67 * @return returns the contained float, if FLOAT was correct otherwise defaultValue 69 68 */ 70 float isFloat(const char*FLOAT, float defaultValue)69 float isFloat(const std::string& FLOAT, float defaultValue) 71 70 { 72 if (FLOAT == NULL)71 if (FLOAT.empty()) 73 72 return defaultValue; 74 73 char* endPtr = NULL; 75 double result = strtod(FLOAT , &endPtr);74 double result = strtod(FLOAT.c_str(), &endPtr); 76 75 77 if ( endPtr >= FLOAT && endPtr < FLOAT + strlen(FLOAT))76 if ( endPtr >= FLOAT.c_str() && endPtr < FLOAT.c_str() + FLOAT.size()) 78 77 return defaultValue; 79 78 else … … 88 87 * @return returns the contained string (char-array), if STRING was correct otherwise defaultValue 89 88 */ 90 const char* isCString(const char*STRING, const char* defaultValue)89 const char* isCString(const std::string& STRING, const char* defaultValue) 91 90 { 92 if (STRING != NULL && strlen(STRING) > 0)93 return STRING ;91 if (STRING.size() > 0) 92 return STRING.c_str(); 94 93 else 95 94 return defaultValue; … … 102 101 * @return returns the contained string (char-array), if STRING was correct otherwise defaultValue 103 102 */ 104 std::string isString(const char*STRING, const std::string& defaultValue)103 std::string isString(const std::string& STRING, const std::string& defaultValue) 105 104 { 106 if (STRING != NULL && strlen(STRING) > 0)105 if (STRING.size() > 0) 107 106 return STRING; 108 107 else
Note: See TracChangeset
for help on using the changeset viewer.