1.1 --- a/include/am-string.h Thu Aug 29 23:51:30 2013 -0700
1.2 +++ b/include/am-string.h Sat Aug 31 19:52:41 2013 -0700
1.3 @@ -45,6 +45,7 @@
1.4 : length_(0)
1.5 {
1.6 }
1.7 +
1.8 explicit AString(const char *str) {
1.9 set(str, strlen(str));
1.10 }
1.11 @@ -80,6 +81,12 @@
1.12 }
1.13 return *this;
1.14 }
1.15 + AString &operator =(Moveable<AString> other) {
1.16 + chars_ = other->chars_.take();
1.17 + length_ = other->length_;
1.18 + other->length_ = 0;
1.19 + return *this;
1.20 + }
1.21
1.22 int compare(const char *str) const {
1.23 return strcmp(chars(), str);
1.24 @@ -97,17 +104,29 @@
1.25 return chars()[index];
1.26 }
1.27
1.28 + void setVoid() {
1.29 + chars_ = NULL;
1.30 + length_ = kInvalidLength;
1.31 + }
1.32 +
1.33 + bool isVoid() const {
1.34 + return length_ == kInvalidLength;
1.35 + }
1.36 +
1.37 size_t length() const {
1.38 + assert(!isVoid());
1.39 return length_;
1.40 }
1.41
1.42 const char *chars() const {
1.43 if (!chars_)
1.44 - return "";
1.45 + return isVoid() ? NULL : "";
1.46 return chars_;
1.47 }
1.48
1.49 private:
1.50 + static const size_t kInvalidLength = (size_t)-1;
1.51 +
1.52 void set(const char *str, size_t length) {
1.53 chars_ = new char[length + 1];
1.54 length_ = length;