Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Sep 3, 2010, 12:19:53 AM (14 years ago)
Author:
landauf
Message:

added documentation

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/doc/src/libraries/util/StringUtils.cc

    r7297 r7327  
    4141namespace orxonox
    4242{
     43    /// A blank string (""). Used to return a blank string by reference.
    4344    std::string BLANKSTRING;
    4445
     46    /// Returns a string of a unique number. This function is guaranteed to never return the same string twice.
    4547    std::string getUniqueNumberString()
    4648    {
     
    4850    }
    4951
    50     /**
    51         @brief Removes all whitespaces from a string.
    52         @param str The string to strip
    53     */
     52    /// Removes all whitespaces from a string.
    5453    void strip(std::string* str)
    5554    {
     
    6362    }
    6463
    65     /**
    66         @brief Returns a copy of a string without whitespaces.
    67         @param str The string to strip
    68         @return The stripped line
    69     */
     64    /// Returns a copy of a string without whitespaces.
    7065    std::string getStripped(const std::string& str)
    7166    {
     
    7570    }
    7671
    77     /**
    78         @brief Returns a copy of a string without trailing whitespaces.
    79         @param str The string
    80         @return The modified copy
    81     */
     72    /// Returns a copy of a string without trailing whitespaces.
    8273    std::string removeTrailingWhitespaces(const std::string& str)
    8374    {
     
    9081
    9182    /**
    92         @brief Returns the position of the next quote in the string, starting with start.
     83        @brief Returns the position of the next quotation mark in the string, starting with start.
    9384        @param str The string
    94         @param start The startposition
    95         @return The position of the next quote (std::string::npos if there is no next quote)
     85        @param start The first position to look at
     86        @return The position of the next quotation mark (@c std::string::npos if there is none)
    9687    */
    9788    size_t getNextQuote(const std::string& str, size_t start)
     
    115106
    116107    /**
    117         @brief Returns true if pos is between two quotes.
     108        @brief Returns true if pos is between two quotation marks.
    118109        @param str The string
    119110        @param pos The position to check
    120         @return True if pos is between two quotes
     111        @return True if pos is between two quotation marks
    121112    */
    122113    bool isBetweenQuotes(const std::string& str, size_t pos)
     
    140131    }
    141132
    142     /**
    143         @brief Returns true if the string contains something like '..."between quotes"...'.
    144         @param str The string
    145         @return True if there is something between quotes
    146     */
     133    /// Returns true if the string contains something like '..."between quotaton marks"...'.
    147134    bool hasStringBetweenQuotes(const std::string& str)
    148135    {
     
    152139    }
    153140
    154     /**
    155         @brief If the string contains something like '..."between quotes"...' then 'between quotes' gets returned (without quotes).
    156         @param str The string between the quotes
    157     */
     141    /// If the string contains something like '..."between quotaton marks"...' then 'between quotaton marks' gets returned, otherwise "".
    158142    std::string getStringBetweenQuotes(const std::string& str)
    159143    {
     
    167151
    168152    /**
    169         @brief Removes enclosing quotes if available (including whitespaces at the outside of the quotes).
    170         @param str The string to strip
    171         @return The string with removed quotes
     153        @brief Removes enclosing quotation marks if available (including whitespaces at the outside of the quotation marks).
     154        @return The striped string without quotation marks
    172155    */
    173156    std::string stripEnclosingQuotes(const std::string& str)
     
    207190
    208191    /**
    209         @brief Removes enclosing {braces} (braces must be exactly on the beginning and the end of the string).
    210         @param str The string to strip
    211         @return The striped string
     192        @brief Removes enclosing braces '{' and '}' (the braces must be exactly on the beginning and the end of the string).
     193        @return The striped string without braces
    212194    */
    213195    std::string stripEnclosingBraces(const std::string& str)
     
    223205    /**
    224206        @brief Determines if a string is a comment (starts with a comment-symbol).
    225         @param str The string to check
    226         @return True = it's a comment
    227207
    228208        A comment is defined by a leading '#', '%', ';' or '//'.
     
    252232    }
    253233
    254     /**
    255         @brief Determines if a string is empty (contains only whitespaces).
    256         @param str The string to check
    257         @return True = it's empty
    258     */
     234    /// Determines if a string is empty (contains only whitespaces).
    259235    bool isEmpty(const std::string& str)
    260236    {
     
    262238    }
    263239
    264     /**
    265         @brief Determines if a string contains only numbers and maximal one '.'.
    266         @param str The string to check
    267         @return True = it's a number
    268     */
     240    /// Determines if a string contains only numbers and maximal one '.'.
    269241    bool isNumeric(const std::string& str)
    270242    {
     
    287259    /**
    288260        @brief Adds backslashes to the given string which makes special chars visible. Existing slashes will be doubled.
    289         @param str The string to manipulate
    290         @return The string with added slashes
     261
     262        This function converts all special chars like line breaks, tabs, quotation marks etc. into
     263        a human readable format by adding a backslash. So for example "\n" will be converted to
     264        "\\" + "n".
     265
     266        This is usually used when a string is written to a file.
     267
     268        @see removeSlashes
    291269    */
    292270    std::string addSlashes(const std::string& str)
     
    319297    /**
    320298        @brief Removes backslashes from the given string. Double backslashes are interpreted as one backslash.
    321         @param str The string to manipulate
    322         @return The string with removed slashes
     299
     300        This function removes all backslashes and converts the human readable equivalents of
     301        special chars like "\\" + "n" into their real meaning (in this case a line break or "\n").
     302
     303        This is usually used when reading a string from a file.
     304
     305        @see addSlashes
    323306    */
    324307    std::string removeSlashes(const std::string& str)
     
    360343    }
    361344
    362     /**
    363         @brief Replaces each char between A and Z with its lowercase equivalent.
    364         @param str The string to convert
    365     */
     345    /// Replaces each char between A and Z with its lowercase equivalent.
    366346    void lowercase(std::string* str)
    367347    {
     
    372352    }
    373353
    374     /**
    375         @brief Returns a copy of the given string without uppercase chars.
    376         @param str The string
    377         @return The copy
    378     */
     354    /// Returns a copy of the given string where all chars are converted to lowercase.
    379355    std::string getLowercase(const std::string& str)
    380356    {
     
    384360    }
    385361
    386     /**
    387         @brief Replaces each char between a and z with its uppercase equivalent.
    388         @param str The string to convert
    389     */
     362    /// Replaces each char between a and z with its uppercase equivalent.
    390363    void uppercase(std::string* str)
    391364    {
     
    396369    }
    397370
    398     /**
    399         @brief Returns a copy of the given string without lowercase chars.
    400         @param str The string
    401         @return The copy
    402     */
     371    /// Returns a copy of the given string where all chars are converted to uppercase.
    403372    std::string getUppercase(const std::string& str)
    404373    {
     
    410379    /**
    411380        @brief Compares two strings ignoring different casing.
    412         @param s1 First string
    413         @param s2 Second string
     381        @return s1 == s1 -> returns 0 / s1 < s2 -> returns -1 / s1 >= s2 -> returns 1
    414382    */
    415383    int nocaseCmp(const std::string& s1, const std::string& s2)
     
    437405
    438406    /**
    439         @brief Compares the first 'len' chars of two strings ignoring different casing.
     407        @brief Compares the first @a len chars of two strings ignoring different casing.
    440408        @param s1 First string
    441409        @param s2 Second string
     
    462430    }
    463431
    464     /**
    465         @brief Returns true if the string contains a comment, introduced by #, %, ; or //.
     432    /// Returns true if the string contains a comment, introduced by #, %, ; or //.
     433    bool hasComment(const std::string& str)
     434    {
     435        return (getCommentPosition(str) != std::string::npos);
     436    }
     437
     438    /// If the string contains a comment, the comment gets returned (including the comment symbol), an empty string otherwise.
     439    std::string getComment(const std::string& str)
     440    {
     441        return str.substr(getCommentPosition(str));
     442    }
     443
     444    /// If the string contains a comment, the position of the comment-symbol gets returned, @c std::string::npos otherwise.
     445    size_t getCommentPosition(const std::string& str)
     446    {
     447        return getNextCommentPosition(str, 0);
     448    }
     449
     450    /**
     451        @brief Returns the position of the next comment-symbol, starting with @a start.
    466452        @param str The string
    467         @return True if the string contains a comment
    468     */
    469     bool hasComment(const std::string& str)
    470     {
    471         return (getCommentPosition(str) != std::string::npos);
    472     }
    473 
    474     /**
    475         @brief If the string contains a comment, the comment gets returned (including the comment symbol), an empty string otherwise.
    476         @param str The string
    477         @return The comment
    478     */
    479     std::string getComment(const std::string& str)
    480     {
    481         return str.substr(getCommentPosition(str));
    482     }
    483 
    484     /**
    485         @brief If the string contains a comment, the position of the comment-symbol gets returned, std::string::npos otherwise.
    486         @param str The string
    487         @return The position
    488     */
    489     size_t getCommentPosition(const std::string& str)
    490     {
    491         return getNextCommentPosition(str, 0);
    492     }
    493 
    494     /**
    495         @brief Returns the position of the next comment-symbol, starting with start.
    496         @param str The string
    497         @param start The startposition
    498         @return The position
     453        @param start The first position to look at
    499454    */
    500455    size_t getNextCommentPosition(const std::string& str, size_t start)
Note: See TracChangeset for help on using the changeset viewer.