Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Oct 6, 2008, 1:05:07 AM (16 years ago)
Author:
landauf
Message:

unsigned int → size_t for std::string related functions
I hope this fixes some problems on 64bit systems

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/trunk/src/util/String.cc

    r1830 r1889  
    4848void strip(std::string* str)
    4949{
    50     unsigned int pos;
     50    size_t pos;
    5151    while ((pos = (*str).find(" ")) < (*str).length())
    5252        (*str).erase(pos, 1);
     
    7676std::string removeTrailingWhitespaces(const std::string& str)
    7777{
    78     unsigned int pos1 = 0;
     78    size_t pos1 = 0;
    7979    int pos2 = str.size() - 1;
    8080    for (; pos1 < str.size() && (str[pos1] == ' ' || str[pos1] == '\t' || str[pos1] == '\n'); pos1++);
    81     for (; pos2 > 0          && (str[pos2] == ' ' || str[pos2] == '\t' || str[pos2] == '\n'); pos2--);
     81    for (; pos2 != 0         && (str[pos2] == ' ' || str[pos2] == '\t' || str[pos2] == '\n'); pos2--);
    8282    return str.substr(pos1, pos2 - pos1 + 1);
    8383}
     
    8989    @return The position of the next quote (std::string::npos if there is no next quote)
    9090*/
    91 unsigned int getNextQuote(const std::string& str, unsigned int start)
    92 {
    93     unsigned int quote = start - 1;
     91size_t getNextQuote(const std::string& str, size_t start)
     92{
     93    size_t quote = start - 1;
    9494
    9595    while ((quote = str.find('\"', quote + 1)) != std::string::npos)
    9696    {
    97         unsigned int backslash = quote;
    98         unsigned int numbackslashes = 0;
     97        size_t backslash = quote;
     98        size_t numbackslashes = 0;
    9999        for (; backslash > 0; backslash--, numbackslashes++)
    100100            if (str[backslash - 1] != '\\')
     
    114114    @return True if pos is between two quotes
    115115*/
    116 bool isBetweenQuotes(const std::string& str, unsigned int pos)
     116bool isBetweenQuotes(const std::string& str, size_t pos)
    117117{
    118118    if (pos == std::string::npos)
    119119        return false;
    120120
    121     unsigned int quotecount = 0;
    122     unsigned int quote = (unsigned int)-1;
     121    size_t quotecount = 0;
     122    size_t quote = (size_t)-1;
    123123    while ((quote = getNextQuote(str, quote + 1)) < pos)
    124124    {
     
    141141bool hasStringBetweenQuotes(const std::string& str)
    142142{
    143     unsigned int pos1 = getNextQuote(str, 0);
    144     unsigned int pos2 = getNextQuote(str, pos1 + 1);
     143    size_t pos1 = getNextQuote(str, 0);
     144    size_t pos2 = getNextQuote(str, pos1 + 1);
    145145    return (pos1 != std::string::npos && pos2 != std::string::npos && pos2 > pos1 + 1);
    146146}
     
    153153std::string getStringBetweenQuotes(const std::string& str)
    154154{
    155     unsigned int pos1 = getNextQuote(str, 0);
    156     unsigned int pos2 = getNextQuote(str, pos1 + 1);
     155    size_t pos1 = getNextQuote(str, 0);
     156    size_t pos2 = getNextQuote(str, pos1 + 1);
    157157    if (pos1 != std::string::npos && pos2 != std::string::npos)
    158158        return str.substr(pos1, pos2 - pos1 + 1);
     
    168168std::string stripEnclosingQuotes(const std::string& str)
    169169{
    170     unsigned int start = std::string::npos;
    171     unsigned int end = 0;
    172 
    173     for (unsigned int pos = 0; (pos < str.size()) && (pos < std::string::npos); pos++)
     170    size_t start = std::string::npos;
     171    size_t end = 0;
     172
     173    for (size_t pos = 0; (pos < str.size()) && (pos < std::string::npos); pos++)
    174174    {
    175175        if (str[pos] == '"')
     
    183183    }
    184184
    185     for (unsigned int pos = str.size() - 1; pos < std::string::npos; pos--)
     185    for (size_t pos = str.size() - 1; pos < std::string::npos; pos--)
    186186    {
    187187        if (str[pos] == '"')
     
    290290    std::string output = str;
    291291
    292     for (unsigned int pos = 0; (pos = output.find('\\', pos)) < std::string::npos; pos += 2) { output.replace(pos, 1, "\\\\"); }
    293     for (unsigned int pos = 0; (pos = output.find('\n', pos)) < std::string::npos; pos += 2) { output.replace(pos, 1, "\\n"); }
    294     for (unsigned int pos = 0; (pos = output.find('\t', pos)) < std::string::npos; pos += 2) { output.replace(pos, 1, "\\t"); }
    295     for (unsigned int pos = 0; (pos = output.find('\v', pos)) < std::string::npos; pos += 2) { output.replace(pos, 1, "\\v"); }
    296     for (unsigned int pos = 0; (pos = output.find('\b', pos)) < std::string::npos; pos += 2) { output.replace(pos, 1, "\\b"); }
    297     for (unsigned int pos = 0; (pos = output.find('\r', pos)) < std::string::npos; pos += 2) { output.replace(pos, 1, "\\r"); }
    298     for (unsigned int pos = 0; (pos = output.find('\f', pos)) < std::string::npos; pos += 2) { output.replace(pos, 1, "\\f"); }
    299     for (unsigned int pos = 0; (pos = output.find('\a', pos)) < std::string::npos; pos += 2) { output.replace(pos, 1, "\\a"); }
    300     for (unsigned int pos = 0; (pos = output.find('"', pos)) < std::string::npos; pos += 2) { output.replace(pos, 1, "\\\""); }
    301     for (unsigned int pos = 0; (pos = output.find('\0', pos)) < std::string::npos; pos += 2) { output.replace(pos, 1, "\\0"); }
     292    for (size_t pos = 0; (pos = output.find('\\', pos)) < std::string::npos; pos += 2) { output.replace(pos, 1, "\\\\"); }
     293    for (size_t pos = 0; (pos = output.find('\n', pos)) < std::string::npos; pos += 2) { output.replace(pos, 1, "\\n"); }
     294    for (size_t pos = 0; (pos = output.find('\t', pos)) < std::string::npos; pos += 2) { output.replace(pos, 1, "\\t"); }
     295    for (size_t pos = 0; (pos = output.find('\v', pos)) < std::string::npos; pos += 2) { output.replace(pos, 1, "\\v"); }
     296    for (size_t pos = 0; (pos = output.find('\b', pos)) < std::string::npos; pos += 2) { output.replace(pos, 1, "\\b"); }
     297    for (size_t pos = 0; (pos = output.find('\r', pos)) < std::string::npos; pos += 2) { output.replace(pos, 1, "\\r"); }
     298    for (size_t pos = 0; (pos = output.find('\f', pos)) < std::string::npos; pos += 2) { output.replace(pos, 1, "\\f"); }
     299    for (size_t pos = 0; (pos = output.find('\a', pos)) < std::string::npos; pos += 2) { output.replace(pos, 1, "\\a"); }
     300    for (size_t pos = 0; (pos = output.find('"', pos)) < std::string::npos; pos += 2) { output.replace(pos, 1, "\\\""); }
     301    for (size_t pos = 0; (pos = output.find('\0', pos)) < std::string::npos; pos += 2) { output.replace(pos, 1, "\\0"); }
    302302
    303303    return output;
     
    315315
    316316    std::string output = "";
    317     for (unsigned int pos = 0; pos < str.size() - 1; )
     317    for (size_t pos = 0; pos < str.size() - 1; )
    318318    {
    319319        if (str[pos] == '\\')
     
    345345void lowercase(std::string* str)
    346346{
    347     for (unsigned int i = 0; i < str->size(); ++i)
     347    for (size_t i = 0; i < str->size(); ++i)
    348348    {
    349349        (*str)[i] = (char)tolower((*str)[i]);
     
    369369void uppercase(std::string* str)
    370370{
    371     for (unsigned int i = 0; i < str->size(); ++i)
     371    for (size_t i = 0; i < str->size(); ++i)
    372372    {
    373373        (*str)[i] = (char)toupper((*str)[i]);
     
    421421    @param len Maximal number of chars to compare
    422422*/
    423 int nocaseCmp(const std::string& s1, const std::string& s2, unsigned int len)
     423int nocaseCmp(const std::string& s1, const std::string& s2, size_t len)
    424424{
    425425    if (len == 0)
     
    466466    @return The position
    467467*/
    468 unsigned int getCommentPosition(const std::string& str)
     468size_t getCommentPosition(const std::string& str)
    469469{
    470470    return getNextCommentPosition(str, 0);
     
    477477    @return The position
    478478*/
    479 unsigned int getNextCommentPosition(const std::string& str, unsigned int start)
    480 {
    481     for (unsigned int i = start; i < str.size(); i++)
     479size_t getNextCommentPosition(const std::string& str, size_t start)
     480{
     481    for (size_t i = start; i < str.size(); i++)
    482482        if (isComment(str.substr(i)))
    483483            return i;
Note: See TracChangeset for help on using the changeset viewer.