| 40 | namespace Firebird { |
| 41 | |
| 42 | class MetaString |
| 43 | { |
| 44 | private: |
| 45 | char data[MAX_SQL_IDENTIFIER_SIZE]; |
| 46 | unsigned int count; |
| 47 | |
| 48 | void init() |
| 49 | { |
| 50 | memset(data, 0, MAX_SQL_IDENTIFIER_SIZE); |
| 51 | } |
| 52 | MetaString& set(const MetaString& m) |
| 53 | { |
| 54 | memcpy(data, m.data, MAX_SQL_IDENTIFIER_SIZE); |
| 55 | count = m.count; |
| 56 | return *this; |
| 57 | } |
| 58 | |
| 59 | public: |
| 60 | MetaString() { init(); count = 0; } |
| 61 | MetaString(const char* s) { assign(s); } |
| 62 | MetaString(const char* s, FB_SIZE_T l) { assign(s, l); } |
| 63 | MetaString(const MetaString& m) { set(m); } |
| 64 | MetaString(const AbstractString& s) { assign(s.c_str(), s.length()); } |
| 65 | explicit MetaString(MemoryPool&) { init(); count = 0; } |
| 66 | MetaString(MemoryPool&, const char* s) { assign(s); } |
| 67 | MetaString(MemoryPool&, const char* s, FB_SIZE_T l) { assign(s, l); } |
| 68 | MetaString(MemoryPool&, const MetaString& m) { set(m); } |
| 69 | MetaString(MemoryPool&, const AbstractString& s) { assign(s.c_str(), s.length()); } |
| 70 | |
| 71 | MetaString& assign(const char* s, FB_SIZE_T l); |
| 72 | MetaString& assign(const char* s) { return assign(s, s ? fb_strlen(s) : 0); } |
| 73 | MetaString& operator=(const char* s) { return assign(s); } |
| 74 | MetaString& operator=(const AbstractString& s) { return assign(s.c_str(), s.length()); } |
| 75 | MetaString& operator=(const MetaString& m) { return set(m); } |
| 76 | char* getBuffer(const FB_SIZE_T l); |
| 77 | |
| 78 | FB_SIZE_T length() const { return count; } |
| 79 | const char* c_str() const { return data; } |
| 80 | const char* nullStr() const { return (count == 0 ? NULL : data); } |
| 81 | bool isEmpty() const { return count == 0; } |
| 82 | bool hasData() const { return count != 0; } |
| 83 | |
| 84 | char& operator[](unsigned n) { return data[n]; } |
| 85 | char operator[](unsigned n) const { return data[n]; } |
| 86 | |
| 87 | const char* begin() const { return data; } |
| 88 | const char* end() const { return data + count; } |
| 89 | |
| 90 | int compare(const char* s, FB_SIZE_T l) const; |
| 91 | int compare(const char* s) const { return compare(s, s ? fb_strlen(s) : 0); } |
| 92 | int compare(const AbstractString& s) const { return compare(s.c_str(), s.length()); } |
| 93 | int compare(const MetaString& m) const { return memcmp(data, m.data, MAX_SQL_IDENTIFIER_SIZE); } |
| 94 | |
| 95 | bool operator==(const char* s) const { return compare(s) == 0; } |
| 96 | bool operator!=(const char* s) const { return compare(s) != 0; } |
| 97 | bool operator==(const AbstractString& s) const { return compare(s) == 0; } |
| 98 | bool operator!=(const AbstractString& s) const { return compare(s) != 0; } |
| 99 | bool operator==(const MetaString& m) const { return compare(m) == 0; } |