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-simple.h

    r955 r973  
    1414private:
    1515        char *txt;      ///< string buffer or NULL for empty string
    16         int size;       ///< allocated memory (including \0)
     16        int allocated;       ///< allocated memory (including \0)
    1717        int used;       ///< string length
    1818        int appending;  ///< append mode, changes can occur after character # 'appending'
     
    2020        void initEmpty();
    2121        void copyFrom(SString &from); ///< copy from SString
    22         void resize(int newsize);
    23         void ensureSize(int needed);
     22        void reallocate(int newsize);
     23        void ensureAllocated(int needed);
    2424        const char* getPtr() const { return txt ? txt : ""; }
    2525
     
    3434
    3535        void copyFrom(const char* ch, int chlen = -1); ///< copy string, length of -1 == unknown
    36        
    37         void* operator new(size_t s, void* mem){ return mem; }
     36
     37        void* operator new(size_t s, void* mem) { return mem; }
    3838#ifdef _MSC_VER
    39                 void operator delete(void* mem, void* t) {}
     39        void operator delete(void* mem, void* t) {}
    4040#endif
    41         void* operator new(size_t s){ return malloc(sizeof(SString)); }
     41        void* operator new(size_t s) { return malloc(sizeof(SString)); }
    4242        void operator delete(void* mem) { free(mem); }
    4343
    44         int len() const { return used; } ///< get string length
     44        int length() const { return used; } ///< get string length
     45        int size() const { return length(); } ///< get string length
    4546        void shrink(); ///< free unnecessary buffer
    46         void reserve(int needed) { ensureSize(needed); } ///< like in std::string
     47        void reserve(int cap) { ensureAllocated(cap + 1); } ///< like in std::string
    4748
    4849        /// after this call, you can modify sstring directly.
     
    8788        void endAppend(int appendlength = -1);
    8889
    89         void memoryHint(int howbig) { ensureSize(howbig); }
    90         int directMaxLen() { return size - 1; } ///< when called after directWrite: max number of characters allowed (can be more than requested)
     90        int capacity() { return (allocated > 0) ? (allocated - 1) : allocated; } ///< std::string.capacity()
    9191
    9292        /// find a character in SString.
Note: See TracChangeset for help on using the changeset viewer.