Ignore:
Timestamp:
Jan 21, 2013, 2:11:48 PM (10 years ago)
Author:
sam
Message:

string: implement String::Last() and a constructor for fixed-length strings.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/lol/base/string.h

    r2235 r2240  
    3838      : Super()
    3939    {
    40         do
    41         {
    42             Push(*str);
    43         }
    44         while (*str++);
     40        Resize((int)strlen(str));
     41        memcpy(&(*this)[0], str, Count() + 1);
     42    }
     43
     44    inline String(char const *str, int count)
     45      : Super()
     46    {
     47        Resize(count + 1);
     48        memcpy(&(*this)[0], str, Count());
     49        ((Super &)*this).Last() = '\0';
    4550    }
    4651
     
    5863    {
    5964        return ((Super const &)*this)[n];
     65    }
     66
     67    inline char &Last()
     68    {
     69        return (*this)[Count() - 1];
     70    }
     71
     72    inline char const &Last() const
     73    {
     74        return (*this)[Count() - 1];
    6075    }
    6176
Note: See TracChangeset for help on using the changeset viewer.