diff options
Diffstat (limited to 'prism/util/pm_char.c')
-rw-r--r-- | prism/util/pm_char.c | 144 |
1 files changed, 72 insertions, 72 deletions
diff --git a/prism/util/pm_char.c b/prism/util/pm_char.c index 42c3896626..59a188ae0a 100644 --- a/prism/util/pm_char.c +++ b/prism/util/pm_char.c @@ -1,19 +1,19 @@ -#include "yarp/util/yp_char.h" - -#define YP_CHAR_BIT_WHITESPACE (1 << 0) -#define YP_CHAR_BIT_INLINE_WHITESPACE (1 << 1) -#define YP_CHAR_BIT_REGEXP_OPTION (1 << 2) - -#define YP_NUMBER_BIT_BINARY_DIGIT (1 << 0) -#define YP_NUMBER_BIT_BINARY_NUMBER (1 << 1) -#define YP_NUMBER_BIT_OCTAL_DIGIT (1 << 2) -#define YP_NUMBER_BIT_OCTAL_NUMBER (1 << 3) -#define YP_NUMBER_BIT_DECIMAL_DIGIT (1 << 4) -#define YP_NUMBER_BIT_DECIMAL_NUMBER (1 << 5) -#define YP_NUMBER_BIT_HEXADECIMAL_DIGIT (1 << 6) -#define YP_NUMBER_BIT_HEXADECIMAL_NUMBER (1 << 7) - -static const uint8_t yp_byte_table[256] = { +#include "prism/util/pm_char.h" + +#define PRISM_CHAR_BIT_WHITESPACE (1 << 0) +#define PRISM_CHAR_BIT_INLINE_WHITESPACE (1 << 1) +#define PRISM_CHAR_BIT_REGEXP_OPTION (1 << 2) + +#define PRISM_NUMBER_BIT_BINARY_DIGIT (1 << 0) +#define PRISM_NUMBER_BIT_BINARY_NUMBER (1 << 1) +#define PRISM_NUMBER_BIT_OCTAL_DIGIT (1 << 2) +#define PRISM_NUMBER_BIT_OCTAL_NUMBER (1 << 3) +#define PRISM_NUMBER_BIT_DECIMAL_DIGIT (1 << 4) +#define PRISM_NUMBER_BIT_DECIMAL_NUMBER (1 << 5) +#define PRISM_NUMBER_BIT_HEXADECIMAL_DIGIT (1 << 6) +#define PRISM_NUMBER_BIT_HEXADECIMAL_NUMBER (1 << 7) + +static const uint8_t pm_byte_table[256] = { // 0 1 2 3 4 5 6 7 8 9 A B C D E F 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 1, 3, 3, 3, 0, 0, // 0x 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 1x @@ -33,7 +33,7 @@ static const uint8_t yp_byte_table[256] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // Fx }; -static const uint8_t yp_number_table[256] = { +static const uint8_t pm_number_table[256] = { // 0 1 2 3 4 5 6 7 8 9 A B C D E F 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0x 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 1x @@ -54,36 +54,36 @@ static const uint8_t yp_number_table[256] = { }; static inline size_t -yp_strspn_char_kind(const uint8_t *string, ptrdiff_t length, uint8_t kind) { +pm_strspn_char_kind(const uint8_t *string, ptrdiff_t length, uint8_t kind) { if (length <= 0) return 0; size_t size = 0; size_t maximum = (size_t) length; - while (size < maximum && (yp_byte_table[string[size]] & kind)) size++; + while (size < maximum && (pm_byte_table[string[size]] & kind)) size++; return size; } // Returns the number of characters at the start of the string that are // whitespace. Disallows searching past the given maximum number of characters. size_t -yp_strspn_whitespace(const uint8_t *string, ptrdiff_t length) { - return yp_strspn_char_kind(string, length, YP_CHAR_BIT_WHITESPACE); +pm_strspn_whitespace(const uint8_t *string, ptrdiff_t length) { + return pm_strspn_char_kind(string, length, PRISM_CHAR_BIT_WHITESPACE); } // Returns the number of characters at the start of the string that are // whitespace while also tracking the location of each newline. Disallows // searching past the given maximum number of characters. size_t -yp_strspn_whitespace_newlines(const uint8_t *string, ptrdiff_t length, yp_newline_list_t *newline_list) { +pm_strspn_whitespace_newlines(const uint8_t *string, ptrdiff_t length, pm_newline_list_t *newline_list) { if (length <= 0) return 0; size_t size = 0; size_t maximum = (size_t) length; - while (size < maximum && (yp_byte_table[string[size]] & YP_CHAR_BIT_WHITESPACE)) { + while (size < maximum && (pm_byte_table[string[size]] & PRISM_CHAR_BIT_WHITESPACE)) { if (string[size] == '\n') { - yp_newline_list_append(newline_list, string + size); + pm_newline_list_append(newline_list, string + size); } size++; @@ -95,45 +95,45 @@ yp_strspn_whitespace_newlines(const uint8_t *string, ptrdiff_t length, yp_newlin // Returns the number of characters at the start of the string that are inline // whitespace. Disallows searching past the given maximum number of characters. size_t -yp_strspn_inline_whitespace(const uint8_t *string, ptrdiff_t length) { - return yp_strspn_char_kind(string, length, YP_CHAR_BIT_INLINE_WHITESPACE); +pm_strspn_inline_whitespace(const uint8_t *string, ptrdiff_t length) { + return pm_strspn_char_kind(string, length, PRISM_CHAR_BIT_INLINE_WHITESPACE); } // Returns the number of characters at the start of the string that are regexp // options. Disallows searching past the given maximum number of characters. size_t -yp_strspn_regexp_option(const uint8_t *string, ptrdiff_t length) { - return yp_strspn_char_kind(string, length, YP_CHAR_BIT_REGEXP_OPTION); +pm_strspn_regexp_option(const uint8_t *string, ptrdiff_t length) { + return pm_strspn_char_kind(string, length, PRISM_CHAR_BIT_REGEXP_OPTION); } static inline bool -yp_char_is_char_kind(const uint8_t b, uint8_t kind) { - return (yp_byte_table[b] & kind) != 0; +pm_char_is_char_kind(const uint8_t b, uint8_t kind) { + return (pm_byte_table[b] & kind) != 0; } // Returns true if the given character is a whitespace character. bool -yp_char_is_whitespace(const uint8_t b) { - return yp_char_is_char_kind(b, YP_CHAR_BIT_WHITESPACE); +pm_char_is_whitespace(const uint8_t b) { + return pm_char_is_char_kind(b, PRISM_CHAR_BIT_WHITESPACE); } // Returns true if the given character is an inline whitespace character. bool -yp_char_is_inline_whitespace(const uint8_t b) { - return yp_char_is_char_kind(b, YP_CHAR_BIT_INLINE_WHITESPACE); +pm_char_is_inline_whitespace(const uint8_t b) { + return pm_char_is_char_kind(b, PRISM_CHAR_BIT_INLINE_WHITESPACE); } // Scan through the string and return the number of characters at the start of // the string that match the given kind. Disallows searching past the given // maximum number of characters. static inline size_t -yp_strspn_number_kind(const uint8_t *string, ptrdiff_t length, uint8_t kind) { +pm_strspn_number_kind(const uint8_t *string, ptrdiff_t length, uint8_t kind) { if (length <= 0) return 0; size_t size = 0; size_t maximum = (size_t) length; - while (size < maximum && (yp_number_table[string[size]] & kind)) size++; + while (size < maximum && (pm_number_table[string[size]] & kind)) size++; return size; } @@ -144,14 +144,14 @@ yp_strspn_number_kind(const uint8_t *string, ptrdiff_t length, uint8_t kind) { // Additionally, report the location of the last invalid underscore character // found in the string through the out invalid parameter. static inline size_t -yp_strspn_number_kind_underscores(const uint8_t *string, ptrdiff_t length, const uint8_t **invalid, uint8_t kind) { +pm_strspn_number_kind_underscores(const uint8_t *string, ptrdiff_t length, const uint8_t **invalid, uint8_t kind) { if (length <= 0) return 0; size_t size = 0; size_t maximum = (size_t) length; bool underscore = false; - while (size < maximum && (yp_number_table[string[size]] & kind)) { + while (size < maximum && (pm_number_table[string[size]] & kind)) { if (string[size] == '_') { if (underscore) *invalid = string + size; underscore = true; @@ -174,8 +174,8 @@ yp_strspn_number_kind_underscores(const uint8_t *string, ptrdiff_t length, const // found at the end of the number, then the invalid pointer is set to the index // of the first invalid underscore. size_t -yp_strspn_binary_number(const uint8_t *string, ptrdiff_t length, const uint8_t **invalid) { - return yp_strspn_number_kind_underscores(string, length, invalid, YP_NUMBER_BIT_BINARY_NUMBER); +pm_strspn_binary_number(const uint8_t *string, ptrdiff_t length, const uint8_t **invalid) { + return pm_strspn_number_kind_underscores(string, length, invalid, PRISM_NUMBER_BIT_BINARY_NUMBER); } // Returns the number of characters at the start of the string that are octal @@ -186,15 +186,15 @@ yp_strspn_binary_number(const uint8_t *string, ptrdiff_t length, const uint8_t * // found at the end of the number, then the invalid pointer is set to the index // of the first invalid underscore. size_t -yp_strspn_octal_number(const uint8_t *string, ptrdiff_t length, const uint8_t **invalid) { - return yp_strspn_number_kind_underscores(string, length, invalid, YP_NUMBER_BIT_OCTAL_NUMBER); +pm_strspn_octal_number(const uint8_t *string, ptrdiff_t length, const uint8_t **invalid) { + return pm_strspn_number_kind_underscores(string, length, invalid, PRISM_NUMBER_BIT_OCTAL_NUMBER); } // Returns the number of characters at the start of the string that are decimal // digits. Disallows searching past the given maximum number of characters. size_t -yp_strspn_decimal_digit(const uint8_t *string, ptrdiff_t length) { - return yp_strspn_number_kind(string, length, YP_NUMBER_BIT_DECIMAL_DIGIT); +pm_strspn_decimal_digit(const uint8_t *string, ptrdiff_t length) { + return pm_strspn_number_kind(string, length, PRISM_NUMBER_BIT_DECIMAL_DIGIT); } // Returns the number of characters at the start of the string that are decimal @@ -205,16 +205,16 @@ yp_strspn_decimal_digit(const uint8_t *string, ptrdiff_t length) { // found at the end of the number, then the invalid pointer is set to the index // of the first invalid underscore. size_t -yp_strspn_decimal_number(const uint8_t *string, ptrdiff_t length, const uint8_t **invalid) { - return yp_strspn_number_kind_underscores(string, length, invalid, YP_NUMBER_BIT_DECIMAL_NUMBER); +pm_strspn_decimal_number(const uint8_t *string, ptrdiff_t length, const uint8_t **invalid) { + return pm_strspn_number_kind_underscores(string, length, invalid, PRISM_NUMBER_BIT_DECIMAL_NUMBER); } // Returns the number of characters at the start of the string that are // hexadecimal digits. Disallows searching past the given maximum number of // characters. size_t -yp_strspn_hexadecimal_digit(const uint8_t *string, ptrdiff_t length) { - return yp_strspn_number_kind(string, length, YP_NUMBER_BIT_HEXADECIMAL_DIGIT); +pm_strspn_hexadecimal_digit(const uint8_t *string, ptrdiff_t length) { + return pm_strspn_number_kind(string, length, PRISM_NUMBER_BIT_HEXADECIMAL_DIGIT); } // Returns the number of characters at the start of the string that are @@ -225,48 +225,48 @@ yp_strspn_hexadecimal_digit(const uint8_t *string, ptrdiff_t length) { // found at the end of the number, then the invalid pointer is set to the index // of the first invalid underscore. size_t -yp_strspn_hexadecimal_number(const uint8_t *string, ptrdiff_t length, const uint8_t **invalid) { - return yp_strspn_number_kind_underscores(string, length, invalid, YP_NUMBER_BIT_HEXADECIMAL_NUMBER); +pm_strspn_hexadecimal_number(const uint8_t *string, ptrdiff_t length, const uint8_t **invalid) { + return pm_strspn_number_kind_underscores(string, length, invalid, PRISM_NUMBER_BIT_HEXADECIMAL_NUMBER); } static inline bool -yp_char_is_number_kind(const uint8_t b, uint8_t kind) { - return (yp_number_table[b] & kind) != 0; +pm_char_is_number_kind(const uint8_t b, uint8_t kind) { + return (pm_number_table[b] & kind) != 0; } // Returns true if the given character is a binary digit. bool -yp_char_is_binary_digit(const uint8_t b) { - return yp_char_is_number_kind(b, YP_NUMBER_BIT_BINARY_DIGIT); +pm_char_is_binary_digit(const uint8_t b) { + return pm_char_is_number_kind(b, PRISM_NUMBER_BIT_BINARY_DIGIT); } // Returns true if the given character is an octal digit. bool -yp_char_is_octal_digit(const uint8_t b) { - return yp_char_is_number_kind(b, YP_NUMBER_BIT_OCTAL_DIGIT); +pm_char_is_octal_digit(const uint8_t b) { + return pm_char_is_number_kind(b, PRISM_NUMBER_BIT_OCTAL_DIGIT); } // Returns true if the given character is a decimal digit. bool -yp_char_is_decimal_digit(const uint8_t b) { - return yp_char_is_number_kind(b, YP_NUMBER_BIT_DECIMAL_DIGIT); +pm_char_is_decimal_digit(const uint8_t b) { + return pm_char_is_number_kind(b, PRISM_NUMBER_BIT_DECIMAL_DIGIT); } // Returns true if the given character is a hexadecimal digit. bool -yp_char_is_hexadecimal_digit(const uint8_t b) { - return yp_char_is_number_kind(b, YP_NUMBER_BIT_HEXADECIMAL_DIGIT); +pm_char_is_hexadecimal_digit(const uint8_t b) { + return pm_char_is_number_kind(b, PRISM_NUMBER_BIT_HEXADECIMAL_DIGIT); } -#undef YP_CHAR_BIT_WHITESPACE -#undef YP_CHAR_BIT_INLINE_WHITESPACE -#undef YP_CHAR_BIT_REGEXP_OPTION - -#undef YP_NUMBER_BIT_BINARY_DIGIT -#undef YP_NUMBER_BIT_BINARY_NUMBER -#undef YP_NUMBER_BIT_OCTAL_DIGIT -#undef YP_NUMBER_BIT_OCTAL_NUMBER -#undef YP_NUMBER_BIT_DECIMAL_DIGIT -#undef YP_NUMBER_BIT_DECIMAL_NUMBER -#undef YP_NUMBER_BIT_HEXADECIMAL_NUMBER -#undef YP_NUMBER_BIT_HEXADECIMAL_DIGIT +#undef PRISM_CHAR_BIT_WHITESPACE +#undef PRISM_CHAR_BIT_INLINE_WHITESPACE +#undef PRISM_CHAR_BIT_REGEXP_OPTION + +#undef PRISM_NUMBER_BIT_BINARY_DIGIT +#undef PRISM_NUMBER_BIT_BINARY_NUMBER +#undef PRISM_NUMBER_BIT_OCTAL_DIGIT +#undef PRISM_NUMBER_BIT_OCTAL_NUMBER +#undef PRISM_NUMBER_BIT_DECIMAL_DIGIT +#undef PRISM_NUMBER_BIT_DECIMAL_NUMBER +#undef PRISM_NUMBER_BIT_HEXADECIMAL_NUMBER +#undef PRISM_NUMBER_BIT_HEXADECIMAL_DIGIT |