Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Apr 1, 2012, 11:07:02 AM (13 years ago)
Author:
landauf
Message:

small fixes and adjustments of code and documentation

Location:
code/branches/testing/src/libraries/util
Files:
2 edited

Legend:

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

    r8858 r9076  
    8181    }
    8282
    83     /// Splits a given string by a delimiter and stores it in an output vector
     83    /// Splits a given string by a delimiter and stores it in an output vector. See @ref SubString for a more sophisticated implementation.
    8484    void vectorize(const std::string& str, char delimiter, std::vector<std::string>* output)
    8585    {
     86        output->clear();
    8687        for (size_t start = 0, end = 0; end != std::string::npos; start = end + 1)
    8788        {
     
    9293
    9394    /**
    94         @brief Returns the position of the next quotation mark in the string, starting with start.
     95        @brief Returns the position of the next quotation mark in the string, starting with start. Escaped quotation marks (with \ in front) are not considered.
    9596        @param str The string
    9697        @param start The first position to look at
     
    130131        size_t quote = static_cast<size_t>(-1);
    131132        while ((quote = getNextQuote(str, quote + 1)) < pos)
    132         {
    133             if (quote == pos)
    134                 return false;
    135133            quotecount++;
    136         }
    137 
     134
     135        if (quote == pos)
     136            return false;
    138137        if (quote == std::string::npos)
    139138            return false;
     
    156155        size_t pos2 = getNextQuote(str, pos1 + 1);
    157156        if (pos1 != std::string::npos && pos2 != std::string::npos)
    158             return str.substr(pos1, pos2 - pos1 + 1);
     157            return str.substr(pos1 + 1, pos2 - pos1 - 1);
    159158        else
    160159            return "";
     
    247246    {
    248247        return getStripped(str).empty();
    249     }
    250 
    251     /// Determines if a string contains only numbers and maximal one '.'.
    252     bool isNumeric(const std::string& str)
    253     {
    254         bool foundPoint = false;
    255 
    256         for (std::string::const_iterator it = str.begin(); it != str.end(); ++it)
    257         {
    258             if (((*it) < '0' || (*it) > '9'))
    259             {
    260                 if ((*it) != '.' && !foundPoint)
    261                     foundPoint = true;
    262                 else
    263                     return false;
    264             }
    265         }
    266 
    267         return true;
    268248    }
    269249
     
    444424    bool hasComment(const std::string& str)
    445425    {
    446         return (getCommentPosition(str) != std::string::npos);
    447     }
    448 
    449     /// If the string contains a comment, the comment gets returned (including the comment symbol), an empty string otherwise.
     426        return (getNextCommentPosition(str) != std::string::npos);
     427    }
     428
     429    /// If the string contains a comment, the comment gets returned (including the comment symbol and white spaces in front of it), an empty string otherwise.
    450430    std::string getComment(const std::string& str)
    451431    {
    452         return str.substr(getCommentPosition(str));
    453     }
    454 
    455     /// If the string contains a comment, the position of the comment-symbol gets returned, @c std::string::npos otherwise.
    456     size_t getCommentPosition(const std::string& str)
    457     {
    458         return getNextCommentPosition(str, 0);
    459     }
    460 
    461     /**
    462         @brief Returns the position of the next comment-symbol, starting with @a start.
     432        size_t pos = getNextCommentPosition(str);
     433        if (pos == std::string::npos)
     434            return "";
     435        else
     436            return str.substr(pos);
     437    }
     438
     439    /**
     440        @brief Returns the beginning of the next comment including whitespaces in front of the comment symbol.
    463441        @param str The string
    464442        @param start The first position to look at
  • code/branches/testing/src/libraries/util/StringUtils.h

    r8858 r9076  
    5858    _UtilExport void         vectorize(const std::string& str, char delimiter, std::vector<std::string>* output);
    5959
    60     _UtilExport size_t       getNextQuote(const std::string& str, size_t start);
     60    _UtilExport size_t       getNextQuote(const std::string& str, size_t start = 0);
    6161    _UtilExport bool         isBetweenQuotes(const std::string& str, size_t pos);
    6262
     
    6969    _UtilExport bool         isEmpty(const std::string& str);
    7070    _UtilExport bool         isComment(const std::string& str);
    71     _UtilExport bool         isNumeric(const std::string& str);
    7271
    7372    _UtilExport std::string  addSlashes(const std::string& str);
     
    8584    _UtilExport bool         hasComment(const std::string& str);
    8685    _UtilExport std::string  getComment(const std::string& str);
    87     _UtilExport size_t       getCommentPosition(const std::string& str);
    8886    _UtilExport size_t       getNextCommentPosition(const std::string& str, size_t start = 0);
    8987
Note: See TracChangeset for help on using the changeset viewer.