MCPcopy Create free account
hub / github.com/Kitware/CMake / cm_utf8_decode_character

Function cm_utf8_decode_character

Source/cm_utf8.c:42–94  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

40};
41
42char const* cm_utf8_decode_character(char const* first, char const* last,
43 unsigned int* pc)
44{
45 /* We need at least one byte. */
46 if (first == last) {
47 return 0;
48 }
49
50 /* Count leading ones in the first byte. */
51 unsigned char c = (unsigned char)*first++;
52 unsigned char const ones = cm_utf8_ones[c];
53 switch (ones) {
54 case 0:
55 *pc = c;
56 return first; /* One-byte character. */
57 case 1:
58 case 7:
59 case 8:
60 return 0; /* Invalid leading byte. */
61 default:
62 break;
63 }
64
65 /* Extract bits from this multi-byte character. */
66 {
67 unsigned int uc = c & cm_utf8_mask[ones];
68 int left;
69 for (left = ones - 1; left && first != last; --left) {
70 c = (unsigned char)*first++;
71 if (cm_utf8_ones[c] != 1) {
72 return 0;
73 }
74 uc = (uc << 6) | (c & cm_utf8_mask[1]);
75 }
76
77 if (left > 0 || uc < cm_utf8_min[ones]) {
78 return 0;
79 }
80
81 /* UTF-16 surrogate halves. */
82 if (0xD800 <= uc && uc <= 0xDFFF) {
83 return 0;
84 }
85
86 /* Invalid codepoints. */
87 if (0x10FFFF < uc) {
88 return 0;
89 }
90
91 *pc = uc;
92 return first;
93 }
94}
95
96int cm_utf8_is_valid(char const* s)
97{

Callers 6

decode_goodFunction · 0.85
decode_badFunction · 0.85
cmXMLSafe.cxxFile · 0.85
WriteLiteralTextBlockMethod · 0.85
cm_utf8_is_validFunction · 0.85
CleanTestOutputMethod · 0.85

Calls

no outgoing calls

Tested by 3

decode_goodFunction · 0.68
decode_badFunction · 0.68
CleanTestOutputMethod · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…