Changeset 7203 in orxonox.OLD for branches/std/src/lib/util/helper_functions.cc
- Timestamp:
- Mar 9, 2006, 5:28:10 PM (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/std/src/lib/util/helper_functions.cc
r5331 r7203 22 22 23 23 /** 24 * checks if the input was a bool24 * @brief checks if the input was a bool 25 25 * @param BOOL a String that holds a bool: must be one of those: 1,0,true,false(case-insensitive) 26 26 * @param defaultValue a default value that is set, if BOOL is corrupt … … 42 42 43 43 /** 44 * checks if the input was a int44 * @brief checks if the input was a int 45 45 * @param INT a String that holds an int. 46 46 * @param defaultValue a default value that is set, if INT is corrupt … … 63 63 64 64 /** 65 * checks if the input was a float65 * @brief checks if the input was a float 66 66 * @param FLOAT a String that holds an float. 67 67 * @param defaultValue a default value that is set, if FLOAT is corrupt … … 83 83 84 84 /** 85 * checks if the input was a string85 * @brief checks if the input was a string 86 86 * @param STING a String(char-array) that holds an string. 87 87 * @param defaultValue a default value that is set, if STRING is corrupt 88 88 * @return returns the contained string (char-array), if STRING was correct otherwise defaultValue 89 89 */ 90 const char* is String(const char* STRING, const char* defaultValue)90 const char* isCString(const char* STRING, const char* defaultValue) 91 91 { 92 92 if (STRING != NULL && strlen(STRING) > 0) … … 95 95 return defaultValue; 96 96 } 97 98 /** 99 * @brief checks if the input was a string 100 * @param STING a String(char-array) that holds an string. 101 * @param defaultValue a default value that is set, if STRING is corrupt 102 * @return returns the contained string (char-array), if STRING was correct otherwise defaultValue 103 */ 104 std::string isString(const char* STRING, const std::string& defaultValue) 105 { 106 if (STRING != NULL && strlen(STRING) > 0) 107 return STRING; 108 else 109 return defaultValue; 110 } 111 112 113 /** 114 * @brief compares two strings without ignoring the case 115 * @param s1 first string 116 * @param s2 second string 117 */ 118 int nocase_cmp(const std::string& s1, const std::string& s2) 119 { 120 std::string::const_iterator it1=s1.begin(); 121 std::string::const_iterator it2=s2.begin(); 122 123 //stop when either string's end has been reached 124 while ( (it1!=s1.end()) && (it2!=s2.end()) ) 125 { 126 if(::toupper(*it1) != ::toupper(*it2)) //letters differ? 127 // return -1 to indicate smaller than, 1 otherwise 128 return (::toupper(*it1) < ::toupper(*it2)) ? -1 : 1; 129 //proceed to the next character in each string 130 ++it1; 131 ++it2; 132 } 133 size_t size1=s1.size(), size2=s2.size();// cache lengths 134 //return -1,0 or 1 according to strings' lengths 135 if (size1==size2) 136 return 0; 137 return (size1<size2) ? -1 : 1; 138 } 139
Note: See TracChangeset
for help on using the changeset viewer.