* @brief Appends char to the token value * * @param Token * @param c the character to append * @return void */
| 240 | * @return void |
| 241 | */ |
| 242 | void |
| 243 | AppendByte(PSCRIPT_ENGINE_TOKEN Token, char c) |
| 244 | { |
| 245 | // |
| 246 | // Check overflow of the string |
| 247 | // |
| 248 | if (Token->Len >= Token->MaxLen - 1) |
| 249 | { |
| 250 | // |
| 251 | // Double the length of the allocated space for the string |
| 252 | // |
| 253 | Token->MaxLen *= 2; |
| 254 | char * NewValue = (char *)calloc(Token->MaxLen + 1, sizeof(char)); |
| 255 | |
| 256 | if (NewValue == NULL) |
| 257 | { |
| 258 | printf("err, could not allocate buffer"); |
| 259 | return; |
| 260 | } |
| 261 | |
| 262 | // |
| 263 | // Free Old buffer and update the pointer |
| 264 | // |
| 265 | memcpy(NewValue, Token->Value, Token->Len); |
| 266 | free(Token->Value); |
| 267 | Token->Value = NewValue; |
| 268 | } |
| 269 | |
| 270 | // |
| 271 | // Append the new character to the string |
| 272 | // |
| 273 | Token->Value[Token->Len] = c; |
| 274 | Token->Len++; |
| 275 | } |
| 276 | |
| 277 | /** |
| 278 | * @brief Appends wchar_t to the token value |