Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Apr 10, 2008, 4:39:06 PM (17 years ago)
Author:
landauf
Message:

changed ConfigValueContainer to use ConfigFileManager, but there is still an error

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/core2/src/util/String.cc

    r1006 r1020  
    6262std::string removeTrailingWhitespaces(const std::string& str)
    6363{
     64    unsigned int pos1 = 0;
     65    unsigned int pos2 = str.size() - 1;
     66    for (; pos1 < str.size() && (str[pos1] == ' ' || str[pos1] == '\t' || str[pos1] == '\n'); pos1++);
     67    for (; pos2 >= 0         && (str[pos2] == ' ' || str[pos2] == '\t' || str[pos2] == '\n'); pos2--);
     68    return str.substr(pos1, pos2 - pos1 + 1);
     69}
     70
     71/**
     72    @brief Returns the position of the next quote in the string, starting with start.
     73    @param str The string
     74    @param start The startposition
     75    @return The position of the next quote (std::string::npos if there is no next quote)
     76*/
     77unsigned int getNextQuote(const std::string& str, unsigned int start)
     78{
     79    unsigned int quote = start - 1;
     80
     81    while ((quote = str.find('\"', quote + 1)) != std::string::npos)
     82    {
     83        unsigned int backslash = quote;
     84        unsigned int numbackslashes = 0;
     85        for (; backslash > 0; backslash--, numbackslashes++)
     86            if (str[backslash - 1] != '\\')
     87                break;
     88
     89        if (numbackslashes % 2 == 0)
     90            break;
     91    }
     92
     93    return quote;
    6494}
    6595
     
    71101bool hasStringBetweenQuotes(const std::string& str)
    72102{
     103    unsigned int pos1 = getNextQuote(str, 0);
     104    unsigned int pos2 = getNextQuote(str, pos1 + 1);
     105    return (pos1 != std::string::npos && pos2 != std::string::npos && pos2 > pos1 + 1);
    73106}
    74107
     
    80113std::string getStringBetweenQuotes(const std::string& str)
    81114{
     115    unsigned int pos1 = getNextQuote(str, 0);
     116    unsigned int pos2 = getNextQuote(str, pos1 + 1);
     117    if (pos1 != std::string::npos && pos2 != std::string::npos)
     118        return str.substr(pos1, pos2 - pos1 + 1);
     119    else
     120        return "";
    82121}
    83122
Note: See TracChangeset for help on using the changeset viewer.