diff --git a/internal/cgen/base/strconv-public.h b/internal/cgen/base/strconv-public.h index b1f80780..ce47874c 100644 --- a/internal/cgen/base/strconv-public.h +++ b/internal/cgen/base/strconv-public.h @@ -40,13 +40,14 @@ wuffs_base__parse_number_i64(wuffs_base__slice_u8 s); // parse: it returns an error unless all of s is consumed. // - It does not allow whitespace, leading or otherwise. // - It does not allow a leading '+' or '-'. -// - It does not allow multiple leading zeroes: "0" is valid but "00" is not. +// - It does not allow unnecessary leading zeroes ("0" is valid and its sole +// zero is necessary). All of "00", "0644" and "007" are invalid. // - It does not take a base argument (e.g. base 10 vs base 16). Instead, it // always accepts both decimal (e.g "1234", "0d5678") and hexadecimal (e.g. // "0x9aBC"). The caller is responsible for prior filtering of e.g. hex // numbers if they are unwanted. For example, Wuffs' JSON decoder will only // produce a wuffs_base__token for decimal numbers, not hexadecimal. -// - It is not affected by i18n / l10n settings. +// - It is not affected by i18n / l10n settings such as environment variables. // - It does allow arbitrary underscores, except inside the optional 2-byte // opening "0d" or "0X" that denotes base-10 or base-16. For example, // "__0D_1_002" would successfully parse as "one thousand and two". diff --git a/internal/cgen/data.go b/internal/cgen/data.go index ed2eb66a..956a5df5 100644 --- a/internal/cgen/data.go +++ b/internal/cgen/data.go @@ -288,8 +288,8 @@ const baseStrConvPrivateH = "" + const baseStrConvPublicH = "" + "// ---------------- String Conversions\n\n// wuffs_base__parse_number_i64 parses the ASCII integer in s. For example, if\n// s contains the bytes \"-123\" then it will return the int64_t -123.\n//\n// It returns an error if s does not contain an integer or if the integer\n// within would overflow an int64_t.\n//\n// It is similar to wuffs_base__parse_number_u64 but it returns a signed\n// integer, not an unsigned integer. It also allows a leading '+' or '-'.\nwuffs_base__result_i64 //\nwuffs_base__parse_number_i64(wuffs_base__slice_u8 s);\n\n// wuffs_base__parse_number_u64 parses the ASCII integer in s. For example, if\n// s contains the bytes \"123\" then it will return the uint64_t 123.\n//\n// It returns an error if s does not contain an integer or if the integer\n// within would overflow a uint64_t.\n//\n// It is similar to the C standard library's strtoull function, but:\n// - Errors are returned in-band (in a result type), not out-of-band (errno).\n// - It takes a slice (a pointer and length), not a NUL-terminated C string.\n" + - "// - It does not take an optional endptr argument. It does not allow a partial\n// parse: it returns an error unless all of s is consumed.\n// - It does not allow whitespace, leading or otherwise.\n// - It does not allow a leading '+' or '-'.\n// - It does not allow multiple leading zeroes: \"0\" is valid but \"00\" is not.\n// - It does not take a base argument (e.g. base 10 vs base 16). Instead, it\n// always accepts both decimal (e.g \"1234\", \"0d5678\") and hexadecimal (e.g.\n// \"0x9aBC\"). The caller is responsible for prior filtering of e.g. hex\n// numbers if they are unwanted. For example, Wuffs' JSON decoder will only\n// produce a wuffs_base__token for decimal numbers, not hexadecimal.\n// - It is not affected by i18n / l10n settings.\n// - It does allow arbitrary underscores, except inside the optional 2-byte\n// opening \"0d\" or \"0X\" that denotes base-10 or base-16. For example,\n// \"__0D_1_002\" would successfully parse as \"one thousand and two\".\nwuffs_base__result_u64 //\nwuffs_base__parse_" + - "number_u64(wuffs_base__slice_u8 s);\n\n" + + "// - It does not take an optional endptr argument. It does not allow a partial\n// parse: it returns an error unless all of s is consumed.\n// - It does not allow whitespace, leading or otherwise.\n// - It does not allow a leading '+' or '-'.\n// - It does not allow unnecessary leading zeroes (\"0\" is valid and its sole\n// zero is necessary). All of \"00\", \"0644\" and \"007\" are invalid.\n// - It does not take a base argument (e.g. base 10 vs base 16). Instead, it\n// always accepts both decimal (e.g \"1234\", \"0d5678\") and hexadecimal (e.g.\n// \"0x9aBC\"). The caller is responsible for prior filtering of e.g. hex\n// numbers if they are unwanted. For example, Wuffs' JSON decoder will only\n// produce a wuffs_base__token for decimal numbers, not hexadecimal.\n// - It is not affected by i18n / l10n settings such as environment variables.\n// - It does allow arbitrary underscores, except inside the optional 2-byte\n// opening \"0d\" or \"0X\" that denotes base-10 or base-16. For example,\n// \"__0D_1_002\"" + + " would successfully parse as \"one thousand and two\".\nwuffs_base__result_u64 //\nwuffs_base__parse_number_u64(wuffs_base__slice_u8 s);\n\n" + "" + "// ---------------- Unicode and UTF-8\n\n#define WUFFS_BASE__UNICODE_CODE_POINT__MIN_INCL 0x00000000\n#define WUFFS_BASE__UNICODE_CODE_POINT__MAX_INCL 0x0010FFFF\n\n#define WUFFS_BASE__UNICODE_REPLACEMENT_CHARACTER 0x0000FFFD\n\n#define WUFFS_BASE__UNICODE_SURROGATE__MIN_INCL 0x0000D800\n#define WUFFS_BASE__UNICODE_SURROGATE__MAX_INCL 0x0000DFFF\n\n#define WUFFS_BASE__ASCII__MIN_INCL 0x00\n#define WUFFS_BASE__ASCII__MAX_INCL 0x7F\n\n#define WUFFS_BASE__UTF_8__BYTE_LENGTH__MIN_INCL 1\n#define WUFFS_BASE__UTF_8__BYTE_LENGTH__MAX_INCL 4\n\n#define WUFFS_BASE__UTF_8__BYTE_LENGTH_1__CODE_POINT__MIN_INCL 0x00000000\n#define WUFFS_BASE__UTF_8__BYTE_LENGTH_1__CODE_POINT__MAX_INCL 0x0000007F\n#define WUFFS_BASE__UTF_8__BYTE_LENGTH_2__CODE_POINT__MIN_INCL 0x00000080\n#define WUFFS_BASE__UTF_8__BYTE_LENGTH_2__CODE_POINT__MAX_INCL 0x000007FF\n#define WUFFS_BASE__UTF_8__BYTE_LENGTH_3__CODE_POINT__MIN_INCL 0x00000800\n#define WUFFS_BASE__UTF_8__BYTE_LENGTH_3__CODE_POINT__MAX_INCL 0x0000FFFF\n#define WUFFS_BASE__UTF_8__BYTE_LENGTH_4__CODE_POINT_" + "_MIN_INCL 0x00010000\n#define WUFFS_BASE__UTF_8__BYTE_LENGTH_4__CODE_POINT__MAX_INCL 0x0010FFFF\n\n" + diff --git a/release/c/wuffs-unsupported-snapshot.c b/release/c/wuffs-unsupported-snapshot.c index 597b1098..f6196038 100644 --- a/release/c/wuffs-unsupported-snapshot.c +++ b/release/c/wuffs-unsupported-snapshot.c @@ -3419,13 +3419,14 @@ wuffs_base__parse_number_i64(wuffs_base__slice_u8 s); // parse: it returns an error unless all of s is consumed. // - It does not allow whitespace, leading or otherwise. // - It does not allow a leading '+' or '-'. -// - It does not allow multiple leading zeroes: "0" is valid but "00" is not. +// - It does not allow unnecessary leading zeroes ("0" is valid and its sole +// zero is necessary). All of "00", "0644" and "007" are invalid. // - It does not take a base argument (e.g. base 10 vs base 16). Instead, it // always accepts both decimal (e.g "1234", "0d5678") and hexadecimal (e.g. // "0x9aBC"). The caller is responsible for prior filtering of e.g. hex // numbers if they are unwanted. For example, Wuffs' JSON decoder will only // produce a wuffs_base__token for decimal numbers, not hexadecimal. -// - It is not affected by i18n / l10n settings. +// - It is not affected by i18n / l10n settings such as environment variables. // - It does allow arbitrary underscores, except inside the optional 2-byte // opening "0d" or "0X" that denotes base-10 or base-16. For example, // "__0D_1_002" would successfully parse as "one thousand and two". diff --git a/test/c/std/json.c b/test/c/std/json.c index 15795297..b89525c7 100644 --- a/test/c/std/json.c +++ b/test/c/std/json.c @@ -161,6 +161,12 @@ test_strconv_parse_number_u64() { {.want = fail, .str = "-0"}, {.want = fail, .str = "-1"}, {.want = fail, .str = "0 "}, + {.want = fail, .str = "00"}, + {.want = fail, .str = "000000x"}, + {.want = fail, .str = "000000x0"}, + {.want = fail, .str = "007"}, + {.want = fail, .str = "0644"}, + {.want = fail, .str = "0_0"}, {.want = fail, .str = "0_x1"}, {.want = fail, .str = "0d___"}, {.want = fail, .str = "0x"},