diff --git a/fio-stl.h b/fio-stl.h index bcc693b..5601eb5 100644 --- a/fio-stl.h +++ b/fio-stl.h @@ -17078,12 +17078,18 @@ SFUNC int fio_string_write_url_enc(fio_str_info_s *dest, const void *raw, size_t raw_len); -/** Writes decoded URL data to String. */ +/** Writes decoded URL data to String, decoding + to spaces. */ SFUNC int fio_string_write_url_dec(fio_str_info_s *dest, fio_string_realloc_fn reallocate, const void *encoded, size_t encoded_len); +/** Writes decoded URL data to String, without decoding + to spaces. */ +SFUNC int fio_string_write_path_dec(fio_str_info_s *dest, + fio_string_realloc_fn reallocate, + const void *encoded, + size_t encoded_len); + /* ***************************************************************************** String HTML escaping support ***************************************************************************** */ @@ -19050,10 +19056,12 @@ SFUNC int fio_string_write_url_enc(fio_str_info_s *dest, } /** Writes decoded URL data to String. */ -SFUNC int fio_string_write_url_dec(fio_str_info_s *dest, - fio_string_realloc_fn reallocate, - const void *encoded, - size_t encoded_len) { +FIO_IFUNC int fio_string_write_url_dec_internal( + fio_str_info_s *dest, + fio_string_realloc_fn reallocate, + const void *encoded, + size_t encoded_len, + _Bool plus_is_included) { int r = 0; if (!dest || !encoded || !encoded_len) return r; @@ -19089,13 +19097,15 @@ SFUNC int fio_string_write_url_dec(fio_str_info_s *dest, if (slice_len) { FIO_MEMCPY(dest->buf + dest->len, last, slice_len); /* test for '+' in the slice that has no % characters */ - uint8_t *start_plus = (uint8_t *)dest->buf + dest->len; - uint8_t *end_plus = start_plus + slice_len; - while ( - start_plus && start_plus < end_plus && - (start_plus = - (uint8_t *)FIO_MEMCHR(start_plus, '+', end_plus - start_plus))) - *(start_plus++) = ' '; + if (plus_is_included) { + uint8_t *start_plus = (uint8_t *)dest->buf + dest->len; + uint8_t *end_plus = start_plus + slice_len; + while ( + start_plus && start_plus < end_plus && + (start_plus = + (uint8_t *)FIO_MEMCHR(start_plus, '+', end_plus - start_plus))) + *(start_plus++) = ' '; + } } dest->len += slice_len; last = pr + 1; @@ -19131,18 +19141,45 @@ SFUNC int fio_string_write_url_dec(fio_str_info_s *dest, const size_t slice_len = end - last; FIO_MEMCPY(dest->buf + dest->len, last, slice_len); /* test for '+' in the slice that has no % characters */ - uint8_t *start_plus = (uint8_t *)dest->buf + dest->len; - uint8_t *end_plus = start_plus + slice_len; - while (start_plus && start_plus < end_plus && - (start_plus = - (uint8_t *)FIO_MEMCHR(start_plus, '+', end_plus - start_plus))) - *(start_plus++) = ' '; + if (plus_is_included) { + uint8_t *start_plus = (uint8_t *)dest->buf + dest->len; + uint8_t *end_plus = start_plus + slice_len; + while ( + start_plus && start_plus < end_plus && + (start_plus = + (uint8_t *)FIO_MEMCHR(start_plus, '+', end_plus - start_plus))) + *(start_plus++) = ' '; + } dest->len += slice_len; } dest->buf[dest->len] = 0; return r; } +/** Writes decoded URL data to String. */ +SFUNC int fio_string_write_url_dec(fio_str_info_s *dest, + fio_string_realloc_fn reallocate, + const void *encoded, + size_t encoded_len) { + return fio_string_write_url_dec_internal(dest, + reallocate, + encoded, + encoded_len, + 1); +} + +/** Writes decoded URL data to String. */ +SFUNC int fio_string_write_path_dec(fio_str_info_s *dest, + fio_string_realloc_fn reallocate, + const void *encoded, + size_t encoded_len) { + return fio_string_write_url_dec_internal(dest, + reallocate, + encoded, + encoded_len, + 0); +} + /* ***************************************************************************** String HTML escaping support ***************************************************************************** */ diff --git a/fio-stl.md b/fio-stl.md index 5b9659f..6ee9485 100644 --- a/fio-stl.md +++ b/fio-stl.md @@ -5766,6 +5766,19 @@ Writes decoded URL data to String. Decodes "percent encoding" as well as spaces **Note**: the decoding function reads the non-standard `"%uXXXX"` as UTF-8 encoded data. +#### `fio_string_write_path_dec` + +```c +int fio_string_write_url_dec(fio_str_info_s *dest, + fio_string_realloc_fn reallocate, + const void *encoded, + size_t len); +``` + +Writes decoded URL data to String. Decodes "percent encoding" without converting `+` to spaces. + +**Note**: the decoding function reads the non-standard `"%uXXXX"` as UTF-8 encoded data. + ### Core String HTML escaping support #### `fio_string_write_html_escape` diff --git a/fio-stl/102 string core.h b/fio-stl/102 string core.h index 114da02..eba28fb 100644 --- a/fio-stl/102 string core.h +++ b/fio-stl/102 string core.h @@ -270,12 +270,18 @@ SFUNC int fio_string_write_url_enc(fio_str_info_s *dest, const void *raw, size_t raw_len); -/** Writes decoded URL data to String. */ +/** Writes decoded URL data to String, decoding + to spaces. */ SFUNC int fio_string_write_url_dec(fio_str_info_s *dest, fio_string_realloc_fn reallocate, const void *encoded, size_t encoded_len); +/** Writes decoded URL data to String, without decoding + to spaces. */ +SFUNC int fio_string_write_path_dec(fio_str_info_s *dest, + fio_string_realloc_fn reallocate, + const void *encoded, + size_t encoded_len); + /* ***************************************************************************** String HTML escaping support ***************************************************************************** */ @@ -2242,10 +2248,12 @@ SFUNC int fio_string_write_url_enc(fio_str_info_s *dest, } /** Writes decoded URL data to String. */ -SFUNC int fio_string_write_url_dec(fio_str_info_s *dest, - fio_string_realloc_fn reallocate, - const void *encoded, - size_t encoded_len) { +FIO_IFUNC int fio_string_write_url_dec_internal( + fio_str_info_s *dest, + fio_string_realloc_fn reallocate, + const void *encoded, + size_t encoded_len, + _Bool plus_is_included) { int r = 0; if (!dest || !encoded || !encoded_len) return r; @@ -2281,13 +2289,15 @@ SFUNC int fio_string_write_url_dec(fio_str_info_s *dest, if (slice_len) { FIO_MEMCPY(dest->buf + dest->len, last, slice_len); /* test for '+' in the slice that has no % characters */ - uint8_t *start_plus = (uint8_t *)dest->buf + dest->len; - uint8_t *end_plus = start_plus + slice_len; - while ( - start_plus && start_plus < end_plus && - (start_plus = - (uint8_t *)FIO_MEMCHR(start_plus, '+', end_plus - start_plus))) - *(start_plus++) = ' '; + if (plus_is_included) { + uint8_t *start_plus = (uint8_t *)dest->buf + dest->len; + uint8_t *end_plus = start_plus + slice_len; + while ( + start_plus && start_plus < end_plus && + (start_plus = + (uint8_t *)FIO_MEMCHR(start_plus, '+', end_plus - start_plus))) + *(start_plus++) = ' '; + } } dest->len += slice_len; last = pr + 1; @@ -2323,18 +2333,45 @@ SFUNC int fio_string_write_url_dec(fio_str_info_s *dest, const size_t slice_len = end - last; FIO_MEMCPY(dest->buf + dest->len, last, slice_len); /* test for '+' in the slice that has no % characters */ - uint8_t *start_plus = (uint8_t *)dest->buf + dest->len; - uint8_t *end_plus = start_plus + slice_len; - while (start_plus && start_plus < end_plus && - (start_plus = - (uint8_t *)FIO_MEMCHR(start_plus, '+', end_plus - start_plus))) - *(start_plus++) = ' '; + if (plus_is_included) { + uint8_t *start_plus = (uint8_t *)dest->buf + dest->len; + uint8_t *end_plus = start_plus + slice_len; + while ( + start_plus && start_plus < end_plus && + (start_plus = + (uint8_t *)FIO_MEMCHR(start_plus, '+', end_plus - start_plus))) + *(start_plus++) = ' '; + } dest->len += slice_len; } dest->buf[dest->len] = 0; return r; } +/** Writes decoded URL data to String. */ +SFUNC int fio_string_write_url_dec(fio_str_info_s *dest, + fio_string_realloc_fn reallocate, + const void *encoded, + size_t encoded_len) { + return fio_string_write_url_dec_internal(dest, + reallocate, + encoded, + encoded_len, + 1); +} + +/** Writes decoded URL data to String. */ +SFUNC int fio_string_write_path_dec(fio_str_info_s *dest, + fio_string_realloc_fn reallocate, + const void *encoded, + size_t encoded_len) { + return fio_string_write_url_dec_internal(dest, + reallocate, + encoded, + encoded_len, + 0); +} + /* ***************************************************************************** String HTML escaping support ***************************************************************************** */ diff --git a/fio-stl/102 string core.md b/fio-stl/102 string core.md index 36e2828..6f850a1 100644 --- a/fio-stl/102 string core.md +++ b/fio-stl/102 string core.md @@ -460,6 +460,19 @@ Writes decoded URL data to String. Decodes "percent encoding" as well as spaces **Note**: the decoding function reads the non-standard `"%uXXXX"` as UTF-8 encoded data. +#### `fio_string_write_path_dec` + +```c +int fio_string_write_url_dec(fio_str_info_s *dest, + fio_string_realloc_fn reallocate, + const void *encoded, + size_t len); +``` + +Writes decoded URL data to String. Decodes "percent encoding" without converting `+` to spaces. + +**Note**: the decoding function reads the non-standard `"%uXXXX"` as UTF-8 encoded data. + ### Core String HTML escaping support #### `fio_string_write_html_escape`