Ignore:
Timestamp:
07/03/20 00:37:13 (4 years ago)
Author:
Maciej Komosinski
Message:

Increased SString and std::string compatibility: introduced length(), size(), and capacity(), and removed legacy methods that have std::string equivalents

File:
1 edited

Legend:

Unmodified
Added
Removed
  • cpp/frams/util/sstring.cpp

    r970 r973  
    163163}
    164164
    165 void SString::memoryHint(int howbig)
    166 {
    167         detachCopy(howbig);
    168 }
    169 
    170165void SString::detachEmpty(int ensuresize)
    171166{
     
    201196char *SString::directWrite(int ensuresize)
    202197{
    203         if (ensuresize < 0) ensuresize = len();
     198        if (ensuresize < 0) ensuresize = length();
    204199        REF_LOCK;
    205200        detachCopy(ensuresize);
     
    259254void SString::operator+=(const SString&s)
    260255{
    261         append(s.c_str(), s.len());
     256        append(s.c_str(), s.length());
    262257}
    263258
     
    298293///////////////////////////////////////
    299294
    300 SString SString::substr(int begin, int length) const
    301 {
    302         if (begin < 0) { length += begin; begin = 0; }
    303         if (length >= (len() - begin)) length = len() - begin;
    304         if (length <= 0) return SString();
    305         if (length == len()) return *this;
    306         return SString((*this)(begin), length);
     295SString SString::substr(int begin, int numchars) const
     296{
     297        if (begin < 0) { numchars += begin; begin = 0; }
     298        if (numchars >= (length() - begin)) numchars = length() - begin;
     299        if (numchars <= 0) return SString();
     300        if (numchars == length()) return *this;
     301        return SString((*this)(begin), numchars);
    307302}
    308303
     
    337332bool SString::getNextToken(int& pos, SString &token, char separator) const
    338333{
    339         if (pos >= len()) { token = 0; return false; }
     334        if (pos >= length()) { token = 0; return false; }
    340335        int p1 = pos, p2;
    341336        const char *t1 = buf->txt + pos;
    342337        const char *t2 = strchr(t1, separator);
    343         if (t2) pos = (p2 = (t2 - buf->txt)) + 1; else p2 = pos = len();
     338        if (t2) pos = (p2 = (t2 - buf->txt)) + 1; else p2 = pos = length();
    344339        strncpy(token.directWrite(p2 - p1), t1, p2 - p1);
    345340        token.endWrite(p2 - p1);
     
    401396                char* p = ret.directWrite(size);
    402397                assert(p != NULL);
    403                 size = ret.directMaxLen() + 1;
     398                size = ret.capacity() + 1;
    404399                /* Try to print in the allocated space. */
    405400                va_start(ap, format);
Note: See TracChangeset for help on using the changeset viewer.