Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Mar 9, 2006, 5:28:10 PM (18 years ago)
Author:
bensch
Message:

orxonox/trunk: compiles again, BUT well…. i do not expect it to run anymore

File:
1 edited

Legend:

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

    r5331 r7203  
    2222
    2323/**
    24  * checks if the input was a bool
     24 * @brief checks if the input was a bool
    2525 * @param BOOL a String that holds a bool: must be one of those: 1,0,true,false(case-insensitive)
    2626 * @param defaultValue a default value that is set, if BOOL is corrupt
     
    4242
    4343/**
    44  * checks if the input was a int
     44 * @brief checks if the input was a int
    4545 * @param INT a String that holds an int.
    4646 * @param defaultValue a default value that is set, if INT is corrupt
     
    6363
    6464/**
    65  * checks if the input was a float
     65 * @brief checks if the input was a float
    6666 * @param FLOAT a String that holds an float.
    6767 * @param defaultValue a default value that is set, if FLOAT is corrupt
     
    8383
    8484/**
    85  * checks if the input was a string
     85 * @brief checks if the input was a string
    8686 * @param STING a String(char-array) that holds an string.
    8787 * @param defaultValue a default value that is set, if STRING is corrupt
    8888 * @return returns the contained string (char-array), if STRING was correct otherwise defaultValue
    8989 */
    90 const char* isString(const char* STRING, const char* defaultValue)
     90const char* isCString(const char* STRING, const char* defaultValue)
    9191{
    9292  if (STRING != NULL && strlen(STRING) > 0)
     
    9595    return defaultValue;
    9696}
     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 */
     104std::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 */
     118int 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.