Skip to content

Commit

Permalink
Sync jparse again
Browse files Browse the repository at this point in the history
To better clarify its true purpose, the function count_utf8_bytes() was
renamed to utf8len().
  • Loading branch information
xexyl committed Oct 9, 2024
1 parent a34982a commit a9df905
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 11 deletions.
2 changes: 2 additions & 0 deletions jparse/CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ Added a `JPARSE_UTF8_VERSION` in order to keep track of the current UTF-8 code.
Set this version to the same as the other versions at this time: `1.2.0
2024-10-09`.

Rename `count_utf8_bytes` to `utf8len()` to better account for what it does.


## Release 1.0.23 2024-10-08

Expand Down
10 changes: 5 additions & 5 deletions jparse/json_parse.c
Original file line number Diff line number Diff line change
Expand Up @@ -1134,7 +1134,7 @@ json_decode(char const *ptr, size_t len, size_t *retlen)
int32_t surrogate = 0; /* for surrogate pairs */
int scanned = 0; /* for sscanf() */
size_t i;
size_t bytes = 0; /* for count_utf8_bytes() */
size_t bytes = 0; /* for utf8len() */

/*
* firewall
Expand Down Expand Up @@ -1268,11 +1268,11 @@ json_decode(char const *ptr, size_t len, size_t *retlen)
} else if (scanned == 1 || (scanned == 2 && surrogates_to_unicode(xa, xb) < 0)) {
surrogate = xa;
bytes = 0; /* reset bytes */
if (!count_utf8_bytes(ptr + i, surrogate, &bytes)) {
if (!utf8len(ptr + i, surrogate, &bytes)) {
if (retlen != NULL) {
*retlen = 0;
}
/* count_utf8_bytes() already warns */
/* utf8len() already warns */
return NULL;
}
dbg(DBG_VVHIGH, "UTF-8 bytes: %ju", (uintmax_t)bytes);
Expand All @@ -1298,11 +1298,11 @@ json_decode(char const *ptr, size_t len, size_t *retlen)
* try counting the bytes needed.
*/
bytes = 0; /* reset bytes */
if (!count_utf8_bytes(NULL, surrogate, &bytes)) {
if (!utf8len(NULL, surrogate, &bytes)) {
if (retlen != NULL) {
*retlen = 0;
}
/* count_utf8_bytes() already warns */
/* utf8len() already warns */
return NULL;
}
dbg(DBG_VVHIGH, "UTF-8 bytes: %ju", (uintmax_t)bytes);
Expand Down
6 changes: 3 additions & 3 deletions jparse/json_utf8.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
* NOTE: *str should point to the \u!
*/
bool
count_utf8_bytes(const char *str, int32_t surrogate, size_t *bytes)
utf8len(const char *str, int32_t surrogate, size_t *bytes)
{
unsigned char xa = 0; /* first hex digit */
unsigned char xb = 0; /* second hex digit */
Expand Down Expand Up @@ -283,7 +283,7 @@ utf8encode(char *str, unsigned int val)
*/

/*
* -=-=-=---=-=-=-=-=-=-=-=-=-=-=-=---=-=-=-=-=-=-=-=-=-=-=-=---=-=-=-=-=-=-=-=-=
* -=-=-=---=-=-=-=-=-=-=-=-=-=-=-=---=-=-=-=-=-=-=-=-=-=-=-=---=-=-=-=-=-=-=-=-=
*/

/*
Expand Down Expand Up @@ -325,5 +325,5 @@ surrogates_to_unicode (int32_t hi, int32_t lo)
*/

/*
* -=-=-=---=-=-=-=-=-=-=-=-=-=-=-=---=-=-=-=-=-=-=-=-=-=-=-=---=-=-=-=-=-=-=-=-=
* -=-=-=---=-=-=-=-=-=-=-=-=-=-=-=---=-=-=-=-=-=-=-=-=-=-=-=---=-=-=-=-=-=-=-=-=
*/
6 changes: 3 additions & 3 deletions jparse/json_utf8.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
#define JPARSE_UTF8_VERSION "1.2.0 2024-10-09" /* format: major.minor YYYY-MM-DD */


extern bool count_utf8_bytes(const char *str, int32_t surrogate, size_t *bytes);
extern bool utf8len(const char *str, int32_t surrogate, size_t *bytes);

/*
* The below function and macros are based on code from
Expand Down Expand Up @@ -67,7 +67,7 @@ extern int utf8encode(char *str, unsigned int val);
*/

/*
* -=-=-=---=-=-=-=-=-=-=-=-=-=-=-=---=-=-=-=-=-=-=-=-=-=-=-=---=-=-=-=-=-=-=-=-=
* -=-=-=---=-=-=-=-=-=-=-=-=-=-=-=---=-=-=-=-=-=-=-=-=-=-=-=---=-=-=-=-=-=-=-=-=
*/

/*
Expand Down Expand Up @@ -130,7 +130,7 @@ extern int32_t surrogates_to_unicode (int32_t hi, int32_t lo);
*/

/*
* -=-=-=---=-=-=-=-=-=-=-=-=-=-=-=---=-=-=-=-=-=-=-=-=-=-=-=---=-=-=-=-=-=-=-=-=
* -=-=-=---=-=-=-=-=-=-=-=-=-=-=-=---=-=-=-=-=-=-=-=-=-=-=-=---=-=-=-=-=-=-=-=-=
*/

#endif /* INCLUDE_JSON_UTF8_H */

0 comments on commit a9df905

Please sign in to comment.