Skip to content

Commit

Permalink
plus or no plus
Browse files Browse the repository at this point in the history
  • Loading branch information
boazsegev committed Sep 9, 2023
1 parent 2444289 commit 6c51c06
Show file tree
Hide file tree
Showing 4 changed files with 136 additions and 36 deletions.
73 changes: 55 additions & 18 deletions fio-stl.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
***************************************************************************** */
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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
***************************************************************************** */
Expand Down
13 changes: 13 additions & 0 deletions fio-stl.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
73 changes: 55 additions & 18 deletions fio-stl/102 string core.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
***************************************************************************** */
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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
***************************************************************************** */
Expand Down
13 changes: 13 additions & 0 deletions fio-stl/102 string core.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down

0 comments on commit 6c51c06

Please sign in to comment.