backburn 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/LICENSE +21 -0
- data/Makefile +50 -0
- data/README.md +520 -0
- data/docs/cli-and-outputs.md +226 -0
- data/docs/technical-spec.md +656 -0
- data/exe/backburn +8 -0
- data/ext/backburn/extconf.rb +31 -0
- data/ext/backburn/prism/COMMIT +1 -0
- data/ext/backburn/prism/LICENSE.md +7 -0
- data/ext/backburn/prism/Makefile +213 -0
- data/ext/backburn/prism/include/prism/arena.h +45 -0
- data/ext/backburn/prism/include/prism/arena.hpp +42 -0
- data/ext/backburn/prism/include/prism/ast.h +10395 -0
- data/ext/backburn/prism/include/prism/ast.hpp +641 -0
- data/ext/backburn/prism/include/prism/buffer.h +60 -0
- data/ext/backburn/prism/include/prism/buffer.hpp +55 -0
- data/ext/backburn/prism/include/prism/comments.h +72 -0
- data/ext/backburn/prism/include/prism/compiler/accel.h +26 -0
- data/ext/backburn/prism/include/prism/compiler/align.h +36 -0
- data/ext/backburn/prism/include/prism/compiler/assume.h +25 -0
- data/ext/backburn/prism/include/prism/compiler/branch.h +26 -0
- data/ext/backburn/prism/include/prism/compiler/bswap.h +46 -0
- data/ext/backburn/prism/include/prism/compiler/cplusplus.hpp +16 -0
- data/ext/backburn/prism/include/prism/compiler/endianness.h +34 -0
- data/ext/backburn/prism/include/prism/compiler/exceptions.hpp +17 -0
- data/ext/backburn/prism/include/prism/compiler/exported.h +24 -0
- data/ext/backburn/prism/include/prism/compiler/fallthrough.h +22 -0
- data/ext/backburn/prism/include/prism/compiler/filesystem.h +32 -0
- data/ext/backburn/prism/include/prism/compiler/flex_array.h +19 -0
- data/ext/backburn/prism/include/prism/compiler/force_inline.h +21 -0
- data/ext/backburn/prism/include/prism/compiler/format.h +27 -0
- data/ext/backburn/prism/include/prism/compiler/inline.h +17 -0
- data/ext/backburn/prism/include/prism/compiler/lifetimebound.hpp +25 -0
- data/ext/backburn/prism/include/prism/compiler/nodiscard.h +22 -0
- data/ext/backburn/prism/include/prism/compiler/nonnull.h +18 -0
- data/ext/backburn/prism/include/prism/compiler/noreturn.h +24 -0
- data/ext/backburn/prism/include/prism/compiler/stack.h +60 -0
- data/ext/backburn/prism/include/prism/compiler/unused.h +18 -0
- data/ext/backburn/prism/include/prism/constant_pool.h +112 -0
- data/ext/backburn/prism/include/prism/diagnostic.h +121 -0
- data/ext/backburn/prism/include/prism/errors_format.h +63 -0
- data/ext/backburn/prism/include/prism/excludes.h +29 -0
- data/ext/backburn/prism/include/prism/integer.h +79 -0
- data/ext/backburn/prism/include/prism/internal/allocator.h +68 -0
- data/ext/backburn/prism/include/prism/internal/allocator_debug.h +88 -0
- data/ext/backburn/prism/include/prism/internal/arena.h +223 -0
- data/ext/backburn/prism/include/prism/internal/assert.h +14 -0
- data/ext/backburn/prism/include/prism/internal/bignum.h +239 -0
- data/ext/backburn/prism/include/prism/internal/bit.h +66 -0
- data/ext/backburn/prism/include/prism/internal/buffer.h +104 -0
- data/ext/backburn/prism/include/prism/internal/char.h +145 -0
- data/ext/backburn/prism/include/prism/internal/comments.h +54 -0
- data/ext/backburn/prism/include/prism/internal/constant_pool.h +155 -0
- data/ext/backburn/prism/include/prism/internal/diagnostic.h +392 -0
- data/ext/backburn/prism/include/prism/internal/double.h +19 -0
- data/ext/backburn/prism/include/prism/internal/encoding.h +326 -0
- data/ext/backburn/prism/include/prism/internal/integer.h +66 -0
- data/ext/backburn/prism/include/prism/internal/isinf.h +16 -0
- data/ext/backburn/prism/include/prism/internal/line_offset_list.h +50 -0
- data/ext/backburn/prism/include/prism/internal/list.h +62 -0
- data/ext/backburn/prism/include/prism/internal/magic_comments.h +23 -0
- data/ext/backburn/prism/include/prism/internal/memchr.h +15 -0
- data/ext/backburn/prism/include/prism/internal/node.h +197 -0
- data/ext/backburn/prism/include/prism/internal/oom.h +16 -0
- data/ext/backburn/prism/include/prism/internal/options.h +248 -0
- data/ext/backburn/prism/include/prism/internal/parser.h +1170 -0
- data/ext/backburn/prism/include/prism/internal/regexp.h +70 -0
- data/ext/backburn/prism/include/prism/internal/serialize.h +39 -0
- data/ext/backburn/prism/include/prism/internal/source.h +72 -0
- data/ext/backburn/prism/include/prism/internal/static_literals.h +60 -0
- data/ext/backburn/prism/include/prism/internal/stringy.h +37 -0
- data/ext/backburn/prism/include/prism/internal/strncasecmp.h +18 -0
- data/ext/backburn/prism/include/prism/internal/strpbrk.h +61 -0
- data/ext/backburn/prism/include/prism/internal/tokens.h +11 -0
- data/ext/backburn/prism/include/prism/internal/xxh3.h +16 -0
- data/ext/backburn/prism/include/prism/json.h +40 -0
- data/ext/backburn/prism/include/prism/line_offset_list.h +69 -0
- data/ext/backburn/prism/include/prism/magic_comments.h +53 -0
- data/ext/backburn/prism/include/prism/node.h +139 -0
- data/ext/backburn/prism/include/prism/node.hpp +272 -0
- data/ext/backburn/prism/include/prism/node_type.hpp +38 -0
- data/ext/backburn/prism/include/prism/options.h +393 -0
- data/ext/backburn/prism/include/prism/options.hpp +43 -0
- data/ext/backburn/prism/include/prism/parser.h +433 -0
- data/ext/backburn/prism/include/prism/parser.hpp +274 -0
- data/ext/backburn/prism/include/prism/prettyprint.h +39 -0
- data/ext/backburn/prism/include/prism/serialize.h +123 -0
- data/ext/backburn/prism/include/prism/source.h +163 -0
- data/ext/backburn/prism/include/prism/stream.h +36 -0
- data/ext/backburn/prism/include/prism/string_query.h +97 -0
- data/ext/backburn/prism/include/prism/stringy.h +61 -0
- data/ext/backburn/prism/include/prism/stringy.hpp +31 -0
- data/ext/backburn/prism/include/prism/version.h +46 -0
- data/ext/backburn/prism/include/prism.h +123 -0
- data/ext/backburn/prism/include/prism.hpp +24 -0
- data/ext/backburn/prism/src/arena.c +200 -0
- data/ext/backburn/prism/src/bignum.c +399 -0
- data/ext/backburn/prism/src/buffer.c +405 -0
- data/ext/backburn/prism/src/char.c +289 -0
- data/ext/backburn/prism/src/comments.c +455 -0
- data/ext/backburn/prism/src/constant_pool.c +410 -0
- data/ext/backburn/prism/src/diagnostic.c +918 -0
- data/ext/backburn/prism/src/double.c +394 -0
- data/ext/backburn/prism/src/encoding.c +1701 -0
- data/ext/backburn/prism/src/errors_format.c +650 -0
- data/ext/backburn/prism/src/integer.c +675 -0
- data/ext/backburn/prism/src/json.c +5745 -0
- data/ext/backburn/prism/src/line_offset_list.c +99 -0
- data/ext/backburn/prism/src/list.c +24 -0
- data/ext/backburn/prism/src/memchr.c +37 -0
- data/ext/backburn/prism/src/node.c +4464 -0
- data/ext/backburn/prism/src/options.c +475 -0
- data/ext/backburn/prism/src/parser.c +371 -0
- data/ext/backburn/prism/src/prettyprint.c +9038 -0
- data/ext/backburn/prism/src/prism.c +23615 -0
- data/ext/backburn/prism/src/regexp.c +3833 -0
- data/ext/backburn/prism/src/serialize.c +2656 -0
- data/ext/backburn/prism/src/source.c +525 -0
- data/ext/backburn/prism/src/static_literals.c +562 -0
- data/ext/backburn/prism/src/string_query.c +195 -0
- data/ext/backburn/prism/src/stringy.c +77 -0
- data/ext/backburn/prism/src/strncasecmp.c +37 -0
- data/ext/backburn/prism/src/strpbrk.c +465 -0
- data/ext/backburn/prism/src/tokens.c +724 -0
- data/ext/backburn/prism/src/xxh3.c +292 -0
- data/lib/backburn/version.rb +7 -0
- data/presets/devise.roots +11 -0
- data/presets/fast-mcp.roots +5 -0
- data/presets/graphql.roots +6 -0
- data/presets/phlex.roots +7 -0
- data/presets/pundit.roots +3 -0
- data/presets/rails-framework.roots +10 -0
- data/presets/rails.roots +83 -0
- data/presets/sidekiq.roots +4 -0
- data/presets/thor.roots +3 -0
- data/rails.roots +99 -0
- data/scripts/embed-presets.sh +13 -0
- data/scripts/version-h.sh +7 -0
- data/src/analysis/analysis.c +95 -0
- data/src/analysis/analysis.h +24 -0
- data/src/analysis/batches.c +127 -0
- data/src/analysis/batches.h +17 -0
- data/src/analysis/graph.c +238 -0
- data/src/analysis/graph.h +34 -0
- data/src/analysis/mark.c +300 -0
- data/src/analysis/mark.h +21 -0
- data/src/analysis/roots.c +229 -0
- data/src/analysis/roots.h +29 -0
- data/src/cli/cli.c +237 -0
- data/src/cli/cli.h +9 -0
- data/src/cli/config.c +112 -0
- data/src/cli/config.h +14 -0
- data/src/cli/options.c +17 -0
- data/src/cli/options.h +35 -0
- data/src/commands/commands.h +11 -0
- data/src/commands/explain.c +255 -0
- data/src/commands/gemfile.c +126 -0
- data/src/commands/gemfile.h +27 -0
- data/src/commands/gems.c +408 -0
- data/src/commands/init.c +92 -0
- data/src/commands/roots.c +82 -0
- data/src/commands/scan.c +91 -0
- data/src/core/intern.c +94 -0
- data/src/core/intern.h +40 -0
- data/src/core/json.c +17 -0
- data/src/core/json.h +9 -0
- data/src/core/model.c +25 -0
- data/src/core/model.h +85 -0
- data/src/core/util.c +116 -0
- data/src/core/util.h +48 -0
- data/src/index/erb.c +40 -0
- data/src/index/erb.h +9 -0
- data/src/index/haml.c +334 -0
- data/src/index/haml.h +10 -0
- data/src/index/indexer.c +702 -0
- data/src/index/indexer.h +19 -0
- data/src/index/walk.c +144 -0
- data/src/index/walk.h +14 -0
- data/src/main.c +81 -0
- data/src/output/baseline.c +101 -0
- data/src/output/baseline.h +15 -0
- data/src/output/report.c +440 -0
- data/src/output/report.h +28 -0
- metadata +231 -0
|
@@ -0,0 +1,1701 @@
|
|
|
1
|
+
#include "prism/internal/encoding.h"
|
|
2
|
+
|
|
3
|
+
#include "prism/compiler/branch.h"
|
|
4
|
+
#include "prism/internal/assert.h"
|
|
5
|
+
#include "prism/internal/strncasecmp.h"
|
|
6
|
+
|
|
7
|
+
typedef uint32_t pm_unicode_codepoint_t;
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* The properties of every unicode codepoint are stored in a three-stage lookup
|
|
11
|
+
* table, as described in section 5.1 of the unicode core specification. The
|
|
12
|
+
* high bits of a codepoint index the root table, which gives a middle block.
|
|
13
|
+
* The next five bits index that middle block, which gives a leaf block. The low
|
|
14
|
+
* three bits index that leaf block, which gives the properties of the
|
|
15
|
+
* codepoint, with the same uppercase bit as the ASCII table. Codepoints with
|
|
16
|
+
* identical blocks share a single copy, so the tables stay small, and every
|
|
17
|
+
* lookup is three loads with no searching. Codepoints at or above
|
|
18
|
+
* UNICODE_CODEPOINTS_MAXIMUM have no properties.
|
|
19
|
+
*
|
|
20
|
+
* The tables are Unicode 17.0.0. `bin/prism encoding UTF-8` generates them from
|
|
21
|
+
* the Unicode Character Database at that version.
|
|
22
|
+
*/
|
|
23
|
+
#define UNICODE_CODEPOINTS_MAXIMUM 0x1FC00
|
|
24
|
+
|
|
25
|
+
static const uint8_t pm_unicode_root[508] = {
|
|
26
|
+
/* U+00000 */ 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x04, 0x0E,
|
|
27
|
+
/* U+01000 */ 0x0F, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x00, 0x17, 0x18,
|
|
28
|
+
/* U+02000 */ 0x00, 0x19, 0x00, 0x00, 0x1A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1B, 0x00, 0x00, 0x00,
|
|
29
|
+
/* U+03000 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
30
|
+
/* U+04000 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
31
|
+
/* U+05000 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
32
|
+
/* U+06000 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
33
|
+
/* U+07000 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
34
|
+
/* U+08000 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
35
|
+
/* U+09000 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
36
|
+
/* U+0A000 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1C, 0x1D, 0x1E, 0x1F, 0x02, 0x03, 0x00, 0x00, 0x00, 0x00,
|
|
37
|
+
/* U+0B000 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
38
|
+
/* U+0C000 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
39
|
+
/* U+0D000 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
40
|
+
/* U+0E000 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
41
|
+
/* U+0F000 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20,
|
|
42
|
+
/* U+10000 */ 0x00, 0x00, 0x00, 0x00, 0x21, 0x22, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x23, 0x24, 0x00, 0x00,
|
|
43
|
+
/* U+11000 */ 0x25, 0x26, 0x03, 0x00, 0x04, 0x00, 0x27, 0x28, 0x29, 0x02, 0x00, 0x05, 0x02, 0x2A, 0x00, 0x02,
|
|
44
|
+
/* U+12000 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
45
|
+
/* U+13000 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
46
|
+
/* U+14000 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
47
|
+
/* U+15000 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
48
|
+
/* U+16000 */ 0x00, 0x2B, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x2C, 0x02, 0x00, 0x2D, 0x2E, 0x00,
|
|
49
|
+
/* U+17000 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
50
|
+
/* U+18000 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
51
|
+
/* U+19000 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
52
|
+
/* U+1A000 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
53
|
+
/* U+1B000 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
54
|
+
/* U+1C000 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00,
|
|
55
|
+
/* U+1D000 */ 0x00, 0x00, 0x00, 0x00, 0x2F, 0x30, 0x31, 0x32, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
56
|
+
/* U+1E000 */ 0x00, 0x33, 0x03, 0x00, 0x03, 0x34, 0x00, 0x00, 0x00, 0x35, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
57
|
+
/* U+1F000 */ 0x00, 0x36, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03,
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
static const uint8_t pm_unicode_middle[55][32] = {
|
|
61
|
+
[0x00] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
|
|
62
|
+
[0x01] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x03, 0x00, 0x00 },
|
|
63
|
+
[0x02] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
|
|
64
|
+
[0x03] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x04 },
|
|
65
|
+
[0x04] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x04, 0x00, 0x00, 0x00, 0x00 },
|
|
66
|
+
[0x05] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x0A },
|
|
67
|
+
[0x06] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x04, 0x0D, 0x01, 0x01, 0x0E, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x0F, 0x0F, 0x00, 0x00, 0x00, 0x00 },
|
|
68
|
+
[0x07] = { 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x10, 0x10, 0x11, 0x02, 0x02, 0x02, 0x02, 0x02, 0x22, 0x17, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x18, 0x2A, 0x10, 0x2B, 0x02, 0x02, 0x17, 0x02 },
|
|
69
|
+
[0x08] = { 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x15, 0x2C, 0x2D, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
|
|
70
|
+
[0x09] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x19, 0x1A, 0x1B, 0x2E, 0x0D, 0x01, 0x2F, 0x12, 0x00, 0x00, 0x00, 0x1A, 0x30, 0x02, 0x02, 0x02, 0x31, 0x32 },
|
|
71
|
+
[0x0A] = { 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x02, 0x02, 0x02, 0x13, 0x11, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x33, 0x34, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02 },
|
|
72
|
+
[0x0B] = { 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x0D, 0x01, 0x01, 0x01, 0x0F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
|
|
73
|
+
[0x0C] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x04 },
|
|
74
|
+
[0x0D] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
|
|
75
|
+
[0x0E] = { 0x00, 0x00, 0x00, 0x00, 0x03, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
|
|
76
|
+
[0x0F] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x04, 0x01, 0x01, 0x01, 0x01, 0x35, 0x16, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
|
|
77
|
+
[0x10] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x07, 0x00 },
|
|
78
|
+
[0x11] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x04, 0x00, 0x00 },
|
|
79
|
+
[0x12] = { 0x00, 0x00, 0x03, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
|
|
80
|
+
[0x13] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x04, 0x00, 0x00, 0x00, 0x00 },
|
|
81
|
+
[0x14] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x04, 0x03, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
|
|
82
|
+
[0x15] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
|
|
83
|
+
[0x16] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x04, 0x03, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x36, 0x01, 0x01, 0x01, 0x01, 0x01, 0x1C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
|
|
84
|
+
[0x17] = { 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x1D, 0x1B, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02 },
|
|
85
|
+
[0x18] = { 0x00, 0x01, 0x00, 0x07, 0x00, 0x01, 0x00, 0x01, 0x00, 0x07, 0x00, 0x10, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x09, 0x00, 0x09, 0x00, 0x12, 0x00, 0x09, 0x00, 0x09 },
|
|
86
|
+
[0x19] = { 0x37, 0x38, 0x39, 0x3A, 0x3B, 0x3C, 0x12, 0x14, 0x16, 0x00, 0x00, 0x00, 0x01, 0x01, 0x00, 0x00, 0x3D, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
|
|
87
|
+
[0x1A] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x14, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
|
|
88
|
+
[0x1B] = { 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3E, 0x3F, 0x40, 0x14, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x15, 0x1E, 0x41, 0x00 },
|
|
89
|
+
[0x1C] = { 0x00, 0x00, 0x00, 0x00, 0x03, 0x04, 0x00, 0x00, 0x02, 0x02, 0x02, 0x02, 0x02, 0x1D, 0x00, 0x00, 0x02, 0x02, 0x02, 0x15, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
|
|
90
|
+
[0x1D] = { 0x00, 0x00, 0x00, 0x00, 0x11, 0x02, 0x11, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x00, 0x42, 0x02, 0x1E, 0x19, 0x02, 0x02, 0x43, 0x1F, 0x02, 0x44, 0x45, 0x46, 0x47, 0x00, 0x00, 0x16, 0x00 },
|
|
91
|
+
[0x1E] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x04, 0x00, 0x00, 0x00, 0x00 },
|
|
92
|
+
[0x1F] = { 0x03, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x04, 0x00, 0x00, 0x03, 0x04 },
|
|
93
|
+
[0x20] = { 0x00, 0x00, 0x03, 0x04, 0x0D, 0x01, 0x01, 0x0E, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
|
|
94
|
+
[0x21] = { 0x01, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x04, 0x01, 0x01, 0x01, 0x01, 0x12, 0x00, 0x00, 0x00, 0x00, 0x00 },
|
|
95
|
+
[0x22] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x20, 0x01, 0x20, 0x48, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
|
|
96
|
+
[0x23] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x0E, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
|
|
97
|
+
[0x24] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x04, 0x08, 0x0A, 0x0B, 0x0B, 0x49, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
|
|
98
|
+
[0x25] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x04 },
|
|
99
|
+
[0x26] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x04, 0x00, 0x00, 0x00, 0x00 },
|
|
100
|
+
[0x27] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x04, 0x08, 0x08, 0x4A, 0x00, 0x00, 0x00 },
|
|
101
|
+
[0x28] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
|
|
102
|
+
[0x29] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x03, 0x04, 0x00, 0x00 },
|
|
103
|
+
[0x2A] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x0A, 0x00, 0x00 },
|
|
104
|
+
[0x2B] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x0A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
|
|
105
|
+
[0x2C] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
|
|
106
|
+
[0x2D] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x0A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
|
|
107
|
+
[0x2E] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0B, 0x0B, 0x0B, 0x4B, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
|
|
108
|
+
[0x2F] = { 0x01, 0x01, 0x01, 0x06, 0x00, 0x00, 0x0C, 0x01, 0x01, 0x07, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x06, 0x00, 0x00, 0x4C, 0x4D, 0x4E, 0x07, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x06, 0x00, 0x00 },
|
|
109
|
+
[0x30] = { 0x18, 0x1C, 0x4F, 0x09, 0x00, 0x00, 0x00, 0x50, 0x1F, 0x21, 0x13, 0x00, 0x00, 0x0C, 0x01, 0x01, 0x07, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x06, 0x00, 0x00, 0x0C, 0x01, 0x01, 0x07, 0x00, 0x00 },
|
|
110
|
+
[0x31] = { 0x00, 0x01, 0x01, 0x01, 0x06, 0x00, 0x00, 0x0C, 0x01, 0x01, 0x07, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x06, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x13, 0x00, 0x00, 0x00, 0x21, 0x01, 0x01, 0x0E },
|
|
111
|
+
[0x32] = { 0x00, 0x00, 0x00, 0x0C, 0x01, 0x01, 0x09, 0x00, 0x00, 0x00, 0x14, 0x01, 0x01, 0x0F, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x13, 0x00, 0x00, 0x00, 0x51, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03 },
|
|
112
|
+
[0x33] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
|
|
113
|
+
[0x34] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x52, 0x53 },
|
|
114
|
+
[0x35] = { 0x01, 0x01, 0x01, 0x01, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
|
|
115
|
+
[0x36] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x06, 0x01, 0x01, 0x01, 0x06, 0x01, 0x01, 0x01, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* The version of Ruby that updated its version of Unicode to 17.0.0.
|
|
120
|
+
*
|
|
121
|
+
* * Ruby 3.3 and 3.4 use Unicode 15.0.0.
|
|
122
|
+
* * Ruby 4.0 and 4.1 use Unicode 17.0.0.
|
|
123
|
+
*/
|
|
124
|
+
#define PM_UNICODE_TABLES_17_UPDATE PM_OPTIONS_VERSION_CRUBY_4_0
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* The unicode tables use the fourth bit of each property byte to mark the
|
|
128
|
+
* letters that are uppercase or titlecase in the tables but not in Unicode
|
|
129
|
+
* 15.0.0, which the versions of Ruby before PM_UNICODE_TABLES_17_UPDATE
|
|
130
|
+
* use.
|
|
131
|
+
*/
|
|
132
|
+
#define PM_UNICODE_15_NOT_UPPERCASE_BIT (1 << 3)
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* The unicode tables use the fifth bit of each property byte to mark the
|
|
136
|
+
* decimal digits (Nd).
|
|
137
|
+
*/
|
|
138
|
+
#define PM_UNICODE_DIGIT_BIT (1 << 4)
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* The unicode tables use the sixth bit of each property byte to mark the
|
|
142
|
+
* decimal digits in the tables that are not ones in Unicode 15.0.0.
|
|
143
|
+
*/
|
|
144
|
+
#define PM_UNICODE_15_NOT_DIGIT_BIT (1 << 5)
|
|
145
|
+
|
|
146
|
+
/* Neither uppercase nor a digit. */
|
|
147
|
+
#define N 0
|
|
148
|
+
|
|
149
|
+
/* An uppercase or titlecase letter. */
|
|
150
|
+
#define U (PRISM_ENCODING_UPPERCASE_BIT)
|
|
151
|
+
|
|
152
|
+
/* An uppercase or titlecase letter that is not one in Unicode 15.0.0. */
|
|
153
|
+
#define V (PRISM_ENCODING_UPPERCASE_BIT | PM_UNICODE_15_NOT_UPPERCASE_BIT)
|
|
154
|
+
|
|
155
|
+
/* A decimal digit. */
|
|
156
|
+
#define D (PM_UNICODE_DIGIT_BIT)
|
|
157
|
+
|
|
158
|
+
/* A decimal digit that is not one in Unicode 15.0.0. */
|
|
159
|
+
#define E (PM_UNICODE_DIGIT_BIT | PM_UNICODE_15_NOT_DIGIT_BIT)
|
|
160
|
+
|
|
161
|
+
static const uint8_t pm_unicode_leaf[84][8] = {
|
|
162
|
+
[0x00] = { N, N, N, N, N, N, N, N },
|
|
163
|
+
[0x01] = { U, U, U, U, U, U, U, U },
|
|
164
|
+
[0x02] = { U, N, U, N, U, N, U, N },
|
|
165
|
+
[0x03] = { D, D, D, D, D, D, D, D },
|
|
166
|
+
[0x04] = { D, D, N, N, N, N, N, N },
|
|
167
|
+
[0x05] = { N, N, N, N, N, N, D, D },
|
|
168
|
+
[0x06] = { U, U, N, N, N, N, N, N },
|
|
169
|
+
[0x07] = { U, U, U, U, U, U, N, N },
|
|
170
|
+
[0x08] = { E, E, E, E, E, E, E, E },
|
|
171
|
+
[0x09] = { U, U, U, U, U, N, N, N },
|
|
172
|
+
[0x0A] = { E, E, N, N, N, N, N, N },
|
|
173
|
+
[0x0B] = { V, V, V, V, V, V, V, V },
|
|
174
|
+
[0x0C] = { N, N, N, N, U, U, U, U },
|
|
175
|
+
[0x0D] = { N, U, U, U, U, U, U, U },
|
|
176
|
+
[0x0E] = { U, U, U, N, N, N, N, N },
|
|
177
|
+
[0x0F] = { U, U, U, U, U, U, U, N },
|
|
178
|
+
[0x10] = { N, U, N, U, N, U, N, U },
|
|
179
|
+
[0x11] = { N, N, U, N, U, N, U, N },
|
|
180
|
+
[0x12] = { U, U, U, U, N, N, N, N },
|
|
181
|
+
[0x13] = { U, N, N, N, N, N, N, N },
|
|
182
|
+
[0x14] = { N, N, N, N, N, N, U, U },
|
|
183
|
+
[0x15] = { U, N, U, N, N, N, N, N },
|
|
184
|
+
[0x16] = { N, N, N, N, N, U, N, N },
|
|
185
|
+
[0x17] = { N, U, U, N, U, N, U, U },
|
|
186
|
+
[0x18] = { N, N, N, N, U, U, N, U },
|
|
187
|
+
[0x19] = { U, N, U, N, N, N, U, N },
|
|
188
|
+
[0x1A] = { N, N, N, N, N, N, N, U },
|
|
189
|
+
[0x1B] = { N, N, N, N, N, N, U, N },
|
|
190
|
+
[0x1C] = { U, U, U, N, N, U, U, U },
|
|
191
|
+
[0x1D] = { U, N, U, N, U, N, N, N },
|
|
192
|
+
[0x1E] = { N, N, N, U, N, U, N, N },
|
|
193
|
+
[0x1F] = { U, U, U, U, U, N, U, N },
|
|
194
|
+
[0x20] = { U, U, U, N, U, U, U, U },
|
|
195
|
+
[0x21] = { N, N, U, U, U, U, U, U },
|
|
196
|
+
[0x22] = { U, U, N, U, N, U, N, N },
|
|
197
|
+
[0x23] = { N, U, U, U, N, N, U, U },
|
|
198
|
+
[0x24] = { U, U, N, U, U, N, U, U },
|
|
199
|
+
[0x25] = { U, N, N, N, U, U, N, U },
|
|
200
|
+
[0x26] = { U, N, U, N, U, N, U, U },
|
|
201
|
+
[0x27] = { N, U, N, N, U, N, U, U },
|
|
202
|
+
[0x28] = { N, U, U, U, N, U, N, U },
|
|
203
|
+
[0x29] = { U, N, N, N, U, N, N, N },
|
|
204
|
+
[0x2A] = { U, N, U, U, N, U, N, U },
|
|
205
|
+
[0x2B] = { N, U, N, U, N, N, U, N },
|
|
206
|
+
[0x2C] = { N, N, U, U, N, U, U, N },
|
|
207
|
+
[0x2D] = { N, U, N, U, U, U, U, N },
|
|
208
|
+
[0x2E] = { U, U, U, N, U, N, U, U },
|
|
209
|
+
[0x2F] = { U, U, N, U, U, U, U, U },
|
|
210
|
+
[0x30] = { N, N, U, U, U, N, N, N },
|
|
211
|
+
[0x31] = { N, N, N, N, U, N, N, U },
|
|
212
|
+
[0x32] = { N, U, U, N, N, U, U, U },
|
|
213
|
+
[0x33] = { U, U, N, U, N, U, N, U },
|
|
214
|
+
[0x34] = { N, U, N, U, N, U, N, N },
|
|
215
|
+
[0x35] = { U, U, U, U, U, U, N, U },
|
|
216
|
+
[0x36] = { N, V, N, N, N, N, N, N },
|
|
217
|
+
[0x37] = { N, N, U, N, N, N, N, U },
|
|
218
|
+
[0x38] = { N, N, N, U, U, U, N, N },
|
|
219
|
+
[0x39] = { U, U, U, N, N, U, N, N },
|
|
220
|
+
[0x3A] = { N, U, U, U, U, U, N, N },
|
|
221
|
+
[0x3B] = { N, N, N, N, U, N, U, N },
|
|
222
|
+
[0x3C] = { U, N, U, U, U, U, N, N },
|
|
223
|
+
[0x3D] = { N, N, N, U, N, N, N, N },
|
|
224
|
+
[0x3E] = { U, N, U, U, U, N, N, U },
|
|
225
|
+
[0x3F] = { N, U, N, U, N, U, U, U },
|
|
226
|
+
[0x40] = { U, N, U, N, N, U, N, N },
|
|
227
|
+
[0x41] = { N, N, U, N, N, N, N, N },
|
|
228
|
+
[0x42] = { N, U, N, U, N, U, U, N },
|
|
229
|
+
[0x43] = { U, N, U, U, U, U, U, N },
|
|
230
|
+
[0x44] = { U, N, U, N, U, U, U, U },
|
|
231
|
+
[0x45] = { N, U, N, V, V, N, V, N },
|
|
232
|
+
[0x46] = { U, N, V, N, V, N, U, N },
|
|
233
|
+
[0x47] = { U, N, V, N, V, N, N, N },
|
|
234
|
+
[0x48] = { U, U, U, N, U, U, N, N },
|
|
235
|
+
[0x49] = { V, V, V, V, V, V, N, N },
|
|
236
|
+
[0x4A] = { E, E, E, E, N, N, N, N },
|
|
237
|
+
[0x4B] = { V, N, N, N, N, N, N, N },
|
|
238
|
+
[0x4C] = { N, N, N, N, U, N, U, U },
|
|
239
|
+
[0x4D] = { N, N, U, N, N, U, U, N },
|
|
240
|
+
[0x4E] = { N, U, U, U, U, N, U, U },
|
|
241
|
+
[0x4F] = { U, U, U, U, U, N, U, U },
|
|
242
|
+
[0x50] = { U, U, N, U, U, U, U, N },
|
|
243
|
+
[0x51] = { N, N, U, N, N, N, D, D },
|
|
244
|
+
[0x52] = { N, E, E, E, E, E, E, E },
|
|
245
|
+
[0x53] = { E, E, E, N, N, N, N, N },
|
|
246
|
+
};
|
|
247
|
+
|
|
248
|
+
#undef N
|
|
249
|
+
#undef U
|
|
250
|
+
#undef V
|
|
251
|
+
#undef D
|
|
252
|
+
#undef E
|
|
253
|
+
|
|
254
|
+
/**
|
|
255
|
+
* Each element of the following table contains a bitfield that indicates a
|
|
256
|
+
* piece of information about the corresponding US-ASCII character. Every
|
|
257
|
+
* encoding that prism supports is ASCII-compatible, so this table answers for
|
|
258
|
+
* the bytes below 0x80 in all of them.
|
|
259
|
+
*/
|
|
260
|
+
const uint8_t pm_encoding_ascii_table[256] = {
|
|
261
|
+
/* 0 1 2 3 4 5 6 7 8 9 A B C D E F */
|
|
262
|
+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x */
|
|
263
|
+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 1x */
|
|
264
|
+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 2x */
|
|
265
|
+
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 0, 0, 0, 0, 0, 0, /* 3x */
|
|
266
|
+
0, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, /* 4x */
|
|
267
|
+
7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 0, 0, 0, 0, 0, /* 5x */
|
|
268
|
+
0, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, /* 6x */
|
|
269
|
+
3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 0, 0, 0, 0, 0, /* 7x */
|
|
270
|
+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 8x */
|
|
271
|
+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 9x */
|
|
272
|
+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* Ax */
|
|
273
|
+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* Bx */
|
|
274
|
+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* Cx */
|
|
275
|
+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* Dx */
|
|
276
|
+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* Ex */
|
|
277
|
+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* Fx */
|
|
278
|
+
};
|
|
279
|
+
|
|
280
|
+
/**
|
|
281
|
+
* Return the bitfield of properties for the given unicode codepoint.
|
|
282
|
+
*/
|
|
283
|
+
static uint8_t
|
|
284
|
+
pm_unicode_codepoint_properties(pm_unicode_codepoint_t codepoint) {
|
|
285
|
+
if (codepoint >= UNICODE_CODEPOINTS_MAXIMUM) return 0;
|
|
286
|
+
|
|
287
|
+
uint8_t middle = pm_unicode_root[codepoint >> 8];
|
|
288
|
+
uint8_t leaf = pm_unicode_middle[middle][(codepoint >> 3) & 0x1F];
|
|
289
|
+
return pm_unicode_leaf[leaf][codepoint & 0x7];
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
/**
|
|
293
|
+
* Return true if the code point is uppercase, or titlecase, in the version of
|
|
294
|
+
* Unicode of the given version of Ruby.
|
|
295
|
+
*/
|
|
296
|
+
static bool
|
|
297
|
+
pm_unicode_uppercase_p(pm_unicode_codepoint_t codepoint, pm_options_version_t version) {
|
|
298
|
+
uint8_t properties = pm_unicode_codepoint_properties(codepoint);
|
|
299
|
+
bool uppercase = (properties & PRISM_ENCODING_UPPERCASE_BIT) != 0;
|
|
300
|
+
|
|
301
|
+
/* The tables say if it is an uppercase codepoint in the latest version of
|
|
302
|
+
* Unicode that Ruby uses. If we are parsing as an older version, then we
|
|
303
|
+
* need to exclude more recently added codepoint ranges. */
|
|
304
|
+
if (PRISM_UNLIKELY(version < PM_UNICODE_TABLES_17_UPDATE && (properties & PM_UNICODE_15_NOT_UPPERCASE_BIT))) {
|
|
305
|
+
uppercase = false;
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
return uppercase;
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
/**
|
|
312
|
+
* Return true if the code point is a decimal digit in the version of Unicode of
|
|
313
|
+
* the given version of Ruby.
|
|
314
|
+
*/
|
|
315
|
+
bool
|
|
316
|
+
pm_encoding_unicode_digit_p(uint32_t codepoint, pm_options_version_t version) {
|
|
317
|
+
uint8_t properties = pm_unicode_codepoint_properties(codepoint);
|
|
318
|
+
bool digit = (properties & PM_UNICODE_DIGIT_BIT) != 0;
|
|
319
|
+
|
|
320
|
+
/* The tables say if it is a digit in the latest version of Unicode that
|
|
321
|
+
* Ruby uses. If we are parsing as an older version, then we need to exclude
|
|
322
|
+
* the digits that were added since. */
|
|
323
|
+
if (PRISM_UNLIKELY(version < PM_UNICODE_TABLES_17_UPDATE && (properties & PM_UNICODE_15_NOT_DIGIT_BIT))) {
|
|
324
|
+
digit = false;
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
return digit;
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
/**
|
|
331
|
+
* A state transition table for decoding UTF-8.
|
|
332
|
+
*
|
|
333
|
+
* Copyright (c) 2008-2009 Bjoern Hoehrmann <bjoern@hoehrmann.de>
|
|
334
|
+
*
|
|
335
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
336
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
337
|
+
* in the Software without restriction, including without limitation the rights
|
|
338
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
339
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
340
|
+
* furnished to do so, subject to the following conditions:
|
|
341
|
+
*
|
|
342
|
+
* The above copyright notice and this permission notice shall be included in
|
|
343
|
+
* all copies or substantial portions of the Software.
|
|
344
|
+
*
|
|
345
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
346
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
347
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
348
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
349
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
350
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
351
|
+
* SOFTWARE.
|
|
352
|
+
*/
|
|
353
|
+
static const uint8_t pm_utf_8_dfa[] = {
|
|
354
|
+
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, // 00..1f
|
|
355
|
+
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, // 20..3f
|
|
356
|
+
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, // 40..5f
|
|
357
|
+
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, // 60..7f
|
|
358
|
+
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9, // 80..9f
|
|
359
|
+
7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, // a0..bf
|
|
360
|
+
8,8,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2, // c0..df
|
|
361
|
+
0xa,0x3,0x3,0x3,0x3,0x3,0x3,0x3,0x3,0x3,0x3,0x3,0x3,0x4,0x3,0x3, // e0..ef
|
|
362
|
+
0xb,0x6,0x6,0x6,0x5,0x8,0x8,0x8,0x8,0x8,0x8,0x8,0x8,0x8,0x8,0x8, // f0..ff
|
|
363
|
+
0x0,0x1,0x2,0x3,0x5,0x8,0x7,0x1,0x1,0x1,0x4,0x6,0x1,0x1,0x1,0x1, // s0..s0
|
|
364
|
+
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,1,1,1,1,1,0,1,0,1,1,1,1,1,1, // s1..s2
|
|
365
|
+
1,2,1,1,1,1,1,2,1,2,1,1,1,1,1,1,1,1,1,1,1,1,1,2,1,1,1,1,1,1,1,1, // s3..s4
|
|
366
|
+
1,2,1,1,1,1,1,1,1,2,1,1,1,1,1,1,1,1,1,1,1,1,1,3,1,3,1,1,1,1,1,1, // s5..s6
|
|
367
|
+
1,3,1,1,1,1,1,3,1,3,1,1,1,1,1,1,1,3,1,1,1,1,1,1,1,1,1,1,1,1,1,1, // s7..s8
|
|
368
|
+
};
|
|
369
|
+
|
|
370
|
+
/**
|
|
371
|
+
* Given a pointer to a string and the number of bytes remaining in the string,
|
|
372
|
+
* decode the next UTF-8 codepoint and return it. The number of bytes consumed
|
|
373
|
+
* is returned in the width out parameter.
|
|
374
|
+
*/
|
|
375
|
+
static pm_unicode_codepoint_t
|
|
376
|
+
pm_utf_8_codepoint(const uint8_t *b, ptrdiff_t n, size_t *width) {
|
|
377
|
+
PRISM_ASSERT(n >= 0);
|
|
378
|
+
|
|
379
|
+
size_t maximum = (n > 4) ? 4 : ((size_t) n);
|
|
380
|
+
uint32_t codepoint;
|
|
381
|
+
uint32_t state = 0;
|
|
382
|
+
|
|
383
|
+
for (size_t index = 0; index < maximum; index++) {
|
|
384
|
+
uint32_t byte = b[index];
|
|
385
|
+
uint32_t type = pm_utf_8_dfa[byte];
|
|
386
|
+
|
|
387
|
+
codepoint = (state != 0) ?
|
|
388
|
+
(byte & 0x3fu) | (codepoint << 6) :
|
|
389
|
+
(0xffu >> type) & (byte);
|
|
390
|
+
|
|
391
|
+
state = pm_utf_8_dfa[256 + (state * 16) + type];
|
|
392
|
+
if (state == 0) {
|
|
393
|
+
*width = index + 1;
|
|
394
|
+
return (pm_unicode_codepoint_t) codepoint;
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
*width = 0;
|
|
399
|
+
return 0;
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
/**
|
|
403
|
+
* Return the size of the next character in the UTF-8 encoding.
|
|
404
|
+
*/
|
|
405
|
+
size_t
|
|
406
|
+
pm_encoding_utf_8_char_width(const uint8_t *b, ptrdiff_t n) {
|
|
407
|
+
PRISM_ASSERT(n >= 0);
|
|
408
|
+
|
|
409
|
+
size_t maximum = (n > 4) ? 4 : ((size_t) n);
|
|
410
|
+
uint32_t state = 0;
|
|
411
|
+
|
|
412
|
+
for (size_t index = 0; index < maximum; index++) {
|
|
413
|
+
state = pm_utf_8_dfa[256 + (state * 16) + pm_utf_8_dfa[b[index]]];
|
|
414
|
+
if (state == 0) return index + 1;
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
return 0;
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
/**
|
|
421
|
+
* Return true if the given bytes begin a character in the UTF-8 encoding that
|
|
422
|
+
* takes more bytes than there are. In the state transition table, state 0
|
|
423
|
+
* accepts a character and state 1 rejects one, and every other state waits for
|
|
424
|
+
* another byte.
|
|
425
|
+
*/
|
|
426
|
+
static bool
|
|
427
|
+
pm_encoding_utf_8_char_prefix_p(const uint8_t *b, ptrdiff_t n) {
|
|
428
|
+
if (n <= 0 || n >= 4) return false;
|
|
429
|
+
uint32_t state = 0;
|
|
430
|
+
|
|
431
|
+
for (ptrdiff_t index = 0; index < n; index++) {
|
|
432
|
+
state = pm_utf_8_dfa[256 + (state * 16) + pm_utf_8_dfa[b[index]]];
|
|
433
|
+
if (state <= 1) return false;
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
return true;
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
/**
|
|
440
|
+
* Return true if the next character in the UTF-8 encoding is uppercase, or
|
|
441
|
+
* titlecase, in the given version of Ruby.
|
|
442
|
+
*/
|
|
443
|
+
bool
|
|
444
|
+
pm_encoding_utf_8_isupper_char(const uint8_t *b, ptrdiff_t n, pm_options_version_t version) {
|
|
445
|
+
if (n == 0) {
|
|
446
|
+
return 0;
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
if (*b < 0x80) {
|
|
450
|
+
return pm_encoding_ascii_upper_p(*b);
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
size_t width;
|
|
454
|
+
pm_unicode_codepoint_t codepoint = pm_utf_8_codepoint(b, n, &width);
|
|
455
|
+
|
|
456
|
+
return pm_unicode_uppercase_p(codepoint, version);
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
#ifndef PRISM_ENCODING_EXCLUDE_FULL
|
|
460
|
+
|
|
461
|
+
/**
|
|
462
|
+
* Decode the code point of a character in the CESU-8 encoding that is the
|
|
463
|
+
* given number of bytes long.
|
|
464
|
+
*/
|
|
465
|
+
static pm_unicode_codepoint_t
|
|
466
|
+
pm_cesu_8_codepoint(const uint8_t *b, size_t width) {
|
|
467
|
+
switch (width) {
|
|
468
|
+
case 1:
|
|
469
|
+
return (pm_unicode_codepoint_t) b[0];
|
|
470
|
+
case 2:
|
|
471
|
+
/* 110xxxxx 10xxxxxx */
|
|
472
|
+
return (pm_unicode_codepoint_t) (((b[0] & 0x1F) << 6) | (b[1] & 0x3F));
|
|
473
|
+
case 3:
|
|
474
|
+
/* 1110xxxx 10xxxxxx 10xxxxxx */
|
|
475
|
+
return (pm_unicode_codepoint_t) (((b[0] & 0xF) << 12) | ((b[1] & 0x3F) << 6) | (b[2] & 0x3F));
|
|
476
|
+
default:
|
|
477
|
+
/* 11101101 1010xxxx 10xxxxxx 11101101 1011xxxx 10xxxxxx */
|
|
478
|
+
return (pm_unicode_codepoint_t) (0x10000 + (((b[1] & 0xF) << 16) | ((b[2] & 0x3F) << 10) | ((b[4] & 0xF) << 6) | (b[5] & 0x3F)));
|
|
479
|
+
}
|
|
480
|
+
}
|
|
481
|
+
|
|
482
|
+
#endif
|
|
483
|
+
|
|
484
|
+
/**
|
|
485
|
+
* Return the code point of a valid character, if the characters of the
|
|
486
|
+
* encoding are Unicode code points. Otherwise return -1.
|
|
487
|
+
*/
|
|
488
|
+
int32_t
|
|
489
|
+
pm_encoding_unicode_codepoint(const pm_encoding_t *encoding, const uint8_t *b, size_t width) {
|
|
490
|
+
switch (encoding->kind) {
|
|
491
|
+
case PM_ENCODING_KIND_UTF_8: {
|
|
492
|
+
size_t decoded;
|
|
493
|
+
return (int32_t) pm_utf_8_codepoint(b, (ptrdiff_t) width, &decoded);
|
|
494
|
+
}
|
|
495
|
+
#ifndef PRISM_ENCODING_EXCLUDE_FULL
|
|
496
|
+
case PM_ENCODING_KIND_CESU_8:
|
|
497
|
+
return (int32_t) pm_cesu_8_codepoint(b, width);
|
|
498
|
+
#endif
|
|
499
|
+
default:
|
|
500
|
+
return -1;
|
|
501
|
+
}
|
|
502
|
+
}
|
|
503
|
+
|
|
504
|
+
#undef UNICODE_CODEPOINTS_MAXIMUM
|
|
505
|
+
|
|
506
|
+
#ifndef PRISM_ENCODING_EXCLUDE_FULL
|
|
507
|
+
|
|
508
|
+
/**
|
|
509
|
+
* The bytes from 0x80 up that begin a constant name in ISO-8859-1.
|
|
510
|
+
* ISO-8859-9 has the same bytes, so it shares this bitmap.
|
|
511
|
+
*/
|
|
512
|
+
static const uint8_t pm_encoding_iso_8859_1_uppercase[16] = {
|
|
513
|
+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x80 */
|
|
514
|
+
0xFF, 0xFF, 0x7F, 0x7F, 0x00, 0x00, 0x00, 0x00, /* 0xC0 */
|
|
515
|
+
};
|
|
516
|
+
|
|
517
|
+
/**
|
|
518
|
+
* The bytes from 0x80 up that begin a constant name in ISO-8859-2.
|
|
519
|
+
*/
|
|
520
|
+
static const uint8_t pm_encoding_iso_8859_2_uppercase[16] = {
|
|
521
|
+
0x00, 0x00, 0x00, 0x00, 0x6A, 0xDE, 0x00, 0x00, /* 0x80 */
|
|
522
|
+
0xFF, 0xFF, 0x7F, 0x7F, 0x00, 0x00, 0x00, 0x00, /* 0xC0 */
|
|
523
|
+
};
|
|
524
|
+
|
|
525
|
+
/**
|
|
526
|
+
* The bytes from 0x80 up that begin a constant name in ISO-8859-3.
|
|
527
|
+
*/
|
|
528
|
+
static const uint8_t pm_encoding_iso_8859_3_uppercase[16] = {
|
|
529
|
+
0x00, 0x00, 0x00, 0x00, 0x42, 0x9E, 0x00, 0x00, /* 0x80 */
|
|
530
|
+
0xF7, 0xFF, 0x7E, 0x7F, 0x00, 0x00, 0x00, 0x00, /* 0xC0 */
|
|
531
|
+
};
|
|
532
|
+
|
|
533
|
+
/**
|
|
534
|
+
* The bytes from 0x80 up that begin a constant name in ISO-8859-4.
|
|
535
|
+
*/
|
|
536
|
+
static const uint8_t pm_encoding_iso_8859_4_uppercase[16] = {
|
|
537
|
+
0x00, 0x00, 0x00, 0x00, 0x6A, 0x5E, 0x00, 0x20, /* 0x80 */
|
|
538
|
+
0xFF, 0xFF, 0x7F, 0x7F, 0x00, 0x00, 0x00, 0x00, /* 0xC0 */
|
|
539
|
+
};
|
|
540
|
+
|
|
541
|
+
/**
|
|
542
|
+
* The bytes from 0x80 up that begin a constant name in ISO-8859-5.
|
|
543
|
+
*/
|
|
544
|
+
static const uint8_t pm_encoding_iso_8859_5_uppercase[16] = {
|
|
545
|
+
0x00, 0x00, 0x00, 0x00, 0xFE, 0xDF, 0xFF, 0xFF, /* 0x80 */
|
|
546
|
+
0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xC0 */
|
|
547
|
+
};
|
|
548
|
+
|
|
549
|
+
/**
|
|
550
|
+
* The bytes from 0x80 up that begin a constant name in ISO-8859-7.
|
|
551
|
+
*/
|
|
552
|
+
static const uint8_t pm_encoding_iso_8859_7_uppercase[16] = {
|
|
553
|
+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0xD7, /* 0x80 */
|
|
554
|
+
0xFE, 0xFF, 0xFB, 0x0F, 0x00, 0x00, 0x00, 0x00, /* 0xC0 */
|
|
555
|
+
};
|
|
556
|
+
|
|
557
|
+
/**
|
|
558
|
+
* The bytes from 0x80 up that begin a constant name in ISO-8859-10.
|
|
559
|
+
*/
|
|
560
|
+
static const uint8_t pm_encoding_iso_8859_10_uppercase[16] = {
|
|
561
|
+
0x00, 0x00, 0x00, 0x00, 0x7E, 0xDF, 0x00, 0x00, /* 0x80 */
|
|
562
|
+
0xFF, 0xFF, 0xFF, 0x7F, 0x00, 0x00, 0x00, 0x00, /* 0xC0 */
|
|
563
|
+
};
|
|
564
|
+
|
|
565
|
+
/**
|
|
566
|
+
* The bytes from 0x80 up that begin a constant name in ISO-8859-13.
|
|
567
|
+
* Windows-1257 has the same bytes, so it shares this bitmap.
|
|
568
|
+
*/
|
|
569
|
+
static const uint8_t pm_encoding_iso_8859_13_uppercase[16] = {
|
|
570
|
+
0x00, 0x00, 0x00, 0x00, 0x00, 0x85, 0x00, 0x00, /* 0x80 */
|
|
571
|
+
0xFF, 0xFF, 0x7F, 0x7F, 0x00, 0x00, 0x00, 0x00, /* 0xC0 */
|
|
572
|
+
};
|
|
573
|
+
|
|
574
|
+
/**
|
|
575
|
+
* The bytes from 0x80 up that begin a constant name in ISO-8859-14.
|
|
576
|
+
*/
|
|
577
|
+
static const uint8_t pm_encoding_iso_8859_14_uppercase[16] = {
|
|
578
|
+
0x00, 0x00, 0x00, 0x00, 0x52, 0x95, 0x95, 0x28, /* 0x80 */
|
|
579
|
+
0xFF, 0xFF, 0xFF, 0x7F, 0x00, 0x00, 0x00, 0x00, /* 0xC0 */
|
|
580
|
+
};
|
|
581
|
+
|
|
582
|
+
/**
|
|
583
|
+
* The bytes from 0x80 up that begin a constant name in ISO-8859-15.
|
|
584
|
+
*/
|
|
585
|
+
static const uint8_t pm_encoding_iso_8859_15_uppercase[16] = {
|
|
586
|
+
0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x10, 0x50, /* 0x80 */
|
|
587
|
+
0xFF, 0xFF, 0x7F, 0x7F, 0x00, 0x00, 0x00, 0x00, /* 0xC0 */
|
|
588
|
+
};
|
|
589
|
+
|
|
590
|
+
/**
|
|
591
|
+
* The bytes from 0x80 up that begin a constant name in ISO-8859-16.
|
|
592
|
+
*/
|
|
593
|
+
static const uint8_t pm_encoding_iso_8859_16_uppercase[16] = {
|
|
594
|
+
0x00, 0x00, 0x00, 0x00, 0x5A, 0x94, 0x14, 0x50, /* 0x80 */
|
|
595
|
+
0xFF, 0xFF, 0xFF, 0x7F, 0x00, 0x00, 0x00, 0x00, /* 0xC0 */
|
|
596
|
+
};
|
|
597
|
+
|
|
598
|
+
/**
|
|
599
|
+
* The bytes from 0x80 up that begin a constant name in KOI8-R.
|
|
600
|
+
*/
|
|
601
|
+
static const uint8_t pm_encoding_koi8_r_uppercase[16] = {
|
|
602
|
+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, /* 0x80 */
|
|
603
|
+
0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, /* 0xC0 */
|
|
604
|
+
};
|
|
605
|
+
|
|
606
|
+
/**
|
|
607
|
+
* The bytes from 0x80 up that begin a constant name in KOI8-U.
|
|
608
|
+
*/
|
|
609
|
+
static const uint8_t pm_encoding_koi8_u_uppercase[16] = {
|
|
610
|
+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xD8, 0x20, /* 0x80 */
|
|
611
|
+
0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, /* 0xC0 */
|
|
612
|
+
};
|
|
613
|
+
|
|
614
|
+
/**
|
|
615
|
+
* The bytes from 0x80 up that begin a constant name in Windows-1250.
|
|
616
|
+
*/
|
|
617
|
+
static const uint8_t pm_encoding_windows_1250_uppercase[16] = {
|
|
618
|
+
0x00, 0xF4, 0x00, 0x00, 0x28, 0x84, 0x00, 0x10, /* 0x80 */
|
|
619
|
+
0xFF, 0xFF, 0xFF, 0x7F, 0x00, 0x00, 0x00, 0x00, /* 0xC0 */
|
|
620
|
+
};
|
|
621
|
+
|
|
622
|
+
/**
|
|
623
|
+
* The bytes from 0x80 up that begin a constant name in Windows-1251.
|
|
624
|
+
*/
|
|
625
|
+
static const uint8_t pm_encoding_windows_1251_uppercase[16] = {
|
|
626
|
+
0x03, 0xF4, 0x00, 0x00, 0x2A, 0x85, 0x04, 0x20, /* 0x80 */
|
|
627
|
+
0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, /* 0xC0 */
|
|
628
|
+
};
|
|
629
|
+
|
|
630
|
+
/**
|
|
631
|
+
* The bytes from 0x80 up that begin a constant name in Windows-1252.
|
|
632
|
+
*/
|
|
633
|
+
static const uint8_t pm_encoding_windows_1252_uppercase[16] = {
|
|
634
|
+
0x00, 0x54, 0x00, 0x80, 0x00, 0x80, 0x00, 0x00, /* 0x80 */
|
|
635
|
+
0xFF, 0xFF, 0xFF, 0x7F, 0x00, 0x00, 0x00, 0x00, /* 0xC0 */
|
|
636
|
+
};
|
|
637
|
+
|
|
638
|
+
/**
|
|
639
|
+
* The bytes from 0x80 up that begin a constant name in Windows-1253.
|
|
640
|
+
*/
|
|
641
|
+
static const uint8_t pm_encoding_windows_1253_uppercase[16] = {
|
|
642
|
+
0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x40, 0xD7, /* 0x80 */
|
|
643
|
+
0xFE, 0xFF, 0xFB, 0x0F, 0x00, 0x00, 0x00, 0x00, /* 0xC0 */
|
|
644
|
+
};
|
|
645
|
+
|
|
646
|
+
/**
|
|
647
|
+
* The bytes from 0x80 up that begin a constant name in Windows-1254.
|
|
648
|
+
*/
|
|
649
|
+
static const uint8_t pm_encoding_windows_1254_uppercase[16] = {
|
|
650
|
+
0x00, 0x14, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, /* 0x80 */
|
|
651
|
+
0xFF, 0xFF, 0x7F, 0x7F, 0x00, 0x00, 0x00, 0x00, /* 0xC0 */
|
|
652
|
+
};
|
|
653
|
+
|
|
654
|
+
#endif
|
|
655
|
+
|
|
656
|
+
/*
|
|
657
|
+
* Each multibyte encoding other than UTF-8 is ASCII below 0x80, and its other
|
|
658
|
+
* characters take a list of forms. A form is the number of bytes in its
|
|
659
|
+
* characters, their PRISM_ENCODING_*_BIT properties, and the inclusive range of
|
|
660
|
+
* bytes at each position. Bytes that match a form are a character. Forms may
|
|
661
|
+
* overlap, in which case a character has the properties of every form that it
|
|
662
|
+
* matches. No character is the start of a longer one, and every form with
|
|
663
|
+
* properties lies within the forms without them, so that the first form that
|
|
664
|
+
* answers a question about a character answers it for all of them.
|
|
665
|
+
*
|
|
666
|
+
* Each list is a macro that passes its forms to X_1 through X_6 by the number
|
|
667
|
+
* of bytes in them, where X is the name of a family of macros below that turns
|
|
668
|
+
* each form into a check. The checks run in the order of the list.
|
|
669
|
+
*/
|
|
670
|
+
|
|
671
|
+
/**
|
|
672
|
+
* Return true if the given byte is in the given inclusive range. The distance
|
|
673
|
+
* from the start of the range is compared as a byte so that a range that ends
|
|
674
|
+
* at 0xFF does not compare a byte against a bound that it can never exceed.
|
|
675
|
+
*/
|
|
676
|
+
#define PM_ENCODING_BYTE_IN(byte_, start_, end_) \
|
|
677
|
+
((uint8_t) ((byte_) - (start_)) <= (uint8_t) ((end_) - (start_)))
|
|
678
|
+
|
|
679
|
+
/* Return the width of the character at b if it takes the given form. */
|
|
680
|
+
#define PM_ENCODING_WIDTH_1(properties_, s0_, e0_) \
|
|
681
|
+
if (n >= 1 && PM_ENCODING_BYTE_IN(b[0], s0_, e0_)) return 1;
|
|
682
|
+
#define PM_ENCODING_WIDTH_2(properties_, s0_, e0_, s1_, e1_) \
|
|
683
|
+
if (n >= 2 && PM_ENCODING_BYTE_IN(b[0], s0_, e0_) && PM_ENCODING_BYTE_IN(b[1], s1_, e1_)) return 2;
|
|
684
|
+
#define PM_ENCODING_WIDTH_3(properties_, s0_, e0_, s1_, e1_, s2_, e2_) \
|
|
685
|
+
if (n >= 3 && PM_ENCODING_BYTE_IN(b[0], s0_, e0_) && PM_ENCODING_BYTE_IN(b[1], s1_, e1_) && PM_ENCODING_BYTE_IN(b[2], s2_, e2_)) return 3;
|
|
686
|
+
#define PM_ENCODING_WIDTH_4(properties_, s0_, e0_, s1_, e1_, s2_, e2_, s3_, e3_) \
|
|
687
|
+
if (n >= 4 && PM_ENCODING_BYTE_IN(b[0], s0_, e0_) && PM_ENCODING_BYTE_IN(b[1], s1_, e1_) && PM_ENCODING_BYTE_IN(b[2], s2_, e2_) && PM_ENCODING_BYTE_IN(b[3], s3_, e3_)) return 4;
|
|
688
|
+
#define PM_ENCODING_WIDTH_6(properties_, s0_, e0_, s1_, e1_, s2_, e2_, s3_, e3_, s4_, e4_, s5_, e5_) \
|
|
689
|
+
if (n >= 6 && PM_ENCODING_BYTE_IN(b[0], s0_, e0_) && PM_ENCODING_BYTE_IN(b[1], s1_, e1_) && PM_ENCODING_BYTE_IN(b[2], s2_, e2_) && PM_ENCODING_BYTE_IN(b[3], s3_, e3_) && PM_ENCODING_BYTE_IN(b[4], s4_, e4_) && PM_ENCODING_BYTE_IN(b[5], s5_, e5_)) return 6;
|
|
690
|
+
|
|
691
|
+
/*
|
|
692
|
+
* Return true if the character at b takes the given form and the form is
|
|
693
|
+
* uppercase. Forms that are not uppercase never answer, so their checks fold
|
|
694
|
+
* away.
|
|
695
|
+
*/
|
|
696
|
+
#define PM_ENCODING_UPPERCASE_1(properties_, s0_, e0_) \
|
|
697
|
+
if (((properties_) & PRISM_ENCODING_UPPERCASE_BIT) && n >= 1 && PM_ENCODING_BYTE_IN(b[0], s0_, e0_)) return true;
|
|
698
|
+
#define PM_ENCODING_UPPERCASE_2(properties_, s0_, e0_, s1_, e1_) \
|
|
699
|
+
if (((properties_) & PRISM_ENCODING_UPPERCASE_BIT) && n >= 2 && PM_ENCODING_BYTE_IN(b[0], s0_, e0_) && PM_ENCODING_BYTE_IN(b[1], s1_, e1_)) return true;
|
|
700
|
+
#define PM_ENCODING_UPPERCASE_3(properties_, s0_, e0_, s1_, e1_, s2_, e2_) \
|
|
701
|
+
if (((properties_) & PRISM_ENCODING_UPPERCASE_BIT) && n >= 3 && PM_ENCODING_BYTE_IN(b[0], s0_, e0_) && PM_ENCODING_BYTE_IN(b[1], s1_, e1_) && PM_ENCODING_BYTE_IN(b[2], s2_, e2_)) return true;
|
|
702
|
+
#define PM_ENCODING_UPPERCASE_4(properties_, s0_, e0_, s1_, e1_, s2_, e2_, s3_, e3_) \
|
|
703
|
+
if (((properties_) & PRISM_ENCODING_UPPERCASE_BIT) && n >= 4 && PM_ENCODING_BYTE_IN(b[0], s0_, e0_) && PM_ENCODING_BYTE_IN(b[1], s1_, e1_) && PM_ENCODING_BYTE_IN(b[2], s2_, e2_) && PM_ENCODING_BYTE_IN(b[3], s3_, e3_)) return true;
|
|
704
|
+
|
|
705
|
+
/*
|
|
706
|
+
* Return true if the n bytes at b, of which there is at least one, begin the
|
|
707
|
+
* given form without completing it. A form of a single byte is never begun
|
|
708
|
+
* without being completed.
|
|
709
|
+
*/
|
|
710
|
+
#define PM_ENCODING_PREFIX_1(properties_, s0_, e0_)
|
|
711
|
+
#define PM_ENCODING_PREFIX_2(properties_, s0_, e0_, s1_, e1_) \
|
|
712
|
+
if (n < 2 && PM_ENCODING_BYTE_IN(b[0], s0_, e0_)) return true;
|
|
713
|
+
#define PM_ENCODING_PREFIX_3(properties_, s0_, e0_, s1_, e1_, s2_, e2_) \
|
|
714
|
+
if (n < 3 && PM_ENCODING_BYTE_IN(b[0], s0_, e0_) && (n < 2 || PM_ENCODING_BYTE_IN(b[1], s1_, e1_))) return true;
|
|
715
|
+
#define PM_ENCODING_PREFIX_4(properties_, s0_, e0_, s1_, e1_, s2_, e2_, s3_, e3_) \
|
|
716
|
+
if (n < 4 && PM_ENCODING_BYTE_IN(b[0], s0_, e0_) && (n < 2 || PM_ENCODING_BYTE_IN(b[1], s1_, e1_)) && (n < 3 || PM_ENCODING_BYTE_IN(b[2], s2_, e2_))) return true;
|
|
717
|
+
#define PM_ENCODING_PREFIX_6(properties_, s0_, e0_, s1_, e1_, s2_, e2_, s3_, e3_, s4_, e4_, s5_, e5_) \
|
|
718
|
+
if (n < 6 && PM_ENCODING_BYTE_IN(b[0], s0_, e0_) && (n < 2 || PM_ENCODING_BYTE_IN(b[1], s1_, e1_)) && (n < 3 || PM_ENCODING_BYTE_IN(b[2], s2_, e2_)) && (n < 4 || PM_ENCODING_BYTE_IN(b[3], s3_, e3_)) && (n < 5 || PM_ENCODING_BYTE_IN(b[4], s4_, e4_))) return true;
|
|
719
|
+
|
|
720
|
+
/*
|
|
721
|
+
* The body of the function that returns the width of the character at b in an
|
|
722
|
+
* encoding whose characters beyond ASCII take the given forms, or 0 if the
|
|
723
|
+
* bytes do not form one.
|
|
724
|
+
*/
|
|
725
|
+
#define PM_ENCODING_FORMS_CHAR_WIDTH(forms_) \
|
|
726
|
+
if (n <= 0) return 0; \
|
|
727
|
+
if (b[0] < 0x80) return 1; \
|
|
728
|
+
forms_(PM_ENCODING_WIDTH) \
|
|
729
|
+
return 0;
|
|
730
|
+
|
|
731
|
+
/*
|
|
732
|
+
* The body of the function that returns true if the character at b begins a
|
|
733
|
+
* constant name in an encoding whose characters beyond ASCII take the given
|
|
734
|
+
* forms.
|
|
735
|
+
*/
|
|
736
|
+
#define PM_ENCODING_FORMS_ISUPPER_CHAR(forms_) \
|
|
737
|
+
if (n <= 0) return false; \
|
|
738
|
+
if (b[0] < 0x80) return pm_encoding_ascii_upper_p(b[0]); \
|
|
739
|
+
forms_(PM_ENCODING_UPPERCASE) \
|
|
740
|
+
return false;
|
|
741
|
+
|
|
742
|
+
/*
|
|
743
|
+
* The body of the function that returns true if the bytes at b begin a
|
|
744
|
+
* character in an encoding whose characters beyond ASCII take the given forms,
|
|
745
|
+
* without completing it. No character is the start of a longer one, so bytes
|
|
746
|
+
* that begin a form cannot also complete another.
|
|
747
|
+
*/
|
|
748
|
+
#define PM_ENCODING_FORMS_CHAR_PREFIX(forms_) \
|
|
749
|
+
if (n <= 0 || b[0] < 0x80) return false; \
|
|
750
|
+
forms_(PM_ENCODING_PREFIX) \
|
|
751
|
+
return false;
|
|
752
|
+
|
|
753
|
+
/**
|
|
754
|
+
* The forms of the characters in the EUC-JP encoding. The full-width Latin,
|
|
755
|
+
* Greek, and Cyrillic capital letters are uppercase.
|
|
756
|
+
*/
|
|
757
|
+
#define PM_ENCODING_EUC_JP_FORMS(X) \
|
|
758
|
+
X##_2(0, 0x8E, 0x8E, 0xA1, 0xFE) \
|
|
759
|
+
X##_2(0, 0xA1, 0xFE, 0xA1, 0xFE) \
|
|
760
|
+
X##_3(0, 0x8F, 0x8F, 0xA1, 0xFE, 0xA1, 0xFE) \
|
|
761
|
+
X##_2(PRISM_ENCODING_UPPERCASE_BIT, 0xA3, 0xA3, 0xC1, 0xDA) \
|
|
762
|
+
X##_2(PRISM_ENCODING_UPPERCASE_BIT, 0xA6, 0xA6, 0xA1, 0xB8) \
|
|
763
|
+
X##_2(PRISM_ENCODING_UPPERCASE_BIT, 0xA7, 0xA7, 0xA1, 0xC1)
|
|
764
|
+
|
|
765
|
+
/**
|
|
766
|
+
* Return the width of the character at b in EUC-JP, or 0 if there is none.
|
|
767
|
+
*/
|
|
768
|
+
static size_t
|
|
769
|
+
pm_encoding_euc_jp_char_width(const uint8_t *b, ptrdiff_t n) {
|
|
770
|
+
PM_ENCODING_FORMS_CHAR_WIDTH(PM_ENCODING_EUC_JP_FORMS)
|
|
771
|
+
}
|
|
772
|
+
|
|
773
|
+
/**
|
|
774
|
+
* Return true if the character at b begins a constant name in EUC-JP.
|
|
775
|
+
*/
|
|
776
|
+
static bool
|
|
777
|
+
pm_encoding_euc_jp_isupper_char(const uint8_t *b, ptrdiff_t n) {
|
|
778
|
+
PM_ENCODING_FORMS_ISUPPER_CHAR(PM_ENCODING_EUC_JP_FORMS)
|
|
779
|
+
}
|
|
780
|
+
|
|
781
|
+
/**
|
|
782
|
+
* The forms of the characters in the Shift_JIS encoding, where the single
|
|
783
|
+
* bytes from 0xA1 to 0xDF are half-width katakana. The full-width Latin, Greek,
|
|
784
|
+
* and Cyrillic capital letters are uppercase.
|
|
785
|
+
*/
|
|
786
|
+
#define PM_ENCODING_SHIFT_JIS_FORMS(X) \
|
|
787
|
+
X##_1(0, 0xA1, 0xDF) \
|
|
788
|
+
X##_2(0, 0x81, 0x9F, 0x40, 0x7E) \
|
|
789
|
+
X##_2(0, 0x81, 0x9F, 0x80, 0xFC) \
|
|
790
|
+
X##_2(0, 0xE0, 0xFC, 0x40, 0x7E) \
|
|
791
|
+
X##_2(0, 0xE0, 0xFC, 0x80, 0xFC) \
|
|
792
|
+
X##_2(PRISM_ENCODING_UPPERCASE_BIT, 0x82, 0x82, 0x60, 0x79) \
|
|
793
|
+
X##_2(PRISM_ENCODING_UPPERCASE_BIT, 0x83, 0x83, 0x9F, 0xB6) \
|
|
794
|
+
X##_2(PRISM_ENCODING_UPPERCASE_BIT, 0x84, 0x84, 0x40, 0x60)
|
|
795
|
+
|
|
796
|
+
/**
|
|
797
|
+
* Return the width of the character at b in Shift_JIS, or 0 if there is none.
|
|
798
|
+
*/
|
|
799
|
+
static size_t
|
|
800
|
+
pm_encoding_shift_jis_char_width(const uint8_t *b, ptrdiff_t n) {
|
|
801
|
+
PM_ENCODING_FORMS_CHAR_WIDTH(PM_ENCODING_SHIFT_JIS_FORMS)
|
|
802
|
+
}
|
|
803
|
+
|
|
804
|
+
/**
|
|
805
|
+
* Return true if the character at b begins a constant name in Shift_JIS.
|
|
806
|
+
*/
|
|
807
|
+
static bool
|
|
808
|
+
pm_encoding_shift_jis_isupper_char(const uint8_t *b, ptrdiff_t n) {
|
|
809
|
+
PM_ENCODING_FORMS_ISUPPER_CHAR(PM_ENCODING_SHIFT_JIS_FORMS)
|
|
810
|
+
}
|
|
811
|
+
|
|
812
|
+
#ifndef PRISM_ENCODING_EXCLUDE_FULL
|
|
813
|
+
|
|
814
|
+
/**
|
|
815
|
+
* The forms of the characters in the Big5 encoding. Ruby reads Big5-HKSCS,
|
|
816
|
+
* Big5-UAO, CP950, and CP951 as Big5, so they take these forms as well.
|
|
817
|
+
*/
|
|
818
|
+
#define PM_ENCODING_BIG5_FORMS(X) \
|
|
819
|
+
X##_2(0, 0xA1, 0xFE, 0x40, 0x7E) \
|
|
820
|
+
X##_2(0, 0xA1, 0xFE, 0xA1, 0xFE)
|
|
821
|
+
|
|
822
|
+
/**
|
|
823
|
+
* Return the width of the character at b in Big5, or 0 if there is none.
|
|
824
|
+
*/
|
|
825
|
+
static size_t
|
|
826
|
+
pm_encoding_big5_char_width(const uint8_t *b, ptrdiff_t n) {
|
|
827
|
+
PM_ENCODING_FORMS_CHAR_WIDTH(PM_ENCODING_BIG5_FORMS)
|
|
828
|
+
}
|
|
829
|
+
|
|
830
|
+
/**
|
|
831
|
+
* The forms of the characters in the CESU-8 encoding: those of UTF-8, except
|
|
832
|
+
* that a character beyond U+FFFF is a pair of surrogates. Its characters have
|
|
833
|
+
* the properties of their code points instead of properties of their forms.
|
|
834
|
+
*/
|
|
835
|
+
#define PM_ENCODING_CESU_8_FORMS(X) \
|
|
836
|
+
X##_2(0, 0xC2, 0xDF, 0x80, 0xBF) \
|
|
837
|
+
X##_3(0, 0xE0, 0xE0, 0xA0, 0xBF, 0x80, 0xBF) \
|
|
838
|
+
X##_3(0, 0xE1, 0xEC, 0x80, 0xBF, 0x80, 0xBF) \
|
|
839
|
+
X##_3(0, 0xED, 0xED, 0x80, 0x9F, 0x80, 0xBF) \
|
|
840
|
+
X##_3(0, 0xEE, 0xEF, 0x80, 0xBF, 0x80, 0xBF) \
|
|
841
|
+
X##_6(0, 0xED, 0xED, 0xA0, 0xAF, 0x80, 0xBF, 0xED, 0xED, 0xB0, 0xBF, 0x80, 0xBF)
|
|
842
|
+
|
|
843
|
+
/**
|
|
844
|
+
* Return the width of the character at b in CESU-8, or 0 if there is none.
|
|
845
|
+
*/
|
|
846
|
+
static size_t
|
|
847
|
+
pm_encoding_cesu_8_char_width(const uint8_t *b, ptrdiff_t n) {
|
|
848
|
+
PM_ENCODING_FORMS_CHAR_WIDTH(PM_ENCODING_CESU_8_FORMS)
|
|
849
|
+
}
|
|
850
|
+
|
|
851
|
+
/**
|
|
852
|
+
* The forms of the characters in the CP949 encoding, where 0x80 is a character
|
|
853
|
+
* of its own.
|
|
854
|
+
*/
|
|
855
|
+
#define PM_ENCODING_CP949_FORMS(X) \
|
|
856
|
+
X##_1(0, 0x80, 0x80) \
|
|
857
|
+
X##_2(0, 0x81, 0xFE, 0x41, 0x5A) \
|
|
858
|
+
X##_2(0, 0x81, 0xFE, 0x61, 0x7A) \
|
|
859
|
+
X##_2(0, 0x81, 0xFE, 0x81, 0xFE)
|
|
860
|
+
|
|
861
|
+
/**
|
|
862
|
+
* Return the width of the character at b in CP949, or 0 if there is none.
|
|
863
|
+
*/
|
|
864
|
+
static size_t
|
|
865
|
+
pm_encoding_cp949_char_width(const uint8_t *b, ptrdiff_t n) {
|
|
866
|
+
PM_ENCODING_FORMS_CHAR_WIDTH(PM_ENCODING_CP949_FORMS)
|
|
867
|
+
}
|
|
868
|
+
|
|
869
|
+
/**
|
|
870
|
+
* The forms of the characters in the Emacs-Mule encoding.
|
|
871
|
+
*/
|
|
872
|
+
#define PM_ENCODING_EMACS_MULE_FORMS(X) \
|
|
873
|
+
X##_2(0, 0x81, 0x8F, 0xA0, 0xFF) \
|
|
874
|
+
X##_3(0, 0x90, 0x99, 0xA0, 0xFF, 0xA0, 0xFF) \
|
|
875
|
+
X##_3(0, 0x9A, 0x9B, 0xE0, 0xEF, 0xA0, 0xFF) \
|
|
876
|
+
X##_4(0, 0x9C, 0x9C, 0xF0, 0xF4, 0xA0, 0xFF, 0xA0, 0xFF) \
|
|
877
|
+
X##_4(0, 0x9D, 0x9D, 0xF5, 0xFE, 0xA0, 0xFF, 0xA0, 0xFF)
|
|
878
|
+
|
|
879
|
+
/**
|
|
880
|
+
* Return the width of the character at b in Emacs-Mule, or 0 if there is none.
|
|
881
|
+
*/
|
|
882
|
+
static size_t
|
|
883
|
+
pm_encoding_emacs_mule_char_width(const uint8_t *b, ptrdiff_t n) {
|
|
884
|
+
PM_ENCODING_FORMS_CHAR_WIDTH(PM_ENCODING_EMACS_MULE_FORMS)
|
|
885
|
+
}
|
|
886
|
+
|
|
887
|
+
/**
|
|
888
|
+
* The forms of the characters in the EUC-KR encoding.
|
|
889
|
+
*/
|
|
890
|
+
#define PM_ENCODING_EUC_KR_FORMS(X) \
|
|
891
|
+
X##_2(0, 0xA1, 0xFE, 0xA1, 0xFE)
|
|
892
|
+
|
|
893
|
+
/**
|
|
894
|
+
* Return the width of the character at b in EUC-KR, or 0 if there is none.
|
|
895
|
+
*/
|
|
896
|
+
static size_t
|
|
897
|
+
pm_encoding_euc_kr_char_width(const uint8_t *b, ptrdiff_t n) {
|
|
898
|
+
PM_ENCODING_FORMS_CHAR_WIDTH(PM_ENCODING_EUC_KR_FORMS)
|
|
899
|
+
}
|
|
900
|
+
|
|
901
|
+
/**
|
|
902
|
+
* The forms of the characters in the EUC-TW encoding.
|
|
903
|
+
*/
|
|
904
|
+
#define PM_ENCODING_EUC_TW_FORMS(X) \
|
|
905
|
+
X##_2(0, 0xA1, 0xFE, 0xA1, 0xFE) \
|
|
906
|
+
X##_4(0, 0x8E, 0x8E, 0xA1, 0xB0, 0xA1, 0xFE, 0xA1, 0xFE)
|
|
907
|
+
|
|
908
|
+
/**
|
|
909
|
+
* Return the width of the character at b in EUC-TW, or 0 if there is none.
|
|
910
|
+
*/
|
|
911
|
+
static size_t
|
|
912
|
+
pm_encoding_euc_tw_char_width(const uint8_t *b, ptrdiff_t n) {
|
|
913
|
+
PM_ENCODING_FORMS_CHAR_WIDTH(PM_ENCODING_EUC_TW_FORMS)
|
|
914
|
+
}
|
|
915
|
+
|
|
916
|
+
/**
|
|
917
|
+
* The forms of the characters in the GB18030 encoding.
|
|
918
|
+
*/
|
|
919
|
+
#define PM_ENCODING_GB18030_FORMS(X) \
|
|
920
|
+
X##_2(0, 0x81, 0xFE, 0x40, 0x7E) \
|
|
921
|
+
X##_2(0, 0x81, 0xFE, 0x80, 0xFE) \
|
|
922
|
+
X##_4(0, 0x81, 0xFE, 0x30, 0x39, 0x81, 0xFE, 0x30, 0x39)
|
|
923
|
+
|
|
924
|
+
/**
|
|
925
|
+
* Return the width of the character at b in GB18030, or 0 if there is none.
|
|
926
|
+
*/
|
|
927
|
+
static size_t
|
|
928
|
+
pm_encoding_gb18030_char_width(const uint8_t *b, ptrdiff_t n) {
|
|
929
|
+
PM_ENCODING_FORMS_CHAR_WIDTH(PM_ENCODING_GB18030_FORMS)
|
|
930
|
+
}
|
|
931
|
+
|
|
932
|
+
/**
|
|
933
|
+
* The forms of the characters in the GBK encoding, where 0x80 is a character
|
|
934
|
+
* of its own.
|
|
935
|
+
*/
|
|
936
|
+
#define PM_ENCODING_GBK_FORMS(X) \
|
|
937
|
+
X##_1(0, 0x80, 0x80) \
|
|
938
|
+
X##_2(0, 0xA1, 0xA9, 0xA1, 0xFE) /* GBK/1 */ \
|
|
939
|
+
X##_2(0, 0xB0, 0xF7, 0xA1, 0xFE) /* GBK/2 */ \
|
|
940
|
+
X##_2(0, 0x81, 0xA0, 0x40, 0x7E) /* GBK/3 */ \
|
|
941
|
+
X##_2(0, 0x81, 0xA0, 0x80, 0xFE) /* GBK/3 */ \
|
|
942
|
+
X##_2(0, 0xAA, 0xFE, 0x40, 0x7E) /* GBK/4 */ \
|
|
943
|
+
X##_2(0, 0xAA, 0xFE, 0x80, 0xA0) /* GBK/4 */ \
|
|
944
|
+
X##_2(0, 0xA8, 0xA9, 0x40, 0x7E) /* GBK/5 */ \
|
|
945
|
+
X##_2(0, 0xA8, 0xA9, 0x80, 0xA0) /* GBK/5 */ \
|
|
946
|
+
X##_2(0, 0xAA, 0xAF, 0xA1, 0xFE) /* user-defined 1 */ \
|
|
947
|
+
X##_2(0, 0xF8, 0xFE, 0xA1, 0xFE) /* user-defined 2 */ \
|
|
948
|
+
X##_2(0, 0xA1, 0xA7, 0x40, 0x7E) /* user-defined 3 */ \
|
|
949
|
+
X##_2(0, 0xA1, 0xA7, 0x80, 0xA0) /* user-defined 3 */
|
|
950
|
+
|
|
951
|
+
/**
|
|
952
|
+
* Return the width of the character at b in GBK, or 0 if there is none.
|
|
953
|
+
*/
|
|
954
|
+
static size_t
|
|
955
|
+
pm_encoding_gbk_char_width(const uint8_t *b, ptrdiff_t n) {
|
|
956
|
+
PM_ENCODING_FORMS_CHAR_WIDTH(PM_ENCODING_GBK_FORMS)
|
|
957
|
+
}
|
|
958
|
+
|
|
959
|
+
#endif
|
|
960
|
+
|
|
961
|
+
/**
|
|
962
|
+
* Return the number of bytes in the next character in the given encoding, or 0
|
|
963
|
+
* if the bytes do not form one.
|
|
964
|
+
*/
|
|
965
|
+
size_t
|
|
966
|
+
pm_encoding_char_width(const pm_encoding_t *encoding, const uint8_t *b, ptrdiff_t n) {
|
|
967
|
+
switch (encoding->kind) {
|
|
968
|
+
case PM_ENCODING_KIND_UTF_8:
|
|
969
|
+
return pm_encoding_utf_8_char_width(b, n);
|
|
970
|
+
case PM_ENCODING_KIND_ASCII:
|
|
971
|
+
return ((n > 0) && (*b < 0x80)) ? 1 : 0;
|
|
972
|
+
case PM_ENCODING_KIND_SINGLE_BYTE:
|
|
973
|
+
return n > 0 ? 1 : 0;
|
|
974
|
+
case PM_ENCODING_KIND_EUC_JP:
|
|
975
|
+
return pm_encoding_euc_jp_char_width(b, n);
|
|
976
|
+
case PM_ENCODING_KIND_SHIFT_JIS:
|
|
977
|
+
return pm_encoding_shift_jis_char_width(b, n);
|
|
978
|
+
#ifndef PRISM_ENCODING_EXCLUDE_FULL
|
|
979
|
+
case PM_ENCODING_KIND_BIG5:
|
|
980
|
+
return pm_encoding_big5_char_width(b, n);
|
|
981
|
+
case PM_ENCODING_KIND_CESU_8:
|
|
982
|
+
return pm_encoding_cesu_8_char_width(b, n);
|
|
983
|
+
case PM_ENCODING_KIND_CP949:
|
|
984
|
+
return pm_encoding_cp949_char_width(b, n);
|
|
985
|
+
case PM_ENCODING_KIND_EMACS_MULE:
|
|
986
|
+
return pm_encoding_emacs_mule_char_width(b, n);
|
|
987
|
+
case PM_ENCODING_KIND_EUC_KR:
|
|
988
|
+
return pm_encoding_euc_kr_char_width(b, n);
|
|
989
|
+
case PM_ENCODING_KIND_EUC_TW:
|
|
990
|
+
return pm_encoding_euc_tw_char_width(b, n);
|
|
991
|
+
case PM_ENCODING_KIND_GB18030:
|
|
992
|
+
return pm_encoding_gb18030_char_width(b, n);
|
|
993
|
+
case PM_ENCODING_KIND_GBK:
|
|
994
|
+
return pm_encoding_gbk_char_width(b, n);
|
|
995
|
+
#endif
|
|
996
|
+
default:
|
|
997
|
+
PRISM_ASSERT(false && "unreachable");
|
|
998
|
+
return 0;
|
|
999
|
+
}
|
|
1000
|
+
}
|
|
1001
|
+
|
|
1002
|
+
/**
|
|
1003
|
+
* Return true if the given bytes begin a character in the given encoding that
|
|
1004
|
+
* takes more bytes than there are.
|
|
1005
|
+
*/
|
|
1006
|
+
bool
|
|
1007
|
+
pm_encoding_char_prefix_p(const pm_encoding_t *encoding, const uint8_t *b, ptrdiff_t n) {
|
|
1008
|
+
switch (encoding->kind) {
|
|
1009
|
+
case PM_ENCODING_KIND_UTF_8:
|
|
1010
|
+
return pm_encoding_utf_8_char_prefix_p(b, n);
|
|
1011
|
+
case PM_ENCODING_KIND_ASCII:
|
|
1012
|
+
case PM_ENCODING_KIND_SINGLE_BYTE:
|
|
1013
|
+
return false;
|
|
1014
|
+
case PM_ENCODING_KIND_EUC_JP:
|
|
1015
|
+
PM_ENCODING_FORMS_CHAR_PREFIX(PM_ENCODING_EUC_JP_FORMS)
|
|
1016
|
+
case PM_ENCODING_KIND_SHIFT_JIS:
|
|
1017
|
+
PM_ENCODING_FORMS_CHAR_PREFIX(PM_ENCODING_SHIFT_JIS_FORMS)
|
|
1018
|
+
#ifndef PRISM_ENCODING_EXCLUDE_FULL
|
|
1019
|
+
case PM_ENCODING_KIND_BIG5:
|
|
1020
|
+
PM_ENCODING_FORMS_CHAR_PREFIX(PM_ENCODING_BIG5_FORMS)
|
|
1021
|
+
case PM_ENCODING_KIND_CESU_8:
|
|
1022
|
+
PM_ENCODING_FORMS_CHAR_PREFIX(PM_ENCODING_CESU_8_FORMS)
|
|
1023
|
+
case PM_ENCODING_KIND_CP949:
|
|
1024
|
+
PM_ENCODING_FORMS_CHAR_PREFIX(PM_ENCODING_CP949_FORMS)
|
|
1025
|
+
case PM_ENCODING_KIND_EMACS_MULE:
|
|
1026
|
+
PM_ENCODING_FORMS_CHAR_PREFIX(PM_ENCODING_EMACS_MULE_FORMS)
|
|
1027
|
+
case PM_ENCODING_KIND_EUC_KR:
|
|
1028
|
+
PM_ENCODING_FORMS_CHAR_PREFIX(PM_ENCODING_EUC_KR_FORMS)
|
|
1029
|
+
case PM_ENCODING_KIND_EUC_TW:
|
|
1030
|
+
PM_ENCODING_FORMS_CHAR_PREFIX(PM_ENCODING_EUC_TW_FORMS)
|
|
1031
|
+
case PM_ENCODING_KIND_GB18030:
|
|
1032
|
+
PM_ENCODING_FORMS_CHAR_PREFIX(PM_ENCODING_GB18030_FORMS)
|
|
1033
|
+
case PM_ENCODING_KIND_GBK:
|
|
1034
|
+
PM_ENCODING_FORMS_CHAR_PREFIX(PM_ENCODING_GBK_FORMS)
|
|
1035
|
+
#endif
|
|
1036
|
+
default:
|
|
1037
|
+
PRISM_ASSERT(false && "unreachable");
|
|
1038
|
+
return false;
|
|
1039
|
+
}
|
|
1040
|
+
}
|
|
1041
|
+
|
|
1042
|
+
/**
|
|
1043
|
+
* Return true if the next character in the given encoding is uppercase, or
|
|
1044
|
+
* titlecase, in the given version of Ruby. The answer depends on the version
|
|
1045
|
+
* only in an encoding whose characters are Unicode code points.
|
|
1046
|
+
*/
|
|
1047
|
+
bool
|
|
1048
|
+
pm_encoding_isupper_char(const pm_encoding_t *encoding, const uint8_t *b, ptrdiff_t n, pm_options_version_t version) {
|
|
1049
|
+
switch (encoding->kind) {
|
|
1050
|
+
case PM_ENCODING_KIND_ASCII:
|
|
1051
|
+
case PM_ENCODING_KIND_SINGLE_BYTE: {
|
|
1052
|
+
if (n <= 0) return false;
|
|
1053
|
+
if (*b < 0x80) return pm_encoding_ascii_upper_p(*b);
|
|
1054
|
+
|
|
1055
|
+
const uint8_t *uppercase = encoding->uppercase;
|
|
1056
|
+
return uppercase != NULL && ((uppercase[(*b - 0x80) >> 3] >> (*b & 7)) & 1);
|
|
1057
|
+
}
|
|
1058
|
+
case PM_ENCODING_KIND_UTF_8:
|
|
1059
|
+
return pm_encoding_utf_8_isupper_char(b, n, version);
|
|
1060
|
+
case PM_ENCODING_KIND_EUC_JP:
|
|
1061
|
+
return pm_encoding_euc_jp_isupper_char(b, n);
|
|
1062
|
+
case PM_ENCODING_KIND_SHIFT_JIS:
|
|
1063
|
+
return pm_encoding_shift_jis_isupper_char(b, n);
|
|
1064
|
+
#ifndef PRISM_ENCODING_EXCLUDE_FULL
|
|
1065
|
+
case PM_ENCODING_KIND_CESU_8: {
|
|
1066
|
+
size_t width = pm_encoding_cesu_8_char_width(b, n);
|
|
1067
|
+
return width != 0 && pm_unicode_uppercase_p(pm_cesu_8_codepoint(b, width), version);
|
|
1068
|
+
}
|
|
1069
|
+
/* These encodings have no uppercase letters beyond ASCII. */
|
|
1070
|
+
case PM_ENCODING_KIND_BIG5:
|
|
1071
|
+
case PM_ENCODING_KIND_CP949:
|
|
1072
|
+
case PM_ENCODING_KIND_EMACS_MULE:
|
|
1073
|
+
case PM_ENCODING_KIND_EUC_KR:
|
|
1074
|
+
case PM_ENCODING_KIND_EUC_TW:
|
|
1075
|
+
case PM_ENCODING_KIND_GB18030:
|
|
1076
|
+
case PM_ENCODING_KIND_GBK:
|
|
1077
|
+
return n > 0 && pm_encoding_ascii_upper_p(*b);
|
|
1078
|
+
#endif
|
|
1079
|
+
default:
|
|
1080
|
+
PRISM_ASSERT(false && "unreachable");
|
|
1081
|
+
return false;
|
|
1082
|
+
}
|
|
1083
|
+
}
|
|
1084
|
+
|
|
1085
|
+
#undef PM_ENCODING_FORMS_ISUPPER_CHAR
|
|
1086
|
+
#undef PM_ENCODING_FORMS_CHAR_WIDTH
|
|
1087
|
+
#undef PM_ENCODING_UPPERCASE_4
|
|
1088
|
+
#undef PM_ENCODING_UPPERCASE_3
|
|
1089
|
+
#undef PM_ENCODING_UPPERCASE_2
|
|
1090
|
+
#undef PM_ENCODING_UPPERCASE_1
|
|
1091
|
+
#undef PM_ENCODING_WIDTH_6
|
|
1092
|
+
#undef PM_ENCODING_WIDTH_4
|
|
1093
|
+
#undef PM_ENCODING_WIDTH_3
|
|
1094
|
+
#undef PM_ENCODING_WIDTH_2
|
|
1095
|
+
#undef PM_ENCODING_WIDTH_1
|
|
1096
|
+
#undef PM_ENCODING_BYTE_IN
|
|
1097
|
+
|
|
1098
|
+
/**
|
|
1099
|
+
* This is the table of all of the encodings that prism supports.
|
|
1100
|
+
*/
|
|
1101
|
+
const pm_encoding_t pm_encodings[] = {
|
|
1102
|
+
[PM_ENCODING_UTF_8] = {
|
|
1103
|
+
.name = "UTF-8",
|
|
1104
|
+
.kind = PM_ENCODING_KIND_UTF_8
|
|
1105
|
+
},
|
|
1106
|
+
[PM_ENCODING_US_ASCII] = {
|
|
1107
|
+
.name = "US-ASCII",
|
|
1108
|
+
.kind = PM_ENCODING_KIND_ASCII
|
|
1109
|
+
},
|
|
1110
|
+
[PM_ENCODING_ASCII_8BIT] = {
|
|
1111
|
+
.name = "ASCII-8BIT",
|
|
1112
|
+
.kind = PM_ENCODING_KIND_SINGLE_BYTE
|
|
1113
|
+
},
|
|
1114
|
+
[PM_ENCODING_EUC_JP] = {
|
|
1115
|
+
.name = "EUC-JP",
|
|
1116
|
+
.kind = PM_ENCODING_KIND_EUC_JP
|
|
1117
|
+
},
|
|
1118
|
+
[PM_ENCODING_WINDOWS_31J] = {
|
|
1119
|
+
.name = "Windows-31J",
|
|
1120
|
+
.kind = PM_ENCODING_KIND_SHIFT_JIS
|
|
1121
|
+
},
|
|
1122
|
+
|
|
1123
|
+
#ifndef PRISM_ENCODING_EXCLUDE_FULL
|
|
1124
|
+
[PM_ENCODING_BIG5] = {
|
|
1125
|
+
.name = "Big5",
|
|
1126
|
+
.kind = PM_ENCODING_KIND_BIG5
|
|
1127
|
+
},
|
|
1128
|
+
[PM_ENCODING_BIG5_HKSCS] = {
|
|
1129
|
+
.name = "Big5-HKSCS",
|
|
1130
|
+
.kind = PM_ENCODING_KIND_BIG5
|
|
1131
|
+
},
|
|
1132
|
+
[PM_ENCODING_BIG5_UAO] = {
|
|
1133
|
+
.name = "Big5-UAO",
|
|
1134
|
+
.kind = PM_ENCODING_KIND_BIG5
|
|
1135
|
+
},
|
|
1136
|
+
[PM_ENCODING_CESU_8] = {
|
|
1137
|
+
.name = "CESU-8",
|
|
1138
|
+
.kind = PM_ENCODING_KIND_CESU_8
|
|
1139
|
+
},
|
|
1140
|
+
[PM_ENCODING_CP51932] = {
|
|
1141
|
+
.name = "CP51932",
|
|
1142
|
+
.kind = PM_ENCODING_KIND_EUC_JP
|
|
1143
|
+
},
|
|
1144
|
+
[PM_ENCODING_CP850] = {
|
|
1145
|
+
.name = "CP850",
|
|
1146
|
+
.kind = PM_ENCODING_KIND_SINGLE_BYTE
|
|
1147
|
+
},
|
|
1148
|
+
[PM_ENCODING_CP852] = {
|
|
1149
|
+
.name = "CP852",
|
|
1150
|
+
.kind = PM_ENCODING_KIND_SINGLE_BYTE
|
|
1151
|
+
},
|
|
1152
|
+
[PM_ENCODING_CP855] = {
|
|
1153
|
+
.name = "CP855",
|
|
1154
|
+
.kind = PM_ENCODING_KIND_SINGLE_BYTE
|
|
1155
|
+
},
|
|
1156
|
+
[PM_ENCODING_CP949] = {
|
|
1157
|
+
.name = "CP949",
|
|
1158
|
+
.kind = PM_ENCODING_KIND_CP949
|
|
1159
|
+
},
|
|
1160
|
+
[PM_ENCODING_CP950] = {
|
|
1161
|
+
.name = "CP950",
|
|
1162
|
+
.kind = PM_ENCODING_KIND_BIG5
|
|
1163
|
+
},
|
|
1164
|
+
[PM_ENCODING_CP951] = {
|
|
1165
|
+
.name = "CP951",
|
|
1166
|
+
.kind = PM_ENCODING_KIND_BIG5
|
|
1167
|
+
},
|
|
1168
|
+
[PM_ENCODING_EMACS_MULE] = {
|
|
1169
|
+
.name = "Emacs-Mule",
|
|
1170
|
+
.kind = PM_ENCODING_KIND_EMACS_MULE
|
|
1171
|
+
},
|
|
1172
|
+
[PM_ENCODING_EUC_JP_MS] = {
|
|
1173
|
+
.name = "eucJP-ms",
|
|
1174
|
+
.kind = PM_ENCODING_KIND_EUC_JP
|
|
1175
|
+
},
|
|
1176
|
+
[PM_ENCODING_EUC_JIS_2004] = {
|
|
1177
|
+
.name = "EUC-JIS-2004",
|
|
1178
|
+
.kind = PM_ENCODING_KIND_EUC_JP
|
|
1179
|
+
},
|
|
1180
|
+
[PM_ENCODING_EUC_KR] = {
|
|
1181
|
+
.name = "EUC-KR",
|
|
1182
|
+
.kind = PM_ENCODING_KIND_EUC_KR
|
|
1183
|
+
},
|
|
1184
|
+
[PM_ENCODING_EUC_TW] = {
|
|
1185
|
+
.name = "EUC-TW",
|
|
1186
|
+
.kind = PM_ENCODING_KIND_EUC_TW
|
|
1187
|
+
},
|
|
1188
|
+
[PM_ENCODING_GB12345] = {
|
|
1189
|
+
.name = "GB12345",
|
|
1190
|
+
.kind = PM_ENCODING_KIND_EUC_KR
|
|
1191
|
+
},
|
|
1192
|
+
[PM_ENCODING_GB18030] = {
|
|
1193
|
+
.name = "GB18030",
|
|
1194
|
+
.kind = PM_ENCODING_KIND_GB18030
|
|
1195
|
+
},
|
|
1196
|
+
[PM_ENCODING_GB1988] = {
|
|
1197
|
+
.name = "GB1988",
|
|
1198
|
+
.kind = PM_ENCODING_KIND_SINGLE_BYTE
|
|
1199
|
+
},
|
|
1200
|
+
[PM_ENCODING_GB2312] = {
|
|
1201
|
+
.name = "GB2312",
|
|
1202
|
+
.kind = PM_ENCODING_KIND_EUC_KR
|
|
1203
|
+
},
|
|
1204
|
+
[PM_ENCODING_GBK] = {
|
|
1205
|
+
.name = "GBK",
|
|
1206
|
+
.kind = PM_ENCODING_KIND_GBK
|
|
1207
|
+
},
|
|
1208
|
+
[PM_ENCODING_IBM437] = {
|
|
1209
|
+
.name = "IBM437",
|
|
1210
|
+
.kind = PM_ENCODING_KIND_SINGLE_BYTE
|
|
1211
|
+
},
|
|
1212
|
+
[PM_ENCODING_IBM720] = {
|
|
1213
|
+
.name = "IBM720",
|
|
1214
|
+
.kind = PM_ENCODING_KIND_SINGLE_BYTE
|
|
1215
|
+
},
|
|
1216
|
+
[PM_ENCODING_IBM737] = {
|
|
1217
|
+
.name = "IBM737",
|
|
1218
|
+
.kind = PM_ENCODING_KIND_SINGLE_BYTE
|
|
1219
|
+
},
|
|
1220
|
+
[PM_ENCODING_IBM775] = {
|
|
1221
|
+
.name = "IBM775",
|
|
1222
|
+
.kind = PM_ENCODING_KIND_SINGLE_BYTE
|
|
1223
|
+
},
|
|
1224
|
+
[PM_ENCODING_IBM852] = {
|
|
1225
|
+
.name = "IBM852",
|
|
1226
|
+
.kind = PM_ENCODING_KIND_SINGLE_BYTE
|
|
1227
|
+
},
|
|
1228
|
+
[PM_ENCODING_IBM855] = {
|
|
1229
|
+
.name = "IBM855",
|
|
1230
|
+
.kind = PM_ENCODING_KIND_SINGLE_BYTE
|
|
1231
|
+
},
|
|
1232
|
+
[PM_ENCODING_IBM857] = {
|
|
1233
|
+
.name = "IBM857",
|
|
1234
|
+
.kind = PM_ENCODING_KIND_SINGLE_BYTE
|
|
1235
|
+
},
|
|
1236
|
+
[PM_ENCODING_IBM860] = {
|
|
1237
|
+
.name = "IBM860",
|
|
1238
|
+
.kind = PM_ENCODING_KIND_SINGLE_BYTE
|
|
1239
|
+
},
|
|
1240
|
+
[PM_ENCODING_IBM861] = {
|
|
1241
|
+
.name = "IBM861",
|
|
1242
|
+
.kind = PM_ENCODING_KIND_SINGLE_BYTE
|
|
1243
|
+
},
|
|
1244
|
+
[PM_ENCODING_IBM862] = {
|
|
1245
|
+
.name = "IBM862",
|
|
1246
|
+
.kind = PM_ENCODING_KIND_SINGLE_BYTE
|
|
1247
|
+
},
|
|
1248
|
+
[PM_ENCODING_IBM863] = {
|
|
1249
|
+
.name = "IBM863",
|
|
1250
|
+
.kind = PM_ENCODING_KIND_SINGLE_BYTE
|
|
1251
|
+
},
|
|
1252
|
+
[PM_ENCODING_IBM864] = {
|
|
1253
|
+
.name = "IBM864",
|
|
1254
|
+
.kind = PM_ENCODING_KIND_SINGLE_BYTE
|
|
1255
|
+
},
|
|
1256
|
+
[PM_ENCODING_IBM865] = {
|
|
1257
|
+
.name = "IBM865",
|
|
1258
|
+
.kind = PM_ENCODING_KIND_SINGLE_BYTE
|
|
1259
|
+
},
|
|
1260
|
+
[PM_ENCODING_IBM866] = {
|
|
1261
|
+
.name = "IBM866",
|
|
1262
|
+
.kind = PM_ENCODING_KIND_SINGLE_BYTE
|
|
1263
|
+
},
|
|
1264
|
+
[PM_ENCODING_IBM869] = {
|
|
1265
|
+
.name = "IBM869",
|
|
1266
|
+
.kind = PM_ENCODING_KIND_SINGLE_BYTE
|
|
1267
|
+
},
|
|
1268
|
+
[PM_ENCODING_ISO_8859_1] = {
|
|
1269
|
+
.name = "ISO-8859-1",
|
|
1270
|
+
.kind = PM_ENCODING_KIND_SINGLE_BYTE,
|
|
1271
|
+
.uppercase = pm_encoding_iso_8859_1_uppercase
|
|
1272
|
+
},
|
|
1273
|
+
[PM_ENCODING_ISO_8859_2] = {
|
|
1274
|
+
.name = "ISO-8859-2",
|
|
1275
|
+
.kind = PM_ENCODING_KIND_SINGLE_BYTE,
|
|
1276
|
+
.uppercase = pm_encoding_iso_8859_2_uppercase
|
|
1277
|
+
},
|
|
1278
|
+
[PM_ENCODING_ISO_8859_3] = {
|
|
1279
|
+
.name = "ISO-8859-3",
|
|
1280
|
+
.kind = PM_ENCODING_KIND_SINGLE_BYTE,
|
|
1281
|
+
.uppercase = pm_encoding_iso_8859_3_uppercase
|
|
1282
|
+
},
|
|
1283
|
+
[PM_ENCODING_ISO_8859_4] = {
|
|
1284
|
+
.name = "ISO-8859-4",
|
|
1285
|
+
.kind = PM_ENCODING_KIND_SINGLE_BYTE,
|
|
1286
|
+
.uppercase = pm_encoding_iso_8859_4_uppercase
|
|
1287
|
+
},
|
|
1288
|
+
[PM_ENCODING_ISO_8859_5] = {
|
|
1289
|
+
.name = "ISO-8859-5",
|
|
1290
|
+
.kind = PM_ENCODING_KIND_SINGLE_BYTE,
|
|
1291
|
+
.uppercase = pm_encoding_iso_8859_5_uppercase
|
|
1292
|
+
},
|
|
1293
|
+
[PM_ENCODING_ISO_8859_6] = {
|
|
1294
|
+
.name = "ISO-8859-6",
|
|
1295
|
+
.kind = PM_ENCODING_KIND_SINGLE_BYTE
|
|
1296
|
+
},
|
|
1297
|
+
[PM_ENCODING_ISO_8859_7] = {
|
|
1298
|
+
.name = "ISO-8859-7",
|
|
1299
|
+
.kind = PM_ENCODING_KIND_SINGLE_BYTE,
|
|
1300
|
+
.uppercase = pm_encoding_iso_8859_7_uppercase
|
|
1301
|
+
},
|
|
1302
|
+
[PM_ENCODING_ISO_8859_8] = {
|
|
1303
|
+
.name = "ISO-8859-8",
|
|
1304
|
+
.kind = PM_ENCODING_KIND_SINGLE_BYTE
|
|
1305
|
+
},
|
|
1306
|
+
[PM_ENCODING_ISO_8859_9] = {
|
|
1307
|
+
.name = "ISO-8859-9",
|
|
1308
|
+
.kind = PM_ENCODING_KIND_SINGLE_BYTE,
|
|
1309
|
+
.uppercase = pm_encoding_iso_8859_1_uppercase
|
|
1310
|
+
},
|
|
1311
|
+
[PM_ENCODING_ISO_8859_10] = {
|
|
1312
|
+
.name = "ISO-8859-10",
|
|
1313
|
+
.kind = PM_ENCODING_KIND_SINGLE_BYTE,
|
|
1314
|
+
.uppercase = pm_encoding_iso_8859_10_uppercase
|
|
1315
|
+
},
|
|
1316
|
+
[PM_ENCODING_ISO_8859_11] = {
|
|
1317
|
+
.name = "ISO-8859-11",
|
|
1318
|
+
.kind = PM_ENCODING_KIND_SINGLE_BYTE
|
|
1319
|
+
},
|
|
1320
|
+
[PM_ENCODING_ISO_8859_13] = {
|
|
1321
|
+
.name = "ISO-8859-13",
|
|
1322
|
+
.kind = PM_ENCODING_KIND_SINGLE_BYTE,
|
|
1323
|
+
.uppercase = pm_encoding_iso_8859_13_uppercase
|
|
1324
|
+
},
|
|
1325
|
+
[PM_ENCODING_ISO_8859_14] = {
|
|
1326
|
+
.name = "ISO-8859-14",
|
|
1327
|
+
.kind = PM_ENCODING_KIND_SINGLE_BYTE,
|
|
1328
|
+
.uppercase = pm_encoding_iso_8859_14_uppercase
|
|
1329
|
+
},
|
|
1330
|
+
[PM_ENCODING_ISO_8859_15] = {
|
|
1331
|
+
.name = "ISO-8859-15",
|
|
1332
|
+
.kind = PM_ENCODING_KIND_SINGLE_BYTE,
|
|
1333
|
+
.uppercase = pm_encoding_iso_8859_15_uppercase
|
|
1334
|
+
},
|
|
1335
|
+
[PM_ENCODING_ISO_8859_16] = {
|
|
1336
|
+
.name = "ISO-8859-16",
|
|
1337
|
+
.kind = PM_ENCODING_KIND_SINGLE_BYTE,
|
|
1338
|
+
.uppercase = pm_encoding_iso_8859_16_uppercase
|
|
1339
|
+
},
|
|
1340
|
+
[PM_ENCODING_KOI8_R] = {
|
|
1341
|
+
.name = "KOI8-R",
|
|
1342
|
+
.kind = PM_ENCODING_KIND_SINGLE_BYTE,
|
|
1343
|
+
.uppercase = pm_encoding_koi8_r_uppercase
|
|
1344
|
+
},
|
|
1345
|
+
[PM_ENCODING_KOI8_U] = {
|
|
1346
|
+
.name = "KOI8-U",
|
|
1347
|
+
.kind = PM_ENCODING_KIND_SINGLE_BYTE,
|
|
1348
|
+
.uppercase = pm_encoding_koi8_u_uppercase
|
|
1349
|
+
},
|
|
1350
|
+
[PM_ENCODING_MAC_CENT_EURO] = {
|
|
1351
|
+
.name = "macCentEuro",
|
|
1352
|
+
.kind = PM_ENCODING_KIND_SINGLE_BYTE
|
|
1353
|
+
},
|
|
1354
|
+
[PM_ENCODING_MAC_CROATIAN] = {
|
|
1355
|
+
.name = "macCroatian",
|
|
1356
|
+
.kind = PM_ENCODING_KIND_SINGLE_BYTE
|
|
1357
|
+
},
|
|
1358
|
+
[PM_ENCODING_MAC_CYRILLIC] = {
|
|
1359
|
+
.name = "macCyrillic",
|
|
1360
|
+
.kind = PM_ENCODING_KIND_SINGLE_BYTE
|
|
1361
|
+
},
|
|
1362
|
+
[PM_ENCODING_MAC_GREEK] = {
|
|
1363
|
+
.name = "macGreek",
|
|
1364
|
+
.kind = PM_ENCODING_KIND_SINGLE_BYTE
|
|
1365
|
+
},
|
|
1366
|
+
[PM_ENCODING_MAC_ICELAND] = {
|
|
1367
|
+
.name = "macIceland",
|
|
1368
|
+
.kind = PM_ENCODING_KIND_SINGLE_BYTE
|
|
1369
|
+
},
|
|
1370
|
+
[PM_ENCODING_MAC_JAPANESE] = {
|
|
1371
|
+
.name = "MacJapanese",
|
|
1372
|
+
.kind = PM_ENCODING_KIND_SHIFT_JIS
|
|
1373
|
+
},
|
|
1374
|
+
[PM_ENCODING_MAC_ROMAN] = {
|
|
1375
|
+
.name = "macRoman",
|
|
1376
|
+
.kind = PM_ENCODING_KIND_SINGLE_BYTE
|
|
1377
|
+
},
|
|
1378
|
+
[PM_ENCODING_MAC_ROMANIA] = {
|
|
1379
|
+
.name = "macRomania",
|
|
1380
|
+
.kind = PM_ENCODING_KIND_SINGLE_BYTE
|
|
1381
|
+
},
|
|
1382
|
+
[PM_ENCODING_MAC_THAI] = {
|
|
1383
|
+
.name = "macThai",
|
|
1384
|
+
.kind = PM_ENCODING_KIND_SINGLE_BYTE
|
|
1385
|
+
},
|
|
1386
|
+
[PM_ENCODING_MAC_TURKISH] = {
|
|
1387
|
+
.name = "macTurkish",
|
|
1388
|
+
.kind = PM_ENCODING_KIND_SINGLE_BYTE
|
|
1389
|
+
},
|
|
1390
|
+
[PM_ENCODING_MAC_UKRAINE] = {
|
|
1391
|
+
.name = "macUkraine",
|
|
1392
|
+
.kind = PM_ENCODING_KIND_SINGLE_BYTE
|
|
1393
|
+
},
|
|
1394
|
+
[PM_ENCODING_SHIFT_JIS] = {
|
|
1395
|
+
.name = "Shift_JIS",
|
|
1396
|
+
.kind = PM_ENCODING_KIND_SHIFT_JIS
|
|
1397
|
+
},
|
|
1398
|
+
[PM_ENCODING_SJIS_DOCOMO] = {
|
|
1399
|
+
.name = "SJIS-DoCoMo",
|
|
1400
|
+
.kind = PM_ENCODING_KIND_SHIFT_JIS
|
|
1401
|
+
},
|
|
1402
|
+
[PM_ENCODING_SJIS_KDDI] = {
|
|
1403
|
+
.name = "SJIS-KDDI",
|
|
1404
|
+
.kind = PM_ENCODING_KIND_SHIFT_JIS
|
|
1405
|
+
},
|
|
1406
|
+
[PM_ENCODING_SJIS_SOFTBANK] = {
|
|
1407
|
+
.name = "SJIS-SoftBank",
|
|
1408
|
+
.kind = PM_ENCODING_KIND_SHIFT_JIS
|
|
1409
|
+
},
|
|
1410
|
+
[PM_ENCODING_STATELESS_ISO_2022_JP] = {
|
|
1411
|
+
.name = "stateless-ISO-2022-JP",
|
|
1412
|
+
.kind = PM_ENCODING_KIND_EMACS_MULE
|
|
1413
|
+
},
|
|
1414
|
+
[PM_ENCODING_STATELESS_ISO_2022_JP_KDDI] = {
|
|
1415
|
+
.name = "stateless-ISO-2022-JP-KDDI",
|
|
1416
|
+
.kind = PM_ENCODING_KIND_EMACS_MULE
|
|
1417
|
+
},
|
|
1418
|
+
[PM_ENCODING_TIS_620] = {
|
|
1419
|
+
.name = "TIS-620",
|
|
1420
|
+
.kind = PM_ENCODING_KIND_SINGLE_BYTE
|
|
1421
|
+
},
|
|
1422
|
+
[PM_ENCODING_UTF8_MAC] = {
|
|
1423
|
+
.name = "UTF8-MAC",
|
|
1424
|
+
.kind = PM_ENCODING_KIND_UTF_8
|
|
1425
|
+
},
|
|
1426
|
+
[PM_ENCODING_UTF8_DOCOMO] = {
|
|
1427
|
+
.name = "UTF8-DoCoMo",
|
|
1428
|
+
.kind = PM_ENCODING_KIND_UTF_8
|
|
1429
|
+
},
|
|
1430
|
+
[PM_ENCODING_UTF8_KDDI] = {
|
|
1431
|
+
.name = "UTF8-KDDI",
|
|
1432
|
+
.kind = PM_ENCODING_KIND_UTF_8
|
|
1433
|
+
},
|
|
1434
|
+
[PM_ENCODING_UTF8_SOFTBANK] = {
|
|
1435
|
+
.name = "UTF8-SoftBank",
|
|
1436
|
+
.kind = PM_ENCODING_KIND_UTF_8
|
|
1437
|
+
},
|
|
1438
|
+
[PM_ENCODING_WINDOWS_1250] = {
|
|
1439
|
+
.name = "Windows-1250",
|
|
1440
|
+
.kind = PM_ENCODING_KIND_SINGLE_BYTE,
|
|
1441
|
+
.uppercase = pm_encoding_windows_1250_uppercase
|
|
1442
|
+
},
|
|
1443
|
+
[PM_ENCODING_WINDOWS_1251] = {
|
|
1444
|
+
.name = "Windows-1251",
|
|
1445
|
+
.kind = PM_ENCODING_KIND_SINGLE_BYTE,
|
|
1446
|
+
.uppercase = pm_encoding_windows_1251_uppercase
|
|
1447
|
+
},
|
|
1448
|
+
[PM_ENCODING_WINDOWS_1252] = {
|
|
1449
|
+
.name = "Windows-1252",
|
|
1450
|
+
.kind = PM_ENCODING_KIND_SINGLE_BYTE,
|
|
1451
|
+
.uppercase = pm_encoding_windows_1252_uppercase
|
|
1452
|
+
},
|
|
1453
|
+
[PM_ENCODING_WINDOWS_1253] = {
|
|
1454
|
+
.name = "Windows-1253",
|
|
1455
|
+
.kind = PM_ENCODING_KIND_SINGLE_BYTE,
|
|
1456
|
+
.uppercase = pm_encoding_windows_1253_uppercase
|
|
1457
|
+
},
|
|
1458
|
+
[PM_ENCODING_WINDOWS_1254] = {
|
|
1459
|
+
.name = "Windows-1254",
|
|
1460
|
+
.kind = PM_ENCODING_KIND_SINGLE_BYTE,
|
|
1461
|
+
.uppercase = pm_encoding_windows_1254_uppercase
|
|
1462
|
+
},
|
|
1463
|
+
[PM_ENCODING_WINDOWS_1255] = {
|
|
1464
|
+
.name = "Windows-1255",
|
|
1465
|
+
.kind = PM_ENCODING_KIND_SINGLE_BYTE
|
|
1466
|
+
},
|
|
1467
|
+
[PM_ENCODING_WINDOWS_1256] = {
|
|
1468
|
+
.name = "Windows-1256",
|
|
1469
|
+
.kind = PM_ENCODING_KIND_SINGLE_BYTE
|
|
1470
|
+
},
|
|
1471
|
+
[PM_ENCODING_WINDOWS_1257] = {
|
|
1472
|
+
.name = "Windows-1257",
|
|
1473
|
+
.kind = PM_ENCODING_KIND_SINGLE_BYTE,
|
|
1474
|
+
.uppercase = pm_encoding_iso_8859_13_uppercase
|
|
1475
|
+
},
|
|
1476
|
+
[PM_ENCODING_WINDOWS_1258] = {
|
|
1477
|
+
.name = "Windows-1258",
|
|
1478
|
+
.kind = PM_ENCODING_KIND_SINGLE_BYTE
|
|
1479
|
+
},
|
|
1480
|
+
[PM_ENCODING_WINDOWS_874] = {
|
|
1481
|
+
.name = "Windows-874",
|
|
1482
|
+
.kind = PM_ENCODING_KIND_SINGLE_BYTE
|
|
1483
|
+
}
|
|
1484
|
+
#endif
|
|
1485
|
+
};
|
|
1486
|
+
|
|
1487
|
+
/**
|
|
1488
|
+
* Parse the given name of an encoding and return a pointer to the corresponding
|
|
1489
|
+
* encoding struct if one can be found, otherwise return NULL.
|
|
1490
|
+
*/
|
|
1491
|
+
const pm_encoding_t *
|
|
1492
|
+
pm_encoding_find(const uint8_t *start, const uint8_t *end) {
|
|
1493
|
+
size_t width = (size_t) (end - start);
|
|
1494
|
+
|
|
1495
|
+
// First, we're going to check for UTF-8. This is the most common encoding.
|
|
1496
|
+
// UTF-8 can contain extra information at the end about the platform it is
|
|
1497
|
+
// encoded on, such as UTF-8-MAC or UTF-8-UNIX. We'll ignore those suffixes.
|
|
1498
|
+
if ((start + 5 <= end) && (pm_strncasecmp(start, (const uint8_t *) "UTF-8", 5) == 0)) {
|
|
1499
|
+
#ifndef PRISM_ENCODING_EXCLUDE_FULL
|
|
1500
|
+
// We need to explicitly handle UTF-8-HFS, as that one needs to switch
|
|
1501
|
+
// over to being UTF8-MAC.
|
|
1502
|
+
if (width == 9 && (pm_strncasecmp(start + 5, (const uint8_t *) "-HFS", 4) == 0)) {
|
|
1503
|
+
return &pm_encodings[PM_ENCODING_UTF8_MAC];
|
|
1504
|
+
}
|
|
1505
|
+
#endif
|
|
1506
|
+
|
|
1507
|
+
// Otherwise we'll return the default UTF-8 encoding.
|
|
1508
|
+
return PM_ENCODING_UTF_8_ENTRY;
|
|
1509
|
+
}
|
|
1510
|
+
|
|
1511
|
+
// Next, we're going to loop through each of the encodings that we handle
|
|
1512
|
+
// explicitly. If we found one that we understand, we'll use that value.
|
|
1513
|
+
#define ENCODING1(name, encoding) if (width == sizeof(name) - 1 && pm_strncasecmp(start, (const uint8_t *) name, width) == 0) return &pm_encodings[encoding];
|
|
1514
|
+
#define ENCODING2(name1, name2, encoding) ENCODING1(name1, encoding) ENCODING1(name2, encoding)
|
|
1515
|
+
|
|
1516
|
+
if (width >= 3) {
|
|
1517
|
+
switch (*start) {
|
|
1518
|
+
case 'A': case 'a':
|
|
1519
|
+
ENCODING1("ASCII", PM_ENCODING_US_ASCII);
|
|
1520
|
+
ENCODING1("ASCII-8BIT", PM_ENCODING_ASCII_8BIT);
|
|
1521
|
+
ENCODING1("ANSI_X3.4-1968", PM_ENCODING_US_ASCII);
|
|
1522
|
+
break;
|
|
1523
|
+
case 'B': case 'b':
|
|
1524
|
+
ENCODING1("BINARY", PM_ENCODING_ASCII_8BIT);
|
|
1525
|
+
#ifndef PRISM_ENCODING_EXCLUDE_FULL
|
|
1526
|
+
ENCODING1("Big5", PM_ENCODING_BIG5);
|
|
1527
|
+
ENCODING2("Big5-HKSCS", "Big5-HKSCS:2008", PM_ENCODING_BIG5_HKSCS);
|
|
1528
|
+
ENCODING1("Big5-UAO", PM_ENCODING_BIG5_UAO);
|
|
1529
|
+
#endif
|
|
1530
|
+
break;
|
|
1531
|
+
case 'C': case 'c':
|
|
1532
|
+
ENCODING1("CP65001", PM_ENCODING_UTF_8);
|
|
1533
|
+
ENCODING2("CP932", "csWindows31J", PM_ENCODING_WINDOWS_31J);
|
|
1534
|
+
#ifndef PRISM_ENCODING_EXCLUDE_FULL
|
|
1535
|
+
ENCODING1("CESU-8", PM_ENCODING_CESU_8);
|
|
1536
|
+
ENCODING1("CP437", PM_ENCODING_IBM437);
|
|
1537
|
+
ENCODING1("CP720", PM_ENCODING_IBM720);
|
|
1538
|
+
ENCODING1("CP737", PM_ENCODING_IBM737);
|
|
1539
|
+
ENCODING1("CP775", PM_ENCODING_IBM775);
|
|
1540
|
+
ENCODING1("CP850", PM_ENCODING_CP850);
|
|
1541
|
+
ENCODING1("CP852", PM_ENCODING_CP852);
|
|
1542
|
+
ENCODING1("CP855", PM_ENCODING_CP855);
|
|
1543
|
+
ENCODING1("CP857", PM_ENCODING_IBM857);
|
|
1544
|
+
ENCODING1("CP860", PM_ENCODING_IBM860);
|
|
1545
|
+
ENCODING1("CP861", PM_ENCODING_IBM861);
|
|
1546
|
+
ENCODING1("CP862", PM_ENCODING_IBM862);
|
|
1547
|
+
ENCODING1("CP864", PM_ENCODING_IBM864);
|
|
1548
|
+
ENCODING1("CP865", PM_ENCODING_IBM865);
|
|
1549
|
+
ENCODING1("CP866", PM_ENCODING_IBM866);
|
|
1550
|
+
ENCODING1("CP869", PM_ENCODING_IBM869);
|
|
1551
|
+
ENCODING1("CP874", PM_ENCODING_WINDOWS_874);
|
|
1552
|
+
ENCODING1("CP878", PM_ENCODING_KOI8_R);
|
|
1553
|
+
ENCODING1("CP863", PM_ENCODING_IBM863);
|
|
1554
|
+
ENCODING1("CP936", PM_ENCODING_GBK);
|
|
1555
|
+
ENCODING1("CP949", PM_ENCODING_CP949);
|
|
1556
|
+
ENCODING1("CP950", PM_ENCODING_CP950);
|
|
1557
|
+
ENCODING1("CP951", PM_ENCODING_CP951);
|
|
1558
|
+
ENCODING1("CP1250", PM_ENCODING_WINDOWS_1250);
|
|
1559
|
+
ENCODING1("CP1251", PM_ENCODING_WINDOWS_1251);
|
|
1560
|
+
ENCODING1("CP1252", PM_ENCODING_WINDOWS_1252);
|
|
1561
|
+
ENCODING1("CP1253", PM_ENCODING_WINDOWS_1253);
|
|
1562
|
+
ENCODING1("CP1254", PM_ENCODING_WINDOWS_1254);
|
|
1563
|
+
ENCODING1("CP1255", PM_ENCODING_WINDOWS_1255);
|
|
1564
|
+
ENCODING1("CP1256", PM_ENCODING_WINDOWS_1256);
|
|
1565
|
+
ENCODING1("CP1257", PM_ENCODING_WINDOWS_1257);
|
|
1566
|
+
ENCODING1("CP1258", PM_ENCODING_WINDOWS_1258);
|
|
1567
|
+
ENCODING1("CP51932", PM_ENCODING_CP51932);
|
|
1568
|
+
#endif
|
|
1569
|
+
break;
|
|
1570
|
+
case 'E': case 'e':
|
|
1571
|
+
ENCODING2("EUC-JP", "eucJP", PM_ENCODING_EUC_JP);
|
|
1572
|
+
#ifndef PRISM_ENCODING_EXCLUDE_FULL
|
|
1573
|
+
ENCODING2("eucJP-ms", "euc-jp-ms", PM_ENCODING_EUC_JP_MS);
|
|
1574
|
+
ENCODING2("EUC-JIS-2004", "EUC-JISX0213", PM_ENCODING_EUC_JIS_2004);
|
|
1575
|
+
ENCODING2("EUC-KR", "eucKR", PM_ENCODING_EUC_KR);
|
|
1576
|
+
ENCODING2("EUC-CN", "eucCN", PM_ENCODING_GB2312);
|
|
1577
|
+
ENCODING2("EUC-TW", "eucTW", PM_ENCODING_EUC_TW);
|
|
1578
|
+
ENCODING1("Emacs-Mule", PM_ENCODING_EMACS_MULE);
|
|
1579
|
+
#endif
|
|
1580
|
+
break;
|
|
1581
|
+
case 'G': case 'g':
|
|
1582
|
+
#ifndef PRISM_ENCODING_EXCLUDE_FULL
|
|
1583
|
+
ENCODING1("GBK", PM_ENCODING_GBK);
|
|
1584
|
+
ENCODING1("GB12345", PM_ENCODING_GB12345);
|
|
1585
|
+
ENCODING1("GB18030", PM_ENCODING_GB18030);
|
|
1586
|
+
ENCODING1("GB1988", PM_ENCODING_GB1988);
|
|
1587
|
+
ENCODING1("GB2312", PM_ENCODING_GB2312);
|
|
1588
|
+
#endif
|
|
1589
|
+
break;
|
|
1590
|
+
case 'I': case 'i':
|
|
1591
|
+
#ifndef PRISM_ENCODING_EXCLUDE_FULL
|
|
1592
|
+
ENCODING1("IBM437", PM_ENCODING_IBM437);
|
|
1593
|
+
ENCODING1("IBM720", PM_ENCODING_IBM720);
|
|
1594
|
+
ENCODING1("IBM737", PM_ENCODING_IBM737);
|
|
1595
|
+
ENCODING1("IBM775", PM_ENCODING_IBM775);
|
|
1596
|
+
ENCODING1("IBM850", PM_ENCODING_CP850);
|
|
1597
|
+
ENCODING1("IBM852", PM_ENCODING_IBM852);
|
|
1598
|
+
ENCODING1("IBM855", PM_ENCODING_IBM855);
|
|
1599
|
+
ENCODING1("IBM857", PM_ENCODING_IBM857);
|
|
1600
|
+
ENCODING1("IBM860", PM_ENCODING_IBM860);
|
|
1601
|
+
ENCODING1("IBM861", PM_ENCODING_IBM861);
|
|
1602
|
+
ENCODING1("IBM862", PM_ENCODING_IBM862);
|
|
1603
|
+
ENCODING1("IBM863", PM_ENCODING_IBM863);
|
|
1604
|
+
ENCODING1("IBM864", PM_ENCODING_IBM864);
|
|
1605
|
+
ENCODING1("IBM865", PM_ENCODING_IBM865);
|
|
1606
|
+
ENCODING1("IBM866", PM_ENCODING_IBM866);
|
|
1607
|
+
ENCODING1("IBM869", PM_ENCODING_IBM869);
|
|
1608
|
+
ENCODING2("ISO-8859-1", "ISO8859-1", PM_ENCODING_ISO_8859_1);
|
|
1609
|
+
ENCODING2("ISO-8859-2", "ISO8859-2", PM_ENCODING_ISO_8859_2);
|
|
1610
|
+
ENCODING2("ISO-8859-3", "ISO8859-3", PM_ENCODING_ISO_8859_3);
|
|
1611
|
+
ENCODING2("ISO-8859-4", "ISO8859-4", PM_ENCODING_ISO_8859_4);
|
|
1612
|
+
ENCODING2("ISO-8859-5", "ISO8859-5", PM_ENCODING_ISO_8859_5);
|
|
1613
|
+
ENCODING2("ISO-8859-6", "ISO8859-6", PM_ENCODING_ISO_8859_6);
|
|
1614
|
+
ENCODING2("ISO-8859-7", "ISO8859-7", PM_ENCODING_ISO_8859_7);
|
|
1615
|
+
ENCODING2("ISO-8859-8", "ISO8859-8", PM_ENCODING_ISO_8859_8);
|
|
1616
|
+
ENCODING2("ISO-8859-9", "ISO8859-9", PM_ENCODING_ISO_8859_9);
|
|
1617
|
+
ENCODING2("ISO-8859-10", "ISO8859-10", PM_ENCODING_ISO_8859_10);
|
|
1618
|
+
ENCODING2("ISO-8859-11", "ISO8859-11", PM_ENCODING_ISO_8859_11);
|
|
1619
|
+
ENCODING2("ISO-8859-13", "ISO8859-13", PM_ENCODING_ISO_8859_13);
|
|
1620
|
+
ENCODING2("ISO-8859-14", "ISO8859-14", PM_ENCODING_ISO_8859_14);
|
|
1621
|
+
ENCODING2("ISO-8859-15", "ISO8859-15", PM_ENCODING_ISO_8859_15);
|
|
1622
|
+
ENCODING2("ISO-8859-16", "ISO8859-16", PM_ENCODING_ISO_8859_16);
|
|
1623
|
+
#endif
|
|
1624
|
+
break;
|
|
1625
|
+
case 'K': case 'k':
|
|
1626
|
+
#ifndef PRISM_ENCODING_EXCLUDE_FULL
|
|
1627
|
+
ENCODING1("KOI8-R", PM_ENCODING_KOI8_R);
|
|
1628
|
+
ENCODING1("KOI8-U", PM_ENCODING_KOI8_U);
|
|
1629
|
+
#endif
|
|
1630
|
+
break;
|
|
1631
|
+
case 'M': case 'm':
|
|
1632
|
+
#ifndef PRISM_ENCODING_EXCLUDE_FULL
|
|
1633
|
+
ENCODING1("macCentEuro", PM_ENCODING_MAC_CENT_EURO);
|
|
1634
|
+
ENCODING1("macCroatian", PM_ENCODING_MAC_CROATIAN);
|
|
1635
|
+
ENCODING1("macCyrillic", PM_ENCODING_MAC_CYRILLIC);
|
|
1636
|
+
ENCODING1("macGreek", PM_ENCODING_MAC_GREEK);
|
|
1637
|
+
ENCODING1("macIceland", PM_ENCODING_MAC_ICELAND);
|
|
1638
|
+
ENCODING1("MacJapanese", PM_ENCODING_MAC_JAPANESE);
|
|
1639
|
+
ENCODING1("MacJapan", PM_ENCODING_MAC_JAPANESE);
|
|
1640
|
+
ENCODING1("macRoman", PM_ENCODING_MAC_ROMAN);
|
|
1641
|
+
ENCODING1("macRomania", PM_ENCODING_MAC_ROMANIA);
|
|
1642
|
+
ENCODING1("macThai", PM_ENCODING_MAC_THAI);
|
|
1643
|
+
ENCODING1("macTurkish", PM_ENCODING_MAC_TURKISH);
|
|
1644
|
+
ENCODING1("macUkraine", PM_ENCODING_MAC_UKRAINE);
|
|
1645
|
+
#endif
|
|
1646
|
+
break;
|
|
1647
|
+
case 'P': case 'p':
|
|
1648
|
+
ENCODING1("PCK", PM_ENCODING_WINDOWS_31J);
|
|
1649
|
+
break;
|
|
1650
|
+
case 'S': case 's':
|
|
1651
|
+
ENCODING1("SJIS", PM_ENCODING_WINDOWS_31J);
|
|
1652
|
+
#ifndef PRISM_ENCODING_EXCLUDE_FULL
|
|
1653
|
+
ENCODING1("Shift_JIS", PM_ENCODING_SHIFT_JIS);
|
|
1654
|
+
ENCODING1("SJIS-DoCoMo", PM_ENCODING_SJIS_DOCOMO);
|
|
1655
|
+
ENCODING1("SJIS-KDDI", PM_ENCODING_SJIS_KDDI);
|
|
1656
|
+
ENCODING1("SJIS-SoftBank", PM_ENCODING_SJIS_SOFTBANK);
|
|
1657
|
+
ENCODING1("stateless-ISO-2022-JP", PM_ENCODING_STATELESS_ISO_2022_JP);
|
|
1658
|
+
ENCODING1("stateless-ISO-2022-JP-KDDI", PM_ENCODING_STATELESS_ISO_2022_JP_KDDI);
|
|
1659
|
+
#endif
|
|
1660
|
+
break;
|
|
1661
|
+
case 'T': case 't':
|
|
1662
|
+
#ifndef PRISM_ENCODING_EXCLUDE_FULL
|
|
1663
|
+
ENCODING1("TIS-620", PM_ENCODING_TIS_620);
|
|
1664
|
+
#endif
|
|
1665
|
+
break;
|
|
1666
|
+
case 'U': case 'u':
|
|
1667
|
+
ENCODING1("US-ASCII", PM_ENCODING_US_ASCII);
|
|
1668
|
+
#ifndef PRISM_ENCODING_EXCLUDE_FULL
|
|
1669
|
+
ENCODING2("UTF8-MAC", "UTF-8-HFS", PM_ENCODING_UTF8_MAC);
|
|
1670
|
+
ENCODING1("UTF8-DoCoMo", PM_ENCODING_UTF8_DOCOMO);
|
|
1671
|
+
ENCODING1("UTF8-KDDI", PM_ENCODING_UTF8_KDDI);
|
|
1672
|
+
ENCODING1("UTF8-SoftBank", PM_ENCODING_UTF8_SOFTBANK);
|
|
1673
|
+
#endif
|
|
1674
|
+
break;
|
|
1675
|
+
case 'W': case 'w':
|
|
1676
|
+
ENCODING1("Windows-31J", PM_ENCODING_WINDOWS_31J);
|
|
1677
|
+
#ifndef PRISM_ENCODING_EXCLUDE_FULL
|
|
1678
|
+
ENCODING1("Windows-874", PM_ENCODING_WINDOWS_874);
|
|
1679
|
+
ENCODING1("Windows-1250", PM_ENCODING_WINDOWS_1250);
|
|
1680
|
+
ENCODING1("Windows-1251", PM_ENCODING_WINDOWS_1251);
|
|
1681
|
+
ENCODING1("Windows-1252", PM_ENCODING_WINDOWS_1252);
|
|
1682
|
+
ENCODING1("Windows-1253", PM_ENCODING_WINDOWS_1253);
|
|
1683
|
+
ENCODING1("Windows-1254", PM_ENCODING_WINDOWS_1254);
|
|
1684
|
+
ENCODING1("Windows-1255", PM_ENCODING_WINDOWS_1255);
|
|
1685
|
+
ENCODING1("Windows-1256", PM_ENCODING_WINDOWS_1256);
|
|
1686
|
+
ENCODING1("Windows-1257", PM_ENCODING_WINDOWS_1257);
|
|
1687
|
+
ENCODING1("Windows-1258", PM_ENCODING_WINDOWS_1258);
|
|
1688
|
+
#endif
|
|
1689
|
+
break;
|
|
1690
|
+
case '6':
|
|
1691
|
+
ENCODING1("646", PM_ENCODING_US_ASCII);
|
|
1692
|
+
break;
|
|
1693
|
+
}
|
|
1694
|
+
}
|
|
1695
|
+
|
|
1696
|
+
#undef ENCODING2
|
|
1697
|
+
#undef ENCODING1
|
|
1698
|
+
|
|
1699
|
+
// If we didn't match any encodings, return NULL.
|
|
1700
|
+
return NULL;
|
|
1701
|
+
}
|