Trims whitespaces from both the ends of the input utf8 sequence
| 361 | |
| 362 | // Trims whitespaces from both the ends of the input utf8 sequence |
| 363 | FORCE_INLINE |
| 364 | const char* btrim_utf8(gdv_int64 context, const char* data, gdv_int32 data_len, |
| 365 | int32_t* out_len) { |
| 366 | if (data_len == 0) { |
| 367 | *out_len = 0; |
| 368 | return ""; |
| 369 | } |
| 370 | |
| 371 | gdv_int32 start = 0, end = data_len - 1; |
| 372 | // start and end denote the first and last positions of non-space |
| 373 | // characters in the input string respectively |
| 374 | while (start <= end && data[start] == ' ') { |
| 375 | ++start; |
| 376 | } |
| 377 | while (end >= start && data[end] == ' ') { |
| 378 | --end; |
| 379 | } |
| 380 | |
| 381 | // string has some leading/trailing spaces and some non-space characters |
| 382 | *out_len = end - start + 1; |
| 383 | return data + start; |
| 384 | } |
| 385 | |
| 386 | // Trims characters present in the trim text from the left end of the base text |
| 387 | FORCE_INLINE |