diff options
author | Raiki Tamura <tamaron1203@gmail.com> | 2023-06-19 18:04:32 +0900 |
---|---|---|
committer | Philip Herron <philip.herron@embecosm.com> | 2023-06-20 08:10:20 +0000 |
commit | c05b7f22389964e45ef0e59bc87a9eb3494a33fa (patch) | |
tree | 3fed2b2a6b70c0009f9ccabab406ecb4128f342d /libcpp/charset.cc | |
parent | b533df36436432def2e8c14099b0cf98f96ff839 (diff) | |
download | gcc-c05b7f22389964e45ef0e59bc87a9eb3494a33fa.zip gcc-c05b7f22389964e45ef0e59bc87a9eb3494a33fa.tar.gz gcc-c05b7f22389964e45ef0e59bc87a9eb3494a33fa.tar.bz2 |
libcpp: add function to check XID properties
libcpp/ChangeLog:
* charset.cc (check_xid_property):new function to check XID_Start and XID_Continue
* include/cpplib.h (check_xid_property):add enum representing XID properties
Signed-off-by: Raiki Tamura <tamaron1203@gmail.com>
Diffstat (limited to 'libcpp/charset.cc')
-rw-r--r-- | libcpp/charset.cc | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/libcpp/charset.cc b/libcpp/charset.cc index d7f323b..5a2229c 100644 --- a/libcpp/charset.cc +++ b/libcpp/charset.cc @@ -1256,6 +1256,42 @@ _cpp_uname2c_uax44_lm2 (const char *name, size_t len, char *canon_name) return result; } +/* Returns flags representing the XID properties of the given codepoint. */ +unsigned int +check_xid_property (cppchar_t c) +{ + // fast path for ASCII + if (c < 0x80) + { + if (('A' <= c && c <= 'Z') || ('a' <= c && c <= 'z')) + return XID_START | XID_CONTINUE; + if (('0' <= c && c <= '9') || c == '_') + return XID_CONTINUE; + } + + if (c > UCS_LIMIT) + return 0; + + int mn, mx, md; + mn = 0; + mx = ARRAY_SIZE (ucnranges) - 1; + while (mx != mn) + { + md = (mn + mx) / 2; + if (c <= ucnranges[md].end) + mx = md; + else + mn = md + 1; + } + + unsigned short flags = ucnranges[mn].flags; + + if (flags & CXX23) + return XID_START | XID_CONTINUE; + if (flags & NXX23) + return XID_CONTINUE; + return 0; +} /* Returns 1 if C is valid in an identifier, 2 if C is valid except at the start of an identifier, and 0 if C is not valid in an |