------------------------------------------------------------------------------------------------
| 151 | |
| 152 | // ------------------------------------------------------------------------------------------------ |
| 153 | unsigned int ReadString(const char*& sbegin_out, const char*& send_out, const char* input, |
| 154 | const char*& cursor, const char* end, bool long_length = false, bool allow_null = false) { |
| 155 | const uint32_t len_len = long_length ? 4 : 1; |
| 156 | if(Offset(cursor, end) < len_len) { |
| 157 | TokenizeError("cannot ReadString, out of bounds reading length",input, cursor); |
| 158 | } |
| 159 | |
| 160 | const uint32_t length = long_length ? ReadWord(input, cursor, end) : ReadByte(input, cursor, end); |
| 161 | |
| 162 | if (Offset(cursor, end) < length) { |
| 163 | TokenizeError("cannot ReadString, length is out of bounds",input, cursor); |
| 164 | } |
| 165 | |
| 166 | sbegin_out = cursor; |
| 167 | cursor += length; |
| 168 | |
| 169 | send_out = cursor; |
| 170 | |
| 171 | if(!allow_null) { |
| 172 | for (unsigned int i = 0; i < length; ++i) { |
| 173 | if(sbegin_out[i] == '\0') { |
| 174 | TokenizeError("failed ReadString, unexpected NUL character in string",input, cursor); |
| 175 | } |
| 176 | } |
| 177 | } |
| 178 | |
| 179 | return length; |
| 180 | } |
| 181 | |
| 182 | // ------------------------------------------------------------------------------------------------ |
| 183 | void ReadData(const char*& sbegin_out, const char*& send_out, const char* input, const char*& cursor, const char* end) { |