comparison trunk/src/dil/doc/Macro.d @ 722:ceaac6a24258

Added isUnicodeAlpha() for DDocParser and MacroParser.
author Aziz K?ksal <aziz.koeksal@gmail.com>
date Fri, 01 Feb 2008 19:44:00 +0100
parents be887ada3e3e
children 5dd17d4568ce
comparison
equal deleted inserted replaced
721:8955296dd807 722:ceaac6a24258
92 { 92 {
93 while (*p != '\0') 93 while (*p != '\0')
94 { 94 {
95 skipWhitespace(p); 95 skipWhitespace(p);
96 auto idBegin = p; 96 auto idBegin = p;
97 if (isidbeg(*p) || isUnicodeAlpha(p)) // IdStart 97 if (isidbeg(*p) || isUnicodeAlpha(p, textEnd)) // IdStart
98 { 98 {
99 do // IdChar* 99 do // IdChar*
100 p++; 100 p++;
101 while (isident(*p) || isUnicodeAlpha(p)) 101 while (isident(*p) || isUnicodeAlpha(p, textEnd))
102 auto idEnd = p; 102 auto idEnd = p;
103 103
104 skipWhitespace(p); 104 skipWhitespace(p);
105 if (*p == '=') 105 if (*p == '=')
106 { 106 {
119 { 119 {
120 while (*p != '\n') 120 while (*p != '\n')
121 p++; 121 p++;
122 p++; 122 p++;
123 } 123 }
124
125 bool isUnicodeAlpha(ref char* ref_p)
126 {
127 char* p = ref_p; // Copy.
128 if (isascii(*p))
129 return false;
130
131 dchar d = *p;
132 p++; // Move to second byte.
133 // Error if second byte is not a trail byte.
134 if (!isTrailByte(*p))
135 return false;
136 // Check for overlong sequences.
137 switch (d)
138 {
139 case 0xE0, 0xF0, 0xF8, 0xFC:
140 if ((*p & d) == 0x80)
141 return false;
142 default:
143 if ((d & 0xFE) == 0xC0) // 1100000x
144 return false;
145 }
146 const char[] checkNextByte = "if (!isTrailByte(*++p))"
147 " return false;";
148 const char[] appendSixBits = "d = (d << 6) | *p & 0b0011_1111;";
149 // Decode
150 if ((d & 0b1110_0000) == 0b1100_0000)
151 {
152 d &= 0b0001_1111;
153 mixin(appendSixBits);
154 }
155 else if ((d & 0b1111_0000) == 0b1110_0000)
156 {
157 d &= 0b0000_1111;
158 mixin(appendSixBits ~
159 checkNextByte ~ appendSixBits);
160 }
161 else if ((d & 0b1111_1000) == 0b1111_0000)
162 {
163 d &= 0b0000_0111;
164 mixin(appendSixBits ~
165 checkNextByte ~ appendSixBits ~
166 checkNextByte ~ appendSixBits);
167 }
168 else
169 return false;
170
171 assert(isTrailByte(*p));
172 if (!isValidChar(d) || !isUniAlpha(d))
173 return false;
174 // Only advance pointer if this is a Unicode alpha character.
175 ref_p = p;
176 return true;
177 }
178 } 124 }
179 125
180 char[] makeString(char* begin, char* end) 126 char[] makeString(char* begin, char* end)
181 { 127 {
182 return begin[0 .. end - begin]; 128 return begin[0 .. end - begin];
183 } 129 }
130
131 char[] expandMacros(MacroTable table, char[] text)
132 {
133 char[] result;
134 char* p = text.ptr;
135 char* textEnd = p + text.length;
136 // while (p < text.length)
137 // {
138
139 // }
140 return result;
141 }
142