fork/m-overlay

git clone https://git.julia.blue/fork/m-overlay

BkacjiosAllow double clicking on TextEntry to select closest word/punctuation chunk. Update UTF8 extensions.da85c05

v2.1.3
55.9 KiB2881 linesraw
1-- $Id: utf8.lua 179 2009-04-03 18:10:03Z pasta $
2--
3-- Provides UTF-8 aware string functions implemented in pure lua:
4-- * utf8len(s)
5-- * utf8sub(s, i, j)
6-- * utf8reverse(s)
7-- * utf8char(unicode)
8-- * utf8unicode(s, i, j)
9-- * utf8gensub(s, sub_len)
10-- * utf8find(str, regex, init, plain)
11-- * utf8match(str, regex, init)
12-- * utf8gmatch(str, regex, all)
13-- * utf8gsub(str, regex, repl, limit)
14--
15-- If utf8data.lua (containing the lower<->upper case mappings) is loaded, these
16-- additional functions are available:
17-- * utf8upper(s)
18-- * utf8lower(s)
19--
20-- All functions behave as their non UTF-8 aware counterparts with the exception
21-- that UTF-8 characters are used instead of bytes for all units.
22
23--[[
24Copyright (c) 2006-2007, Kyle Smith
25All rights reserved.
26
27Contributors:
28Alimov Stepan
29
30Redistribution and use in source and binary forms, with or without
31modification, are permitted provided that the following conditions are met:
32
33* Redistributions of source code must retain the above copyright notice,
34this list of conditions and the following disclaimer.
35* Redistributions in binary form must reproduce the above copyright
36notice, this list of conditions and the following disclaimer in the
37documentation and/or other materials provided with the distribution.
38* Neither the name of the author nor the names of its contributors may be
39used to endorse or promote products derived from this software without
40specific prior written permission.
41
42THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
43AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
44IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
45DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
46FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
47DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
48SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
49CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
50OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
51OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
52--]]
53
54-- ABNF from RFC 3629
55--
56-- UTF8-octets = *( UTF8-char )
57-- UTF8-char   = UTF8-1 / UTF8-2 / UTF8-3 / UTF8-4
58-- UTF8-1      = %x00-7F
59-- UTF8-2      = %xC2-DF UTF8-tail
60-- UTF8-3      = %xE0 %xA0-BF UTF8-tail / %xE1-EC 2( UTF8-tail ) /
61--               %xED %x80-9F UTF8-tail / %xEE-EF 2( UTF8-tail )
62-- UTF8-4      = %xF0 %x90-BF 2( UTF8-tail ) / %xF1-F3 3( UTF8-tail ) /
63--               %xF4 %x80-8F 2( UTF8-tail )
64-- UTF8-tail   = %x80-BF
65--
66
67local utf8 = require("utf8")
68
69local utf8len = utf8.len
70local byte    = string.byte
71local char    = string.char
72local dump    = string.dump
73local find    = string.find
74local format  = string.format
75local len     = string.len
76local rep     = string.rep
77local sub     = string.sub
78
79-- returns the number of bytes used by the UTF-8 character at byte i in s
80-- also doubles as a UTF-8 character validator
81local function utf8charbytes (s, i)
82	-- argument defaults
83	i = i or 1
84
85	-- argument checking
86	if type(s) ~= "string" then
87		error("bad argument #1 to 'utf8.charbytes' (string expected, got ".. type(s).. ")")
88	end
89	if type(i) ~= "number" then
90		error("bad argument #2 to 'utf8.charbytes' (number expected, got ".. type(i).. ")")
91	end
92
93	local c = byte(s, i)
94
95	-- determine bytes needed for character, based on RFC 3629
96	-- validate byte 1
97	if c > 0 and c <= 127 then
98		-- UTF8-1
99		return 1
100
101	elseif c >= 194 and c <= 223 then
102		-- UTF8-2
103		local c2 = byte(s, i + 1)
104
105		if not c2 then
106			error("UTF-8 string terminated early")
107		end
108
109		-- validate byte 2
110		if c2 < 128 or c2 > 191 then
111			error("Invalid UTF-8 character")
112		end
113
114		return 2
115
116	elseif c >= 224 and c <= 239 then
117		-- UTF8-3
118		local c2 = byte(s, i + 1)
119		local c3 = byte(s, i + 2)
120
121		if not c2 or not c3 then
122			error("UTF-8 string terminated early")
123		end
124
125		-- validate byte 2
126		if c == 224 and (c2 < 160 or c2 > 191) then
127			error("Invalid UTF-8 character")
128		elseif c == 237 and (c2 < 128 or c2 > 159) then
129			error("Invalid UTF-8 character")
130		elseif c2 < 128 or c2 > 191 then
131			error("Invalid UTF-8 character")
132		end
133
134		-- validate byte 3
135		if c3 < 128 or c3 > 191 then
136			error("Invalid UTF-8 character")
137		end
138
139		return 3
140
141	elseif c >= 240 and c <= 244 then
142		-- UTF8-4
143		local c2 = byte(s, i + 1)
144		local c3 = byte(s, i + 2)
145		local c4 = byte(s, i + 3)
146
147		if not c2 or not c3 or not c4 then
148			error("UTF-8 string terminated early")
149		end
150
151		-- validate byte 2
152		if c == 240 and (c2 < 144 or c2 > 191) then
153			error("Invalid UTF-8 character")
154		elseif c == 244 and (c2 < 128 or c2 > 143) then
155			error("Invalid UTF-8 character")
156		elseif c2 < 128 or c2 > 191 then
157			error("Invalid UTF-8 character")
158		end
159
160		-- validate byte 3
161		if c3 < 128 or c3 > 191 then
162			error("Invalid UTF-8 character")
163		end
164
165		-- validate byte 4
166		if c4 < 128 or c4 > 191 then
167			error("Invalid UTF-8 character")
168		end
169
170		return 4
171
172	else
173		error("Invalid UTF-8 character")
174	end
175end
176
177-- functions identically to string.sub except that i and j are UTF-8 characters
178-- instead of bytes
179local function utf8sub (s, i, j)
180	-- argument defaults
181	j = j or -1
182
183	local pos = 1
184	local bytes = len(s)
185	local length = 0
186
187	-- only set l if i or j is negative
188	local l = (i >= 0 and j >= 0) or utf8len(s)
189	local startChar = (i >= 0) and i or l + i + 1
190	local endChar   = (j >= 0) and j or l + j + 1
191
192	-- can't have start before end!
193	if startChar > endChar then
194		return ""
195	end
196
197	-- byte offsets to pass to string.sub
198	local startByte,endByte = 1,bytes
199
200	while pos <= bytes do
201		length = length + 1
202
203		if length == startChar then
204			startByte = pos
205		end
206
207		pos = pos + utf8charbytes(s, pos)
208
209		if length == endChar then
210			endByte = pos - 1
211			break
212		end
213	end
214
215	if startChar > length then startByte = bytes+1   end
216	if endChar   < 1      then endByte   = 0         end
217
218	return sub(s, startByte, endByte)
219end
220
221-- replace UTF-8 characters based on a mapping table
222local function utf8replace (s, mapping)
223	-- argument checking
224	if type(s) ~= "string" then
225		error("bad argument #1 to 'utf8.replace' (string expected, got ".. type(s).. ")")
226	end
227	if type(mapping) ~= "table" then
228		error("bad argument #2 to 'utf8.replace' (table expected, got ".. type(mapping).. ")")
229	end
230
231	local pos = 1
232	local bytes = len(s)
233	local charbytes
234	local newstr = ""
235
236	while pos <= bytes do
237		charbytes = utf8charbytes(s, pos)
238		local c = sub(s, pos, pos + charbytes - 1)
239
240		newstr = newstr .. (mapping[c] or c)
241
242		pos = pos + charbytes
243	end
244
245	return newstr
246end
247
248local utf8_lc_uc = {
249	["a"] = "A",
250	["b"] = "B",
251	["c"] = "C",
252	["d"] = "D",
253	["e"] = "E",
254	["f"] = "F",
255	["g"] = "G",
256	["h"] = "H",
257	["i"] = "I",
258	["j"] = "J",
259	["k"] = "K",
260	["l"] = "L",
261	["m"] = "M",
262	["n"] = "N",
263	["o"] = "O",
264	["p"] = "P",
265	["q"] = "Q",
266	["r"] = "R",
267	["s"] = "S",
268	["t"] = "T",
269	["u"] = "U",
270	["v"] = "V",
271	["w"] = "W",
272	["x"] = "X",
273	["y"] = "Y",
274	["z"] = "Z",
275	["µ"] = "Μ",
276	["à"] = "À",
277	["á"] = "Á",
278	["â"] = "Â",
279	["ã"] = "Ã",
280	["ä"] = "Ä",
281	["å"] = "Å",
282	["æ"] = "Æ",
283	["ç"] = "Ç",
284	["è"] = "È",
285	["é"] = "É",
286	["ê"] = "Ê",
287	["ë"] = "Ë",
288	["ì"] = "Ì",
289	["í"] = "Í",
290	["î"] = "Î",
291	["ï"] = "Ï",
292	["ð"] = "Ð",
293	["ñ"] = "Ñ",
294	["ò"] = "Ò",
295	["ó"] = "Ó",
296	["ô"] = "Ô",
297	["õ"] = "Õ",
298	["ö"] = "Ö",
299	["ø"] = "Ø",
300	["ù"] = "Ù",
301	["ú"] = "Ú",
302	["û"] = "Û",
303	["ü"] = "Ü",
304	["ý"] = "Ý",
305	["þ"] = "Þ",
306	["ÿ"] = "Ÿ",
307	["ā"] = "Ā",
308	["ă"] = "Ă",
309	["ą"] = "Ą",
310	["ć"] = "Ć",
311	["ĉ"] = "Ĉ",
312	["ċ"] = "Ċ",
313	["č"] = "Č",
314	["ď"] = "Ď",
315	["đ"] = "Đ",
316	["ē"] = "Ē",
317	["ĕ"] = "Ĕ",
318	["ė"] = "Ė",
319	["ę"] = "Ę",
320	["ě"] = "Ě",
321	["ĝ"] = "Ĝ",
322	["ğ"] = "Ğ",
323	["ġ"] = "Ġ",
324	["ģ"] = "Ģ",
325	["ĥ"] = "Ĥ",
326	["ħ"] = "Ħ",
327	["ĩ"] = "Ĩ",
328	["ī"] = "Ī",
329	["ĭ"] = "Ĭ",
330	["į"] = "Į",
331	["ı"] = "I",
332	["ij"] = "IJ",
333	["ĵ"] = "Ĵ",
334	["ķ"] = "Ķ",
335	["ĺ"] = "Ĺ",
336	["ļ"] = "Ļ",
337	["ľ"] = "Ľ",
338	["ŀ"] = "Ŀ",
339	["ł"] = "Ł",
340	["ń"] = "Ń",
341	["ņ"] = "Ņ",
342	["ň"] = "Ň",
343	["ŋ"] = "Ŋ",
344	["ō"] = "Ō",
345	["ŏ"] = "Ŏ",
346	["ő"] = "Ő",
347	["œ"] = "Œ",
348	["ŕ"] = "Ŕ",
349	["ŗ"] = "Ŗ",
350	["ř"] = "Ř",
351	["ś"] = "Ś",
352	["ŝ"] = "Ŝ",
353	["ş"] = "Ş",
354	["š"] = "Š",
355	["ţ"] = "Ţ",
356	["ť"] = "Ť",
357	["ŧ"] = "Ŧ",
358	["ũ"] = "Ũ",
359	["ū"] = "Ū",
360	["ŭ"] = "Ŭ",
361	["ů"] = "Ů",
362	["ű"] = "Ű",
363	["ų"] = "Ų",
364	["ŵ"] = "Ŵ",
365	["ŷ"] = "Ŷ",
366	["ź"] = "Ź",
367	["ż"] = "Ż",
368	["ž"] = "Ž",
369	["ſ"] = "S",
370	["ƀ"] = "Ƀ",
371	["ƃ"] = "Ƃ",
372	["ƅ"] = "Ƅ",
373	["ƈ"] = "Ƈ",
374	["ƌ"] = "Ƌ",
375	["ƒ"] = "Ƒ",
376	["ƕ"] = "Ƕ",
377	["ƙ"] = "Ƙ",
378	["ƚ"] = "Ƚ",
379	["ƞ"] = "Ƞ",
380	["ơ"] = "Ơ",
381	["ƣ"] = "Ƣ",
382	["ƥ"] = "Ƥ",
383	["ƨ"] = "Ƨ",
384	["ƭ"] = "Ƭ",
385	["ư"] = "Ư",
386	["ƴ"] = "Ƴ",
387	["ƶ"] = "Ƶ",
388	["ƹ"] = "Ƹ",
389	["ƽ"] = "Ƽ",
390	["ƿ"] = "Ƿ",
391	["Dž"] = "DŽ",
392	["dž"] = "DŽ",
393	["Lj"] = "LJ",
394	["lj"] = "LJ",
395	["Nj"] = "NJ",
396	["nj"] = "NJ",
397	["ǎ"] = "Ǎ",
398	["ǐ"] = "Ǐ",
399	["ǒ"] = "Ǒ",
400	["ǔ"] = "Ǔ",
401	["ǖ"] = "Ǖ",
402	["ǘ"] = "Ǘ",
403	["ǚ"] = "Ǚ",
404	["ǜ"] = "Ǜ",
405	["ǝ"] = "Ǝ",
406	["ǟ"] = "Ǟ",
407	["ǡ"] = "Ǡ",
408	["ǣ"] = "Ǣ",
409	["ǥ"] = "Ǥ",
410	["ǧ"] = "Ǧ",
411	["ǩ"] = "Ǩ",
412	["ǫ"] = "Ǫ",
413	["ǭ"] = "Ǭ",
414	["ǯ"] = "Ǯ",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",
473	["ʊ"] = "Ʊ",
474	["ʋ"] = "Ʋ",
475	["ʌ"] = "Ʌ",
476	["ʒ"] = "Ʒ",
477	["ͅ"] = "Ι",
478	["ͻ"] = "Ͻ",
479	["ͼ"] = "Ͼ",
480	["ͽ"] = "Ͽ",
481	["ά"] = "Ά",
482	["έ"] = "Έ",
483	["ή"] = "Ή",
484	["ί"] = "Ί",
485	["α"] = "Α",
486	["β"] = "Β",
487	["γ"] = "Γ",
488	["δ"] = "Δ",
489	["ε"] = "Ε",
490	["ζ"] = "Ζ",
491	["η"] = "Η",
492	["θ"] = "Θ",
493	["ι"] = "Ι",
494	["κ"] = "Κ",
495	["λ"] = "Λ",
496	["μ"] = "Μ",
497	["ν"] = "Ν",
498	["ξ"] = "Ξ",
499	["ο"] = "Ο",
500	["π"] = "Π",
501	["ρ"] = "Ρ",
502	["ς"] = "Σ",
503	["σ"] = "Σ",
504	["τ"] = "Τ",
505	["υ"] = "Υ",
506	["φ"] = "Φ",
507	["χ"] = "Χ",
508	["ψ"] = "Ψ",
509	["ω"] = "Ω",
510	["ϊ"] = "Ϊ",
511	["ϋ"] = "Ϋ",
512	["ό"] = "Ό",
513	["ύ"] = "Ύ",
514	["ώ"] = "Ώ",
515	["ϐ"] = "Β",
516	["ϑ"] = "Θ",
517	["ϕ"] = "Φ",
518	["ϖ"] = "Π",
519	["ϙ"] = "Ϙ",
520	["ϛ"] = "Ϛ",
521	["ϝ"] = "Ϝ",
522	["ϟ"] = "Ϟ",
523	["ϡ"] = "Ϡ",
524	["ϣ"] = "Ϣ",
525	["ϥ"] = "Ϥ",
526	["ϧ"] = "Ϧ",
527	["ϩ"] = "Ϩ",
528	["ϫ"] = "Ϫ",
529	["ϭ"] = "Ϭ",
530	["ϯ"] = "Ϯ",
531	["ϰ"] = "Κ",
532	["ϱ"] = "Ρ",
533	["ϲ"] = "Ϲ",
534	["ϵ"] = "Ε",
535	["ϸ"] = "Ϸ",
536	["ϻ"] = "Ϻ",
537	["а"] = "А",
538	["б"] = "Б",
539	["в"] = "В",
540	["г"] = "Г",
541	["д"] = "Д",
542	["е"] = "Е",
543	["ж"] = "Ж",
544	["з"] = "З",
545	["и"] = "И",
546	["й"] = "Й",
547	["к"] = "К",
548	["л"] = "Л",
549	["м"] = "М",
550	["н"] = "Н",
551	["о"] = "О",
552	["п"] = "П",
553	["р"] = "Р",
554	["с"] = "С",
555	["т"] = "Т",
556	["у"] = "У",
557	["ф"] = "Ф",
558	["х"] = "Х",
559	["ц"] = "Ц",
560	["ч"] = "Ч",
561	["ш"] = "Ш",
562	["щ"] = "Щ",
563	["ъ"] = "Ъ",
564	["ы"] = "Ы",
565	["ь"] = "Ь",
566	["э"] = "Э",
567	["ю"] = "Ю",
568	["я"] = "Я",
569	["ѐ"] = "Ѐ",
570	["ё"] = "Ё",
571	["ђ"] = "Ђ",
572	["ѓ"] = "Ѓ",
573	["є"] = "Є",
574	["ѕ"] = "Ѕ",
575	["і"] = "І",
576	["ї"] = "Ї",
577	["ј"] = "Ј",
578	["љ"] = "Љ",
579	["њ"] = "Њ",
580	["ћ"] = "Ћ",
581	["ќ"] = "Ќ",
582	["ѝ"] = "Ѝ",
583	["ў"] = "Ў",
584	["џ"] = "Џ",
585	["ѡ"] = "Ѡ",
586	["ѣ"] = "Ѣ",
587	["ѥ"] = "Ѥ",
588	["ѧ"] = "Ѧ",
589	["ѩ"] = "Ѩ",
590	["ѫ"] = "Ѫ",
591	["ѭ"] = "Ѭ",
592	["ѯ"] = "Ѯ",
593	["ѱ"] = "Ѱ",
594	["ѳ"] = "Ѳ",
595	["ѵ"] = "Ѵ",
596	["ѷ"] = "Ѷ",
597	["ѹ"] = "Ѹ",
598	["ѻ"] = "Ѻ",
599	["ѽ"] = "Ѽ",
600	["ѿ"] = "Ѿ",
601	["ҁ"] = "Ҁ",
602	["ҋ"] = "Ҋ",
603	["ҍ"] = "Ҍ",
604	["ҏ"] = "Ҏ",
605	["ґ"] = "Ґ",
606	["ғ"] = "Ғ",
607	["ҕ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",
666	["ԋ"] = "Ԋ",
667	["ԍ"] = "Ԍ",
668	["ԏ"] = "Ԏ",
669	["ԑ"] = "Ԑ",
670	["ԓ"] = "Ԓ",
671	["ա"] = "Ա",
672	["բ"] = "Բ",
673	["գ"] = "Գ",
674	["դ"] = "Դ",
675	["ե"] = "Ե",
676	["զ"] = "Զ",
677	["է"] = "Է",
678	["ը"] = "Ը",
679	["թ"] = "Թ",
680	["ժ"] = "Ժ",
681	["ի"] = "Ի",
682	["լ"] = "Լ",
683	["խ"] = "Խ",
684	["ծ"] = "Ծ",
685	["կ"] = "Կ",
686	["հ"] = "Հ",
687	["ձ"] = "Ձ",
688	["ղ"] = "Ղ",
689	["ճ"] = "Ճ",
690	["մ"] = "Մ",
691	["յ"] = "Յ",
692	["ն"] = "Ն",
693	["շ"] = "Շ",
694	["ո"] = "Ո",
695	["չ"] = "Չ",
696	["պ"] = "Պ",
697	["ջ"] = "Ջ",
698	["ռ"] = "Ռ",
699	["ս"] = "Ս",
700	["վ"] = "Վ",
701	["տ"] = "Տ",
702	["ր"] = "Ր",
703	["ց"] = "Ց",
704	["ւ"] = "Ւ",
705	["փ"] = "Փ",
706	["ք"] = "Ք",
707	["օ"] = "Օ",
708	["ֆ"] = "Ֆ",
709	["ᵽ"] = "Ᵽ",
710	["ḁ"] = "Ḁ",
711	["ḃ"] = "Ḃ",
712	["ḅ"] = "Ḅ",
713	["ḇ"] = "Ḇ",
714	["ḉ"] = "Ḉ",
715	["ḋ"] = "Ḋ",
716	["ḍ"] = "Ḍ",
717	["ḏ"] = "Ḏ",
718	["ḑ"] = "Ḑ",
719	["ḓ"] = "Ḓ",
720	["ḕ"] = "Ḕ",
721	["ḗ"] = "Ḗ",
722	["ḙ"] = "Ḙ",
723	["ḛ"] = "Ḛ",
724	["ḝ"] = "Ḝ",
725	["ḟ"] = "Ḟ",
726	["ḡ"] = "Ḡ",
727	["ḣ"] = "Ḣ",
728	["ḥ"] = "Ḥ",
729	["ḧ"] = "Ḧ",
730	["ḩ"] = "Ḩ",
731	["ḫ"] = "Ḫ",
732	["ḭ"] = "Ḭ",
733	["ḯ"] = "Ḯ",
734	["ḱ"] = "Ḱ",
735	["ḳ"] = "Ḳ",
736	["ḵ"] = "Ḵ",
737	["ḷ"] = "Ḷ",
738	["ḹ"] = "Ḹ",
739	["ḻ"] = "Ḻ",
740	["ḽ"] = "Ḽ",
741	["ḿ"] = "Ḿ",
742	["ṁ"] = "Ṁ",
743	["ṃ"] = "Ṃ",
744	["ṅ"] = "Ṅ",
745	["ṇ"] = "Ṇ",
746	["ṉ"] = "Ṉ",
747	["ṋ"] = "Ṋ",
748	["ṍ"] = "Ṍ",
749	["ṏ"] = "Ṏ",
750	["ṑ"] = "Ṑ",
751	["ṓ"] = "Ṓ",
752	["ṕ"] = "Ṕ",
753	["ṗ"] = "Ṗ",
754	["ṙ"] = "Ṙ",
755	["ṛ"] = "Ṛ",
756	["ṝ"] = "Ṝ",
757	["ṟ"] = "Ṟ",
758	["ṡ"] = "Ṡ",
759	["ṣ"] = "Ṣ",
760	["ṥ"] = "Ṥ",
761	["ṧ"] = "Ṧ",
762	["ṩ"] = "Ṩ",
763	["ṫ"] = "Ṫ",
764	["ṭ"] = "Ṭ",
765	["ṯ"] = "Ṯ",
766	["ṱ"] = "Ṱ",
767	["ṳ"] = "Ṳ",
768	["ṵ"] = "Ṵ",
769	["ṷ"] = "Ṷ",
770	["ṹ"] = "Ṹ",
771	["ṻ"] = "Ṻ",
772	["ṽ"] = "Ṽ",
773	["ṿ"] = "Ṿ",
774	["ẁ"] = "Ẁ",
775	["ẃ"] = "Ẃ",
776	["ẅ"] = "Ẅ",
777	["ẇ"] = "Ẇ",
778	["ẉ"] = "Ẉ",
779	["ẋ"] = "Ẋ",
780	["ẍ"] = "Ẍ",
781	["ẏ"] = "Ẏ",
782	["ẑ"] = "Ẑ",
783	["ẓ"] = "Ẓ",
784	["ẕ"] = "Ẕ",
785	["ẛ"] = "Ṡ",
786	["ạ"] = "Ạ",
787	["ả"] = "Ả",
788	["ấ"] = "Ấ",
789	["ầ"] = "Ầ",
790	["ẩ"] = "Ẩ",
791	["ẫ"] = "Ẫ",
792	["ậ"] = "Ậ",
793	["ắ"] = "Ắ",
794	["ằ"] = "Ằ",
795	["ẳ"] = "Ẳ",
796	["ẵ"] = "Ẵ",
797	["ặ"] = "Ặ",
798	["ẹ"] = "Ẹ",
799	["ẻ"] = "Ẻ",
800	["ẽ"] = "Ẽ",
801	["ế"] = "Ế",
802	["ề"] = "Ề",
803	["ể"] = "Ể",
804	["ễ"] = "Ễ",
805	["ệ"] = "Ệ",
806	["ỉ"] = "Ỉ",
807	["ị"] = "Ị",
808	["ọ"] = "Ọ",
809	["ỏ"] = "Ỏ",
810	["ố"] = "Ố",
811	["ồ"] = "Ồ",
812	["ổ"] = "Ổ",
813	["ỗ"] = "Ỗ",
814	["ộ"] = "Ộ",
815	["ớ"] = "Ớ",
816	["ờ"] = "Ờ",
817	["ở"] = "Ở",
818	["ỡ"] = "Ỡ",
819	["ợ"] = "Ợ",
820	["ụ"] = "Ụ",
821	["ủ"] = "Ủ",
822	["ứ"] = "Ứ",
823	["ừ"] = "Ừ",
824	["ử"] = "Ử",
825	["ữ"] = "Ữ",
826	["ự"] = "Ự",
827	["ỳ"] = "Ỳ",
828	["ỵ"] = "Ỵ",
829	["ỷ"] = "Ỷ",
830	["ỹ"] = "Ỹ",
831	["ἀ"] = "Ἀ",
832	["ἁ"] = "Ἁ",
833	["ἂ"] = "Ἂ",
834	["ἃ"] = "Ἃ",
835	["ἄ"] = "Ἄ",
836	["ἅ"] = "Ἅ",
837	["ἆ"] = "Ἆ",
838	["ἇ"] = "Ἇ",
839	["ἐ"] = "Ἐ",
840	["ἑ"] = "Ἑ",
841	["ἒ"] = "Ἒ",
842	["ἓ"] = "Ἓ",
843	["ἔ"] = "Ἔ",
844	["ἕ"] = "Ἕ",
845	["ἠ"] = "Ἠ",
846	["ἡ"] = "Ἡ",
847	["ἢ"] = "Ἢ",
848	["ἣ"] = "Ἣ",
849	["ἤ"] = "Ἤ",
850	["ἥ"] = "Ἥ",
851	["ἦ"] = "Ἦ",
852	["ἧ"] = "Ἧ",
853	["ἰ"] = "Ἰ",
854	["ἱ"] = "Ἱ",
855	["ἲ"] = "Ἲ",
856	["ἳ"] = "Ἳ",
857	["ἴ"] = "Ἴ",
858	["ἵ"] = "Ἵ",
859	["ἶ"] = "Ἶ",
860	["ἷ"] = "Ἷ",
861	["ὀ"] = "Ὀ",
862	["ὁ"] = "Ὁ",
863	["ὂ"] = "Ὂ",
864	["ὃ"] = "Ὃ",
865	["ὄ"] = "Ὄ",
866	["ὅ"] = "Ὅ",
867	["ὑ"] = "Ὑ",
868	["ὓ"] = "Ὓ",
869	["ὕ"] = "Ὕ",
870	["ὗ"] = "Ὗ",
871	["ὠ"] = "Ὠ",
872	["ὡ"] = "Ὡ",
873	["ὢ"] = "Ὢ",
874	["ὣ"] = "Ὣ",
875	["ὤ"] = "Ὤ",
876	["ὥ"] = "Ὥ",
877	["ὦ"] = "Ὦ",
878	["ὧ"] = "Ὧ",
879	["ὰ"] = "Ὰ",
880	["ά"] = "Ά",
881	["ὲ"] = "Ὲ",
882	["έ"] = "Έ",
883	["ὴ"] = "Ὴ",
884	["ή"] = "Ή",
885	["ὶ"] = "Ὶ",
886	["ί"] = "Ί",
887	["ὸ"] = "Ὸ",
888	["ό"] = "Ό",
889	["ὺ"] = "Ὺ",
890	["ύ"] = "Ύ",
891	["ὼ"] = "Ὼ",
892	["ώ"] = "Ώ",
893	["ᾀ"] = "ᾈ",
894	["ᾁ"] = "ᾉ",
895	["ᾂ"] = "ᾊ",
896	["ᾃ"] = "ᾋ",
897	["ᾄ"] = "ᾌ",
898	["ᾅ"] = "ᾍ",
899	["ᾆ"] = "ᾎ",
900	["ᾇ"] = "ᾏ",
901	["ᾐ"] = "ᾘ",
902	["ᾑ"] = "ᾙ",
903	["ᾒ"] = "ᾚ",
904	["ᾓ"] = "ᾛ",
905	["ᾔ"] = "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1107	["ⴟ"] = "Ⴟ",
1108	["ⴠ"] = "Ⴠ",
1109	["ⴡ"] = "Ⴡ",
1110	["ⴢ"] = "Ⴢ",
1111	["ⴣ"] = "Ⴣ",
1112	["ⴤ"] = "Ⴤ",
1113	["ⴥ"] = "Ⴥ",
1114	["a"] = "A",
1115	["b"] = "B",
1116	["c"] = "C",
1117	["d"] = "D",
1118	["e"] = "E",
1119	["f"] = "F",
1120	["g"] = "G",
1121	["h"] = "H",
1122	["i"] = "I",
1123	["j"] = "J",
1124	["k"] = "K",
1125	["l"] = "L",
1126	["m"] = "M",
1127	["n"] = "N",
1128	["o"] = "O",
1129	["p"] = "P",
1130	["q"] = "Q",
1131	["r"] = "R",
1132	["s"] = "S",
1133	["t"] = "T",
1134	["u"] = "U",
1135	["v"] = "V",
1136	["w"] = "W",
1137	["x"] = "X",
1138	["y"] = "Y",
1139	["z"] = "Z",
1140	["𐐨"] = "𐐀",
1141	["𐐩"] = "𐐁",
1142	["𐐪"] = "𐐂",
1143	["𐐫"] = "𐐃",
1144	["𐐬"] = "𐐄",
1145	["𐐭"] = "𐐅",
1146	["𐐮"] = "𐐆",
1147	["𐐯"] = "𐐇",
1148	["𐐰"] = "𐐈",
1149	["𐐱"] = "𐐉",
1150	["𐐲"] = "𐐊",
1151	["𐐳"] = "𐐋",
1152	["𐐴"] = "𐐌",
1153	["𐐵"] = "𐐍",
1154	["𐐶"] = "𐐎",
1155	["𐐷"] = "𐐏",
1156	["𐐸"] = "𐐐",
1157	["𐐹"] = "𐐑",
1158	["𐐺"] = "𐐒",
1159	["𐐻"] = "𐐓",
1160	["𐐼"] = "𐐔",
1161	["𐐽"] = "𐐕",
1162	["𐐾"] = "𐐖",
1163	["𐐿"] = "𐐗",
1164	["𐑀"] = "𐐘",
1165	["𐑁"] = "𐐙",
1166	["𐑂"] = "𐐚",
1167	["𐑃"] = "𐐛",
1168	["𐑄"] = "𐐜",
1169	["𐑅"] = "𐐝",
1170	["𐑆"] = "𐐞",
1171	["𐑇"] = "𐐟",
1172	["𐑈"] = "𐐠",
1173	["𐑉"] = "𐐡",
1174	["𐑊"] = "𐐢",
1175	["𐑋"] = "𐐣",
1176	["𐑌"] = "𐐤",
1177	["𐑍"] = "𐐥",
1178	["𐑎"] = "𐐦",
1179	["𐑏"] = "𐐧",
1180}
1181
1182local utf8_uc_lc = {
1183	["A"] = "a",
1184	["B"] = "b",
1185	["C"] = "c",
1186	["D"] = "d",
1187	["E"] = "e",
1188	["F"] = "f",
1189	["G"] = "g",
1190	["H"] = "h",
1191	["I"] = "i",
1192	["J"] = "j",
1193	["K"] = "k",
1194	["L"] = "l",
1195	["M"] = "m",
1196	["N"] = "n",
1197	["O"] = "o",
1198	["P"] = "p",
1199	["Q"] = "q",
1200	["R"] = "r",
1201	["S"] = "s",
1202	["T"] = "t",
1203	["U"] = "u",
1204	["V"] = "v",
1205	["W"] = "w",
1206	["X"] = "x",
1207	["Y"] = "y",
1208	["Z"] = "z",
1209	["À"] = "à",
1210	["Á"] = "á",
1211	["Â"] = "â",
1212	["Ã"] = "ã",
1213	["Ä"] = "ä",
1214	["Å"] = "å",
1215	["Æ"] = "æ",
1216	["Ç"] = "ç",
1217	["È"] = "è",
1218	["É"] = "é",
1219	["Ê"] = "ê",
1220	["Ë"] = "ë",
1221	["Ì"] = "ì",
1222	["Í"] = "í",
1223	["Î"] = "î",
1224	["Ï"] = "ï",
1225	["Ð"] = "ð",
1226	["Ñ"] = "ñ",
1227	["Ò"] = "ò",
1228	["Ó"] = "ó",
1229	["Ô"] = "ô",
1230	["Õ"] = "õ",
1231	["Ö"] = "ö",
1232	["Ø"] = "ø",
1233	["Ù"] = "ù",
1234	["Ú"] = "ú",
1235	["Û"] = "û",
1236	["Ü"] = "ü",
1237	["Ý"] = "ý",
1238	["Þ"] = "þ",
1239	["Ā"] = "ā",
1240	["Ă"] = "ă",
1241	["Ą"] = "ą",
1242	["Ć"] = "ć",
1243	["Ĉ"] = "ĉ",
1244	["Ċ"] = "ċ",
1245	["Č"] = "č",
1246	["Ď"] = "ď",
1247	["Đ"] = "đ",
1248	["Ē"] = "ē",
1249	["Ĕ"] = "ĕ",
1250	["Ė"] = "ė",
1251	["Ę"] = "ę",
1252	["Ě"] = "ě",
1253	["Ĝ"] = "ĝ",
1254	["Ğ"] = "ğ",
1255	["Ġ"] = "ġ",
1256	["Ģ"] = "ģ",
1257	["Ĥ"] = "ĥ",
1258	["Ħ"] = "ħ",
1259	["Ĩ"] = "ĩ",
1260	["Ī"] = "ī",
1261	["Ĭ"] = "ĭ",
1262	["Į"] = "į",
1263	["İ"] = "i",
1264	["IJ"] = "ij",
1265	["Ĵ"] = "ĵ",
1266	["Ķ"] = "ķ",
1267	["Ĺ"] = "ĺ",
1268	["Ļ"] = "ļ",
1269	["Ľ"] = "ľ",
1270	["Ŀ"] = "ŀ",
1271	["Ł"] = "ł",
1272	["Ń"] = "ń",
1273	["Ņ"] = "ņ",
1274	["Ň"] = "ň",
1275	["Ŋ"] = "ŋ",
1276	["Ō"] = "ō",
1277	["Ŏ"] = "ŏ",
1278	["Ő"] = "ő",
1279	["Œ"] = "œ",
1280	["Ŕ"] = "ŕ",
1281	["Ŗ"] = "ŗ",
1282	["Ř"] = "ř",
1283	["Ś"] = "ś",
1284	["Ŝ"] = "ŝ",
1285	["Ş"] = "ş",
1286	["Š"] = "š",
1287	["Ţ"] = "ţ",
1288	["Ť"] = "ť",
1289	["Ŧ"] = "ŧ",
1290	["Ũ"] = "ũ",
1291	["Ū"] = "ū",
1292	["Ŭ"] = "ŭ",
1293	["Ů"] = "ů",
1294	["Ű"] = "ű",
1295	["Ų"] = "ų",
1296	["Ŵ"] = "ŵ",
1297	["Ŷ"] = "ŷ",
1298	["Ÿ"] = "ÿ",
1299	["Ź"] = "ź",
1300	["Ż"] = "ż",
1301	["Ž"] = "ž",
1302	["Ɓ"] = "ɓ",
1303	["Ƃ"] = "ƃ",
1304	["Ƅ"] = "ƅ",
1305	["Ɔ"] = "ɔ",
1306	["Ƈ"]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] = "dz",
1363	["Ǵ"] = "ǵ",
1364	["Ƕ"] = "ƕ",
1365	["Ƿ"] = "ƿ",
1366	["Ǹ"] = "ǹ",
1367	["Ǻ"] = "ǻ",
1368	["Ǽ"] = "ǽ",
1369	["Ǿ"] = "ǿ",
1370	["Ȁ"] = "ȁ",
1371	["Ȃ"] = "ȃ",
1372	["Ȅ"] = "ȅ",
1373	["Ȇ"] = "ȇ",
1374	["Ȉ"] = "ȉ",
1375	["Ȋ"] = "ȋ",
1376	["Ȍ"] = "ȍ",
1377	["Ȏ"] = "ȏ",
1378	["Ȑ"] = "ȑ",
1379	["Ȓ"] = "ȓ",
1380	["Ȕ"] = "ȕ",
1381	["Ȗ"] = "ȗ",
1382	["Ș"] = "ș",
1383	["Ț"] = "ț",
1384	["Ȝ"] = "ȝ",
1385	["Ȟ"] = "ȟ",
1386	["Ƞ"] = "ƞ",
1387	["Ȣ"] = "ȣ",
1388	["Ȥ"] = "ȥ",
1389	["Ȧ"] = "ȧ",
1390	["Ȩ"] = "ȩ",
1391	["Ȫ"] = "ȫ",
1392	["Ȭ"] = "ȭ",
1393	["Ȯ"] = "ȯ",
1394	["Ȱ"] = "ȱ",
1395	["Ȳ"] = "ȳ",
1396	["Ⱥ"] = "ⱥ",
1397	["Ȼ"] = "ȼ",
1398	["Ƚ"] = "ƚ",
1399	["Ⱦ"] = "ⱦ",
1400	["Ɂ"] = "ɂ",
1401	["Ƀ"] = "ƀ",
1402	["Ʉ"] = "ʉ",
1403	["Ʌ"] = "ʌ",
1404	["Ɇ"] = "ɇ",
1405	["Ɉ"] = "ɉ",
1406	["Ɋ"] = "ɋ",
1407	["Ɍ"] = "ɍ",
1408	["Ɏ"] = "ɏ",
1409	["Ά"] = "ά",
1410	["Έ"] = "έ",
1411	["Ή"] = "ή",
1412	["Ί"] = "ί",
1413	["Ό"] = "ό",
1414	["Ύ"] = "ύ",
1415	["Ώ"] = "ώ",
1416	["Α"] = "α",
1417	["Β"] = "β",
1418	["Γ"] = "γ",
1419	["Δ"] = "δ",
1420	["Ε"] = "ε",
1421	["Ζ"] = "ζ",
1422	["Η"] = "η",
1423	["Θ"] = "θ",
1424	["Ι"] = "ι",
1425	["Κ"] = "κ",
1426	["Λ"] = "λ",
1427	["Μ"] = "μ",
1428	["Ν"] = "ν",
1429	["Ξ"] = "ξ",
1430	["Ο"] = "ο",
1431	["Π"] = "π",
1432	["Ρ"] = "ρ",
1433	["Σ"] = "σ",
1434	["Τ"] = "τ",
1435	["Υ"] = "υ",
1436	["Φ"] = "φ",
1437	["Χ"] = "χ",
1438	["Ψ"] = "ψ",
1439	["Ω"] = "ω",
1440	["Ϊ"] = "ϊ",
1441	["Ϋ"] = "ϋ",
1442	["Ϙ"] = "ϙ",
1443	["Ϛ"] = "ϛ",
1444	["Ϝ"] = "ϝ",
1445	["Ϟ"] = "ϟ",
1446	["Ϡ"] = "ϡ",
1447	["Ϣ"] = "ϣ",
1448	["Ϥ"] = "ϥ",
1449	["Ϧ"] = "ϧ",
1450	["Ϩ"] = "ϩ",
1451	["Ϫ"] = "ϫ",
1452	["Ϭ"] = "ϭ",
1453	["Ϯ"] = "ϯ",
1454	["ϴ"] = "θ",
1455	["Ϸ"] = "ϸ",
1456	["Ϲ"] = "ϲ",
1457	["Ϻ"] = "ϻ",
1458	["Ͻ"] = "ͻ",
1459	["Ͼ"] = "ͼ",
1460	["Ͽ"] = "ͽ",
1461	["Ѐ"] = "ѐ",
1462	["Ё"] = "ё",
1463	["Ђ"] = "ђ",
1464	["Ѓ"] = "ѓ",
1465	["Є"] = "є",
1466	["Ѕ"] = "ѕ",
1467	["І"] = "і",
1468	["Ї"] = "ї",
1469	["Ј"] = "ј",
1470	["Љ"] = "љ",
1471	["Њ"] = "њ",
1472	["Ћ"] = "ћ",
1473	["Ќ"] = "ќ",
1474	["Ѝ"] = "ѝ",
1475	["Ў"] = "ў",
1476	["Џ"] = "џ",
1477	["А"] = "а",
1478	["Б"] = "б",
1479	["В"] = "в",
1480	["Г"] = "г",
1481	["Д"] = "д",
1482	["Е"] = "е",
1483	["Ж"] = "ж",
1484	["З"] = "з",
1485	["И"] = "и",
1486	["Й"] = "й",
1487	["К"] = "к",
1488	["Л"] = "л",
1489	["М"] = "м",
1490	["Н"] = "н",
1491	["О"] = "о",
1492	["П"] = "п",
1493	["Р"] = "р",
1494	["С"] = "с",
1495	["Т"] = "т",
1496	["У"] = "у",
1497	["Ф"] = "ф",
1498	["Х"] = "х",
1499	["Ц"] = "ц",
1500	["Ч"] = "ч",
1501	["Ш"] = "ш",
1502	["Щ"] = "щ",
1503	["Ъ"] = "ъ",
1504	["Ы"] = "ы",
1505	["Ь"] = "ь",
1506	["Э"] = "э",
1507	["Ю"] = "ю",
1508	["Я"] = "я",
1509	["Ѡ"] = "ѡ",
1510	["Ѣ"] = "ѣ",
1511	["Ѥ"] = "ѥ",
1512	["Ѧ"] = "ѧ",
1513	["Ѩ"] = "ѩ",
1514	["Ѫ"] = "ѫ",
1515	["Ѭ"] = "ѭ",
1516	["Ѯ"] = "ѯ",
1517	["Ѱ"] = "ѱ",
1518	["Ѳ"] = "ѳ",
1519	["Ѵ"] = "ѵ",
1520	["Ѷ"] = "ѷ",
1521	["Ѹ"] = "ѹ",
1522	["Ѻ"] = "ѻ",
1523	["Ѽ"] = "ѽ",
1524	["Ѿ"] = "ѿ",
1525	["Ҁ"] = "ҁ",
1526	["Ҋ"] = "ҋ",
1527	["Ҍ"] = "ҍ",
1528	["Ҏ"] = "ҏ",
1529	["Ґ"] = "ґ",
1530	["Ғ"] = "ғ",
1531	["Ҕ"] = "ҕ",
1532	["Җ"] = "җ",
1533	["Ҙ"] = "ҙ",
1534	["Қ"] = "қ",
1535	["Ҝ"] = "ҝ",
1536	["Ҟ"] = "ҟ",
1537	["Ҡ"] = "ҡ",
1538	["Ң"] = "ң",
1539	["Ҥ"] = "ҥ",
1540	["Ҧ"] = "ҧ",
1541	["Ҩ"] = "ҩ",
1542	["Ҫ"] = "ҫ",
1543	["Ҭ"] = "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= "ե",
1600	["Զ"] = "զ",
1601	["Է"] = "է",
1602	["Ը"] = "ը",
1603	["Թ"] = "թ",
1604	["Ժ"] = "ժ",
1605	["Ի"] = "ի",
1606	["Լ"] = "լ",
1607	["Խ"] = "խ",
1608	["Ծ"] = "ծ",
1609	["Կ"] = "կ",
1610	["Հ"] = "հ",
1611	["Ձ"] = "ձ",
1612	["Ղ"] = "ղ",
1613	["Ճ"] = "ճ",
1614	["Մ"] = "մ",
1615	["Յ"] = "յ",
1616	["Ն"] = "ն",
1617	["Շ"] = "շ",
1618	["Ո"] = "ո",
1619	["Չ"] = "չ",
1620	["Պ"] = "պ",
1621	["Ջ"] = "ջ",
1622	["Ռ"] = "ռ",
1623	["Ս"] = "ս",
1624	["Վ"] = "վ",
1625	["Տ"] = "տ",
1626	["Ր"] = "ր",
1627	["Ց"] = "ց",
1628	["Ւ"] = "ւ",
1629	["Փ"] = "փ",
1630	["Ք"] = "ք",
1631	["Օ"] = "օ",
1632	["Ֆ"] = "ֆ",
1633	["Ⴀ"] = "ⴀ",
1634	["Ⴁ"] = "ⴁ",
1635	["Ⴂ"] = "ⴂ",
1636	["Ⴃ"] = "ⴃ",
1637	["Ⴄ"] = "ⴄ",
1638	["Ⴅ"] = "ⴅ",
1639	["Ⴆ"] = "ⴆ",
1640	["Ⴇ"] = "ⴇ",
1641	["Ⴈ"] = "ⴈ",
1642	["Ⴉ"] = "ⴉ",
1643	["Ⴊ"] = "ⴊ",
1644	["Ⴋ"] = "ⴋ",
1645	["Ⴌ"] = "ⴌ",
1646	["Ⴍ"] = "ⴍ",
1647	["Ⴎ"] = "ⴎ",
1648	["Ⴏ"] = "ⴏ",
1649	["Ⴐ"] = "ⴐ",
1650	["Ⴑ"] = "ⴑ",
1651	["Ⴒ"] = "ⴒ",
1652	["Ⴓ"] = "ⴓ",
1653	["Ⴔ"] = "ⴔ",
1654	["Ⴕ"] = "ⴕ",
1655	["Ⴖ"] = "ⴖ",
1656	["Ⴗ"] = "ⴗ",
1657	["Ⴘ"] = "ⴘ",
1658	["Ⴙ"] = "ⴙ",
1659	["Ⴚ"] = "ⴚ",
1660	["Ⴛ"] = "ⴛ",
1661	["Ⴜ"] = "ⴜ",
1662	["Ⴝ"] = "ⴝ",
1663	["Ⴞ"] = "ⴞ",
1664	["Ⴟ"] = "ⴟ",
1665	["Ⴠ"] = "ⴠ",
1666	["Ⴡ"] = "ⴡ",
1667	["Ⴢ"] = "ⴢ",
1668	["Ⴣ"] = "ⴣ",
1669	["Ⴤ"] = "ⴤ",
1670	["Ⴥ"] = "ⴥ",
1671	["Ḁ"] = "ḁ",
1672	["Ḃ"] = "ḃ",
1673	["Ḅ"] = "ḅ",
1674	["Ḇ"] = "ḇ",
1675	["Ḉ"] = "ḉ",
1676	["Ḋ"] = "ḋ",
1677	["Ḍ"] = "ḍ",
1678	["Ḏ"] = "ḏ",
1679	["Ḑ"] = "ḑ",
1680	["Ḓ"] = "ḓ",
1681	["Ḕ"] = "ḕ",
1682	["Ḗ"] = "ḗ",
1683	["Ḙ"] = "ḙ",
1684	["Ḛ"] = "ḛ",
1685	["Ḝ"] = "ḝ",
1686	["Ḟ"] = "ḟ",
1687	["Ḡ"] = "ḡ",
1688	["Ḣ"] = "ḣ",
1689	["Ḥ"] = "ḥ",
1690	["Ḧ"] = "ḧ",
1691	["Ḩ"] = "ḩ",
1692	["Ḫ"] = "ḫ",
1693	["Ḭ"] = "ḭ",
1694	["Ḯ"] = "ḯ",
1695	["Ḱ"] = "ḱ",
1696	["Ḳ"] = "ḳ",
1697	["Ḵ"] = "ḵ",
1698	["Ḷ"] = "ḷ",
1699	["Ḹ"] = "ḹ",
1700	["Ḻ"] = "ḻ",
1701	["Ḽ"] = "ḽ",
1702	["Ḿ"] = "ḿ",
1703	["Ṁ"] = "ṁ",
1704	["Ṃ"] = "ṃ",
1705	["Ṅ"] = "ṅ",
1706	["Ṇ"] = "ṇ",
1707	["Ṉ"] = "ṉ",
1708	["Ṋ"] = "ṋ",
1709	["Ṍ"] = "ṍ",
1710	["Ṏ"] = "ṏ",
1711	["Ṑ"] = "ṑ",
1712	["Ṓ"] = "ṓ",
1713	["Ṕ"] = "ṕ",
1714	["Ṗ"] = "ṗ",
1715	["Ṙ"] = "ṙ",
1716	["Ṛ"] = "ṛ",
1717	["Ṝ"] = "ṝ",
1718	["Ṟ"] = "ṟ",
1719	["Ṡ"] = "ṡ",
1720	["Ṣ"] = "ṣ",
1721	["Ṥ"] = "ṥ",
1722	["Ṧ"] = "ṧ",
1723	["Ṩ"] = "ṩ",
1724	["Ṫ"] = "ṫ",
1725	["Ṭ"] = "ṭ",
1726	["Ṯ"] = "ṯ",
1727	["Ṱ"] = "ṱ",
1728	["Ṳ"] = "ṳ",
1729	["Ṵ"] = "ṵ",
1730	["Ṷ"] = "ṷ",
1731	["Ṹ"] = "ṹ",
1732	["Ṻ"] = "ṻ",
1733	["Ṽ"] = "ṽ",
1734	["Ṿ"] = "ṿ",
1735	["Ẁ"] = "ẁ",
1736	["Ẃ"] = "ẃ",
1737	["Ẅ"] = "ẅ",
1738	["Ẇ"] = "ẇ",
1739	["Ẉ"] = "ẉ",
1740	["Ẋ"] = "ẋ",
1741	["Ẍ"] = "ẍ",
1742	["Ẏ"] = "ẏ",
1743	["Ẑ"] = "ẑ",
1744	["Ẓ"] = "ẓ",
1745	["Ẕ"] = "ẕ",
1746	["Ạ"] = "ạ",
1747	["Ả"] = "ả",
1748	["Ấ"] = "ấ",
1749	["Ầ"] = "ầ",
1750	["Ẩ"] = "ẩ",
1751	["Ẫ"] = "ẫ",
1752	["Ậ"] = "ậ",
1753	["Ắ"] = "ắ",
1754	["Ằ"] = "ằ",
1755	["Ẳ"] = "ẳ",
1756	["Ẵ"] = "ẵ",
1757	["Ặ"] = "ặ",
1758	["Ẹ"] = "ẹ",
1759	["Ẻ"] = "ẻ",
1760	["Ẽ"] = "ẽ",
1761	["Ế"] = "ế",
1762	["Ề"] = "ề",
1763	["Ể"] = "ể",
1764	["Ễ"] = "ễ",
1765	["Ệ"] = "ệ",
1766	["Ỉ"] = "ỉ",
1767	["Ị"] = "ị",
1768	["Ọ"] = "ọ",
1769	["Ỏ"] = "ỏ",
1770	["Ố"] = "ố",
1771	["Ồ"] = "ồ",
1772	["Ổ"] = "ổ",
1773	["Ỗ"] = "ỗ",
1774	["Ộ"] = "ộ",
1775	["Ớ"] = "ớ",
1776	["Ờ"] = "ờ",
1777	["Ở"] = "ở",
1778	["Ỡ"] = "ỡ",
1779	["Ợ"] = "ợ",
1780	["Ụ"] = "ụ",
1781	["Ủ"] = "ủ",
1782	["Ứ"] = "ứ",
1783	["Ừ"] = "ừ",
1784	["Ử"] = "ử",
1785	["Ữ"] = "ữ",
1786	["Ự"] = "ự",
1787	["Ỳ"] = "ỳ",
1788	["Ỵ"] = "ỵ",
1789	["Ỷ"] = "ỷ",
1790	["Ỹ"] = "ỹ",
1791	["Ἀ"] = "ἀ",
1792	["Ἁ"] = "ἁ",
1793	["Ἂ"] = "ἂ",
1794	["Ἃ"] = "ἃ",
1795	["Ἄ"] = "ἄ",
1796	["Ἅ"] = "ἅ",
1797	["Ἆ"] = "ἆ",
1798	["Ἇ"] = "ἇ",
1799	["Ἐ"] = "ἐ",
1800	["Ἑ"] = "ἑ",
1801	["Ἒ"] = "ἒ",
1802	["Ἓ"] = "ἓ",
1803	["Ἔ"] = "ἔ",
1804	["Ἕ"] = "ἕ",
1805	["Ἠ"] = "ἠ",
1806	["Ἡ"] = "ἡ",
1807	["Ἢ"] = "ἢ",
1808	["Ἣ"] = "ἣ",
1809	["Ἤ"] = "ἤ",
1810	["Ἥ"] = "ἥ",
1811	["Ἦ"] = "ἦ",
1812	["Ἧ"] = "ἧ",
1813	["Ἰ"] = "ἰ",
1814	["Ἱ"] = "ἱ",
1815	["Ἲ"] = "ἲ",
1816	["Ἳ"] = "ἳ",
1817	["Ἴ"] = "ἴ",
1818	["Ἵ"] = "ἵ",
1819	["Ἶ"] = "ἶ",
1820	["Ἷ"] = "ἷ",
1821	["Ὀ"] = "ὀ",
1822	["Ὁ"] = "ὁ",
1823	["Ὂ"] = "ὂ",
1824	["Ὃ"] = "ὃ",
1825	["Ὄ"] = "ὄ",
1826	["Ὅ"] = "ὅ",
1827	["Ὑ"] = "ὑ",
1828	["Ὓ"] = "ὓ",
1829	["Ὕ"] = "ὕ",
1830	["Ὗ"] = "ὗ",
1831	["Ὠ"] = "ὠ",
1832	["Ὡ"] = "ὡ",
1833	["Ὢ"] = "ὢ",
1834	["Ὣ"] = "ὣ",
1835	["Ὤ"] = "ὤ",
1836	["Ὥ"] = "ὥ",
1837	["Ὦ"] = "ὦ",
1838	["Ὧ"] = "ὧ",
1839	["ᾈ"] = "ᾀ",
1840	["ᾉ"] = "ᾁ",
1841	["ᾊ"] = "ᾂ",
1842	["ᾋ"] = "ᾃ",
1843	["ᾌ"] = "ᾄ",
1844	["ᾍ"] = "ᾅ",
1845	["ᾎ"] = "ᾆ",
1846	["ᾏ"] = "ᾇ",
1847	["ᾘ"] = "ᾐ",
1848	["ᾙ"] = "ᾑ",
1849	["ᾚ"] = "ᾒ",
1850	["ᾛ"] = "ᾓ",
1851	["ᾜ"] = "ᾔ",
1852	["ᾝ"] = "ᾕ",
1853	["ᾞ"] = "ᾖ",
1854	["ᾟ"] = "ᾗ",
1855	["ᾨ"] = "ᾠ",
1856	["ᾩ"] = "ᾡ",
1857	["ᾪ"] = "ᾢ",
1858	["ᾫ"] = "ᾣ",
1859	["ᾬ"] = "ᾤ",
1860	["ᾭ"] = "ᾥ",
1861	["ᾮ"] = "ᾦ",
1862	["ᾯ"] = "ᾧ",
1863	["Ᾰ"] = "ᾰ",
1864	["Ᾱ"] = "ᾱ",
1865	["Ὰ"] = "ὰ",
1866	["Ά"] = "ά",
1867	["ᾼ"] = "ᾳ",
1868	["Ὲ"] = "ὲ",
1869	["Έ"] = "έ",
1870	["Ὴ"] = "ὴ",
1871	["Ή"] = "ή",
1872	["ῌ"] = "ῃ",
1873	["Ῐ"] = "ῐ",
1874	["Ῑ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",
2024	["Ⳇ"] = "ⳇ",
2025	["Ⳉ"] = "ⳉ",
2026	["Ⳋ"] = "ⳋ",
2027	["Ⳍ"] = "ⳍ",
2028	["Ⳏ"] = "ⳏ",
2029	["Ⳑ"] = "ⳑ",
2030	["Ⳓ"] = "ⳓ",
2031	["Ⳕ"] = "ⳕ",
2032	["Ⳗ"] = "ⳗ",
2033	["Ⳙ"] = "ⳙ",
2034	["Ⳛ"] = "ⳛ",
2035	["Ⳝ"] = "ⳝ",
2036	["Ⳟ"] = "ⳟ",
2037	["Ⳡ"] = "ⳡ",
2038	["Ⳣ"] = "ⳣ",
2039	["A"] = "a",
2040	["B"] = "b",
2041	["C"] = "c",
2042	["D"] = "d",
2043	["E"] = "e",
2044	["F"] = "f",
2045	["G"] = "g",
2046	["H"] = "h",
2047	["I"] = "i",
2048	["J"] = "j",
2049	["K"] = "k",
2050	["L"] = "l",
2051	["M"] = "m",
2052	["N"] = "n",
2053	["O"] = "o",
2054	["P"] = "p",
2055	["Q"] = "q",
2056	["R"] = "r",
2057	["S"] = "s",
2058	["T"] = "t",
2059	["U"] = "u",
2060	["V"] = "v",
2061	["W"] = "w",
2062	["X"] = "x",
2063	["Y"] = "y",
2064	["Z"] = "z",
2065	["𐐀"] = "𐐨",
2066	["𐐁"] = "𐐩",
2067	["𐐂"] = "𐐪",
2068	["𐐃"] = "𐐫",
2069	["𐐄"] = "𐐬",
2070	["𐐅"] = "𐐭",
2071	["𐐆"] = "𐐮",
2072	["𐐇"] = "𐐯",
2073	["𐐈"] = "𐐰",
2074	["𐐉"] = "𐐱",
2075	["𐐊"] = "𐐲",
2076	["𐐋"] = "𐐳",
2077	["𐐌"] = "𐐴",
2078	["𐐍"] = "𐐵",
2079	["𐐎"] = "𐐶",
2080	["𐐏"] = "𐐷",
2081	["𐐐"] = "𐐸",
2082	["𐐑"] = "𐐹",
2083	["𐐒"] = "𐐺",
2084	["𐐓"] = "𐐻",
2085	["𐐔"] = "𐐼",
2086	["𐐕"] = "𐐽",
2087	["𐐖"] = "𐐾",
2088	["𐐗"] = "𐐿",
2089	["𐐘"] = "𐑀",
2090	["𐐙"] = "𐑁",
2091	["𐐚"] = "𐑂",
2092	["𐐛"] = "𐑃",
2093	["𐐜"] = "𐑄",
2094	["𐐝"] = "𐑅",
2095	["𐐞"] = "𐑆",
2096	["𐐟"] = "𐑇",
2097	["𐐠"] = "𐑈",
2098	["𐐡"] = "𐑉",
2099	["𐐢"] = "𐑊",
2100	["𐐣"] = "𐑋",
2101	["𐐤"] = "𐑌",
2102	["𐐥"] = "𐑍",
2103	["𐐦"] = "𐑎",
2104	["𐐧"] = "𐑏",
2105}
2106
2107-- identical to string.upper except it knows about unicode simple case conversions
2108local function utf8upper (s)
2109	return utf8replace(s, utf8_lc_uc)
2110end
2111
2112-- identical to string.lower except it knows about unicode simple case conversions
2113local function utf8lower (s)
2114	return utf8replace(s, utf8_uc_lc)
2115end
2116
2117-- identical to string.reverse except that it supports UTF-8
2118local function utf8reverse (s)
2119	-- argument checking
2120	if type(s) ~= "string" then
2121		error("bad argument #1 to 'utf8.reverse' (string expected, got ".. type(s).. ")")
2122	end
2123
2124	local bytes = len(s)
2125	local pos = bytes
2126	local charbytes
2127	local newstr = ""
2128
2129	while pos > 0 do
2130		local c = byte(s, pos)
2131		while c >= 128 and c <= 191 do
2132			pos = pos - 1
2133			c = byte(s, pos)
2134		end
2135
2136		charbytes = utf8charbytes(s, pos)
2137
2138		newstr = newstr .. sub(s, pos, pos + charbytes - 1)
2139
2140		pos = pos - 1
2141	end
2142
2143	return newstr
2144end
2145
2146-- http://en.wikipedia.org/wiki/Utf8
2147-- http://developer.coronalabs.com/code/utf-8-conversion-utility
2148local function utf8char(unicode)
2149	if unicode <= 0x7F then return char(unicode) end
2150
2151	if (unicode <= 0x7FF) then
2152		local Byte0 = 0xC0 + math.floor(unicode / 0x40);
2153		local Byte1 = 0x80 + (unicode % 0x40);
2154		return char(Byte0, Byte1);
2155	end;
2156
2157	if (unicode <= 0xFFFF) then
2158		local Byte0 = 0xE0 +  math.floor(unicode / 0x1000);
2159		local Byte1 = 0x80 + (math.floor(unicode / 0x40) % 0x40);
2160		local Byte2 = 0x80 + (unicode % 0x40);
2161		return char(Byte0, Byte1, Byte2);
2162	end;
2163
2164	if (unicode <= 0x10FFFF) then
2165		local code = unicode
2166		local Byte3= 0x80 + (code % 0x40);
2167		code       = math.floor(code / 0x40)
2168		local Byte2= 0x80 + (code % 0x40);
2169		code       = math.floor(code / 0x40)
2170		local Byte1= 0x80 + (code % 0x40);
2171		code       = math.floor(code / 0x40)
2172		local Byte0= 0xF0 + code;
2173
2174		return char(Byte0, Byte1, Byte2, Byte3);
2175	end;
2176
2177	error 'Unicode cannot be greater than U+10FFFF!'
2178end
2179
2180local shift_6  = 2^6
2181local shift_12 = 2^12
2182local shift_18 = 2^18
2183
2184local utf8unicode
2185utf8unicode = function(str, i, j, byte_pos)
2186	i = i or 1
2187	j = j or i
2188
2189	if i > j then return end
2190
2191	local ch,bytes
2192
2193	if byte_pos then
2194		bytes = utf8charbytes(str,byte_pos)
2195		ch  = sub(str,byte_pos,byte_pos-1+bytes)
2196	else
2197		ch,byte_pos = utf8sub(str,i,i), 0
2198		bytes       = #ch
2199	end
2200
2201	local unicode
2202
2203	if bytes == 1 then unicode = byte(ch) end
2204	if bytes == 2 then
2205		local byte0,byte1 = byte(ch,1,2)
2206		local code0,code1 = byte0-0xC0,byte1-0x80
2207		unicode = code0*shift_6 + code1
2208	end
2209	if bytes == 3 then
2210		local byte0,byte1,byte2 = byte(ch,1,3)
2211		local code0,code1,code2 = byte0-0xE0,byte1-0x80,byte2-0x80
2212		unicode = code0*shift_12 + code1*shift_6 + code2
2213	end
2214	if bytes == 4 then
2215		local byte0,byte1,byte2,byte3 = byte(ch,1,4)
2216		local code0,code1,code2,code3 = byte0-0xF0,byte1-0x80,byte2-0x80,byte3-0x80
2217		unicode = code0*shift_18 + code1*shift_12 + code2*shift_6 + code3
2218	end
2219
2220	return unicode,utf8unicode(str, i+1, j, byte_pos+bytes)
2221end
2222
2223-- Returns an iterator which returns the next substring and its byte interval
2224local function utf8gensub(str, sub_len)
2225	sub_len        = sub_len or 1
2226	local byte_pos = 1
2227	local length   = #str
2228	return function(skip)
2229		if skip then byte_pos = byte_pos + skip end
2230		local char_count = 0
2231		local start      = byte_pos
2232		repeat
2233			if byte_pos > length then return end
2234			char_count  = char_count + 1
2235			local bytes = utf8charbytes(str,byte_pos)
2236			byte_pos    = byte_pos+bytes
2237
2238		until char_count == sub_len
2239
2240		local last  = byte_pos-1
2241		local slice = sub(str,start,last)
2242		return slice, start, last
2243	end
2244end
2245
2246local function binsearch(sortedTable, item, comp)
2247	local head, tail = 1, #sortedTable
2248	local mid = math.floor((head + tail)/2)
2249	if not comp then
2250		while (tail - head) > 1 do
2251			if sortedTable[tonumber(mid)] > item then
2252				tail = mid
2253			else
2254				head = mid
2255			end
2256			mid = math.floor((head + tail)/2)
2257		end
2258	end
2259	if sortedTable[tonumber(head)] == item then
2260		return true, tonumber(head)
2261	elseif sortedTable[tonumber(tail)] == item then
2262		return true, tonumber(tail)
2263	else
2264		return false
2265	end
2266end
2267local function classMatchGenerator(class, plain)
2268	local codes = {}
2269	local ranges = {}
2270	local ignore = false
2271	local range = false
2272	local firstletter = true
2273	local unmatch = false
2274
2275	local it = utf8gensub(class)
2276
2277	local skip
2278	for c, _, be in it do
2279		skip = be
2280		if not ignore and not plain then
2281			if c == "%" then
2282				ignore = true
2283			elseif c == "-" then
2284				table.insert(codes, utf8unicode(c))
2285				range = true
2286			elseif c == "^" then
2287				if not firstletter then
2288					error('!!!')
2289				else
2290					unmatch = true
2291				end
2292			elseif c == ']' then
2293				break
2294			else
2295				if not range then
2296					table.insert(codes, utf8unicode(c))
2297				else
2298					table.remove(codes) -- removing '-'
2299					table.insert(ranges, {table.remove(codes), utf8unicode(c)})
2300					range = false
2301				end
2302			end
2303		elseif ignore and not plain then
2304			if c == 'a' then -- %a: represents all letters. (ONLY ASCII)
2305				table.insert(ranges, {65, 90}) -- A - Z
2306				table.insert(ranges, {97, 122}) -- a - z
2307			elseif c == 'c' then -- %c: represents all control characters.
2308				table.insert(ranges, {0, 31})
2309				table.insert(codes, 127)
2310			elseif c == 'd' then -- %d: represents all digits.
2311				table.insert(ranges, {48, 57}) -- 0 - 9
2312			elseif c == 'g' then -- %g: represents all printable characters except space.
2313				table.insert(ranges, {1, 8})
2314				table.insert(ranges, {14, 31})
2315				table.insert(ranges, {33, 132})
2316				table.insert(ranges, {134, 159})
2317				table.insert(ranges, {161, 5759})
2318				table.insert(ranges, {5761, 8191})
2319				table.insert(ranges, {8203, 8231})
2320				table.insert(ranges, {8234, 8238})
2321				table.insert(ranges, {8240, 8286})
2322				table.insert(ranges, {8288, 12287})
2323			elseif c == 'l' then -- %l: represents all lowercase letters. (ONLY ASCII)
2324				table.insert(ranges, {97, 122}) -- a - z
2325			elseif c == 'p' then -- %p: represents all punctuation characters. (ONLY ASCII)
2326				table.insert(ranges, {33, 47})
2327				table.insert(ranges, {58, 64})
2328				table.insert(ranges, {91, 96})
2329				table.insert(ranges, {123, 126})
2330			elseif c == 's' then -- %s: represents all space characters.
2331				table.insert(ranges, {9, 13})
2332				table.insert(codes, 32)
2333				table.insert(codes, 133)
2334				table.insert(codes, 160)
2335				table.insert(codes, 5760)
2336				table.insert(ranges, {8192, 8202})
2337				table.insert(codes, 8232)
2338				table.insert(codes, 8233)
2339				table.insert(codes, 8239)
2340				table.insert(codes, 8287)
2341				table.insert(codes, 12288)
2342			elseif c == 'u' then -- %u: represents all uppercase letters. (ONLY ASCII)
2343				table.insert(ranges, {65, 90}) -- A - Z
2344			elseif c == 'w' then -- %w: represents all alphanumeric characters. (ONLY ASCII)
2345				table.insert(ranges, {48, 57}) -- 0 - 9
2346				table.insert(ranges, {65, 90}) -- A - Z
2347				table.insert(ranges, {97, 122}) -- a - z
2348			elseif c == 'x' then -- %x: represents all hexadecimal digits.
2349				table.insert(ranges, {48, 57}) -- 0 - 9
2350				table.insert(ranges, {65, 70}) -- A - F
2351				table.insert(ranges, {97, 102}) -- a - f
2352			else
2353				if not range then
2354					table.insert(codes, utf8unicode(c))
2355				else
2356					table.remove(codes) -- removing '-'
2357					table.insert(ranges, {table.remove(codes), utf8unicode(c)})
2358					range = false
2359				end
2360			end
2361			ignore = false
2362		else
2363			if not range then
2364				table.insert(codes, utf8unicode(c))
2365			else
2366				table.remove(codes) -- removing '-'
2367				table.insert(ranges, {table.remove(codes), utf8unicode(c)})
2368				range = false
2369			end
2370			ignore = false
2371		end
2372
2373		firstletter = false
2374	end
2375
2376	table.sort(codes)
2377
2378	local function inRanges(charCode)
2379		for _,r in ipairs(ranges) do
2380			if r[1] <= charCode and charCode <= r[2] then
2381				return true
2382			end
2383		end
2384		return false
2385	end
2386	if not unmatch then
2387		return function(charCode)
2388			return binsearch(codes, charCode) or inRanges(charCode)
2389		end, skip
2390	else
2391		return function(charCode)
2392			return charCode ~= -1 and not (binsearch(codes, charCode) or inRanges(charCode))
2393		end, skip
2394	end
2395end
2396
2397--[[
2398-- utf8sub with extra argument, and extra result value
2399local function utf8subWithBytes (s, i, j, sb)
2400	-- argument defaults
2401	j = j or -1
2402
2403	local pos = sb or 1
2404	local bytes = len(s)
2405	local length = 0
2406
2407	-- only set l if i or j is negative
2408	local l = (i >= 0 and j >= 0) or utf8len(s)
2409	local startChar = (i >= 0) and i or l + i + 1
2410	local endChar   = (j >= 0) and j or l + j + 1
2411
2412	-- can't have start before end!
2413	if startChar > endChar then
2414		return ""
2415	end
2416
2417	-- byte offsets to pass to string.sub
2418	local startByte,endByte = 1,bytes
2419
2420	while pos <= bytes do
2421		length = length + 1
2422
2423		if length == startChar then
2424			startByte = pos
2425		end
2426
2427		pos = pos + utf8charbytes(s, pos)
2428
2429		if length == endChar then
2430			endByte = pos - 1
2431			break
2432		end
2433	end
2434
2435	if startChar > length then startByte = bytes+1   end
2436	if endChar   < 1      then endByte   = 0         end
2437
2438	return sub(s, startByte, endByte), endByte + 1
2439end
2440]]
2441
2442local cache = setmetatable({},{
2443	__mode = 'kv'
2444})
2445local cachePlain = setmetatable({},{
2446	__mode = 'kv'
2447})
2448local function matcherGenerator(regex, plain)
2449	local matcher = {
2450		functions = {},
2451		captures = {}
2452	}
2453	if not plain then
2454		cache[regex] =  matcher
2455	else
2456		cachePlain[regex] = matcher
2457	end
2458	local function simple(func)
2459		return function(cC)
2460			if func(cC) then
2461				matcher:nextFunc()
2462				matcher:nextStr()
2463			else
2464				matcher:reset()
2465			end
2466		end
2467	end
2468	local function star(func)
2469		return function(cC)
2470			if func(cC) then
2471				matcher:fullResetOnNextFunc()
2472				matcher:nextStr()
2473			else
2474				matcher:nextFunc()
2475			end
2476		end
2477	end
2478	local function minus(func)
2479		return function(cC)
2480			if func(cC) then
2481				matcher:fullResetOnNextStr()
2482			end
2483			matcher:nextFunc()
2484		end
2485	end
2486	local function question(func)
2487		return function(cC)
2488			if func(cC) then
2489				matcher:fullResetOnNextFunc()
2490				matcher:nextStr()
2491			end
2492			matcher:nextFunc()
2493		end
2494	end
2495
2496	local function capture(id)
2497		return function(_)
2498			local l = matcher.captures[id][2] - matcher.captures[id][1]
2499			local captured = utf8sub(matcher.string, matcher.captures[id][1], matcher.captures[id][2])
2500			local check = utf8sub(matcher.string, matcher.str, matcher.str + l)
2501			if captured == check then
2502				for _ = 0, l do
2503					matcher:nextStr()
2504				end
2505				matcher:nextFunc()
2506			else
2507				matcher:reset()
2508			end
2509		end
2510	end
2511	local function captureStart(id)
2512		return function(_)
2513			matcher.captures[id][1] = matcher.str
2514			matcher:nextFunc()
2515		end
2516	end
2517	local function captureStop(id)
2518		return function(_)
2519			matcher.captures[id][2] = matcher.str - 1
2520			matcher:nextFunc()
2521		end
2522	end
2523
2524	local function balancer(str)
2525		local sum = 0
2526		local bc, ec = utf8sub(str, 1, 1), utf8sub(str, 2, 2)
2527		local skip = len(bc) + len(ec)
2528		bc, ec = utf8unicode(bc), utf8unicode(ec)
2529		return function(cC)
2530			if cC == ec and sum > 0 then
2531				sum = sum - 1
2532				if sum == 0 then
2533					matcher:nextFunc()
2534				end
2535				matcher:nextStr()
2536			elseif cC == bc then
2537				sum = sum + 1
2538				matcher:nextStr()
2539			else
2540				if sum == 0 or cC == -1 then
2541					sum = 0
2542					matcher:reset()
2543				else
2544					matcher:nextStr()
2545				end
2546			end
2547		end, skip
2548	end
2549
2550	matcher.functions[1] = function(_)
2551		matcher:fullResetOnNextStr()
2552		matcher.seqStart = matcher.str
2553		matcher:nextFunc()
2554		if (matcher.str > matcher.startStr and matcher.fromStart) or matcher.str >= matcher.stringLen then
2555			matcher.stop = true
2556			matcher.seqStart = nil
2557		end
2558	end
2559
2560	local lastFunc
2561	local ignore = false
2562	local skip = nil
2563	local it = (function()
2564		local gen = utf8gensub(regex)
2565		return function()
2566			return gen(skip)
2567		end
2568	end)()
2569	local cs = {}
2570	for c, bs, be in it do
2571		skip = nil
2572		if plain then
2573			table.insert(matcher.functions, simple(classMatchGenerator(c, plain)))
2574		else
2575			if ignore then
2576				if find('123456789', c, 1, true) then
2577					if lastFunc then
2578						table.insert(matcher.functions, simple(lastFunc))
2579						lastFunc = nil
2580					end
2581					table.insert(matcher.functions, capture(tonumber(c)))
2582				elseif c == 'b' then
2583					if lastFunc then
2584						table.insert(matcher.functions, simple(lastFunc))
2585						lastFunc = nil
2586					end
2587					local b
2588					b, skip = balancer(sub(regex, be + 1, be + 9))
2589					table.insert(matcher.functions, b)
2590				else
2591					lastFunc = classMatchGenerator('%' .. c)
2592				end
2593				ignore = false
2594			else
2595				if c == '*' then
2596					if lastFunc then
2597						table.insert(matcher.functions, star(lastFunc))
2598						lastFunc = nil
2599					else
2600						error('invalid regex after ' .. sub(regex, 1, bs))
2601					end
2602				elseif c == '+' then
2603					if lastFunc then
2604						table.insert(matcher.functions, simple(lastFunc))
2605						table.insert(matcher.functions, star(lastFunc))
2606						lastFunc = nil
2607					else
2608						error('invalid regex after ' .. sub(regex, 1, bs))
2609					end
2610				elseif c == '-' then
2611					if lastFunc then
2612						table.insert(matcher.functions, minus(lastFunc))
2613						lastFunc = nil
2614					else
2615						error('invalid regex after ' .. sub(regex, 1, bs))
2616					end
2617				elseif c == '?' then
2618					if lastFunc then
2619						table.insert(matcher.functions, question(lastFunc))
2620						lastFunc = nil
2621					else
2622						error('invalid regex after ' .. sub(regex, 1, bs))
2623					end
2624				elseif c == '^' then
2625					if bs == 1 then
2626						matcher.fromStart = true
2627					else
2628						error('invalid regex after ' .. sub(regex, 1, bs))
2629					end
2630				elseif c == '$' then
2631					if be == len(regex) then
2632						matcher.toEnd = true
2633					else
2634						error('invalid regex after ' .. sub(regex, 1, bs))
2635					end
2636				elseif c == '[' then
2637					if lastFunc then
2638						table.insert(matcher.functions, simple(lastFunc))
2639					end
2640					lastFunc, skip = classMatchGenerator(sub(regex, be + 1))
2641				elseif c == '(' then
2642					if lastFunc then
2643						table.insert(matcher.functions, simple(lastFunc))
2644						lastFunc = nil
2645					end
2646					table.insert(matcher.captures, {})
2647					table.insert(cs, #matcher.captures)
2648					table.insert(matcher.functions, captureStart(cs[#cs]))
2649					if sub(regex, be + 1, be + 1) == ')' then matcher.captures[#matcher.captures].empty = true end
2650				elseif c == ')' then
2651					if lastFunc then
2652						table.insert(matcher.functions, simple(lastFunc))
2653						lastFunc = nil
2654					end
2655					local cap = table.remove(cs)
2656					if not cap then
2657						error('invalid capture: "(" missing')
2658					end
2659					table.insert(matcher.functions, captureStop(cap))
2660				elseif c == '.' then
2661					if lastFunc then
2662						table.insert(matcher.functions, simple(lastFunc))
2663					end
2664					lastFunc = function(cC) return cC ~= -1 end
2665				elseif c == '%' then
2666					ignore = true
2667				else
2668					if lastFunc then
2669						table.insert(matcher.functions, simple(lastFunc))
2670					end
2671					lastFunc = classMatchGenerator(c)
2672				end
2673			end
2674		end
2675	end
2676	if #cs > 0 then
2677		error('invalid capture: ")" missing')
2678	end
2679	if lastFunc then
2680		table.insert(matcher.functions, simple(lastFunc))
2681	end
2682
2683	table.insert(matcher.functions, function()
2684		if matcher.toEnd and matcher.str ~= matcher.stringLen then
2685			matcher:reset()
2686		else
2687			matcher.stop = true
2688		end
2689	end)
2690
2691	matcher.nextFunc = function(self)
2692		self.func = self.func + 1
2693	end
2694	matcher.nextStr = function(self)
2695		self.str = self.str + 1
2696	end
2697	matcher.strReset = function(self)
2698		local oldReset = self.reset
2699		local str = self.str
2700		self.reset = function(s)
2701			s.str = str
2702			s.reset = oldReset
2703		end
2704	end
2705	matcher.fullResetOnNextFunc = function(self)
2706		local oldReset = self.reset
2707		local func = self.func +1
2708		local str = self.str
2709		self.reset = function(s)
2710			s.func = func
2711			s.str = str
2712			s.reset = oldReset
2713		end
2714	end
2715	matcher.fullResetOnNextStr = function(self)
2716		local oldReset = self.reset
2717		local str = self.str + 1
2718		local func = self.func
2719		self.reset = function(s)
2720			s.func = func
2721			s.str = str
2722			s.reset = oldReset
2723		end
2724	end
2725
2726	matcher.process = function(self, str, start)
2727
2728		self.func = 1
2729		start = start or 1
2730		self.startStr = (start >= 0) and start or utf8len(str) + start + 1
2731		self.seqStart = self.startStr
2732		self.str = self.startStr
2733		self.stringLen = utf8len(str) + 1
2734		self.string = str
2735		self.stop = false
2736
2737		self.reset = function(s)
2738			s.func = 1
2739		end
2740
2741		-- local lastPos = self.str
2742		-- local lastByte
2743		local ch
2744		while not self.stop do
2745			if self.str < self.stringLen then
2746				--[[ if lastPos < self.str then
2747				print('last byte', lastByte)
2748				ch, lastByte = utf8subWithBytes(str, 1, self.str - lastPos - 1, lastByte)
2749				ch, lastByte = utf8subWithBytes(str, 1, 1, lastByte)
2750				lastByte = lastByte - 1
2751			else
2752				ch, lastByte = utf8subWithBytes(str, self.str, self.str)
2753			end
2754			lastPos = self.str ]]
2755			ch = utf8sub(str, self.str,self.str)
2756			--print('char', ch, utf8unicode(ch))
2757			self.functions[self.func](utf8unicode(ch))
2758		else
2759			self.functions[self.func](-1)
2760		end
2761	end
2762
2763	if self.seqStart then
2764		local captures = {}
2765		for _,pair in pairs(self.captures) do
2766			if pair.empty then
2767				table.insert(captures, pair[1])
2768			else
2769				table.insert(captures, utf8sub(str, pair[1], pair[2]))
2770			end
2771		end
2772		return self.seqStart, self.str - 1, unpack(captures)
2773	end
2774end
2775
2776return matcher
2777end
2778
2779-- string.find
2780local function utf8find(str, regex, init, plain)
2781local matcher = cache[regex] or matcherGenerator(regex, plain)
2782return matcher:process(str, init)
2783end
2784
2785-- string.match
2786local function utf8match(str, regex, init)
2787init = init or 1
2788local found = {utf8find(str, regex, init)}
2789if found[1] then
2790	if found[3] then
2791		return unpack(found, 3)
2792	end
2793	return utf8sub(str, found[1], found[2])
2794end
2795end
2796
2797-- string.gmatch
2798local function utf8gmatch(str, regex, all)
2799regex = (utf8sub(regex,1,1) ~= '^') and regex or '%' .. regex
2800local lastChar = 1
2801return function()
2802	local found = {utf8find(str, regex, lastChar)}
2803	if found[1] then
2804		lastChar = found[2] + 1
2805		if found[all and 1 or 3] then
2806			return unpack(found, all and 1 or 3)
2807		end
2808		return utf8sub(str, found[1], found[2])
2809	end
2810end
2811end
2812
2813local function replace(repl, args)
2814local ret = ''
2815if type(repl) == 'string' then
2816	local ignore = false
2817	local num
2818	for c in utf8gensub(repl) do
2819		if not ignore then
2820			if c == '%' then
2821				ignore = true
2822			else
2823				ret = ret .. c
2824			end
2825		else
2826			num = tonumber(c)
2827			if num then
2828				ret = ret .. args[num]
2829			else
2830				ret = ret .. c
2831			end
2832			ignore = false
2833		end
2834	end
2835elseif type(repl) == 'table' then
2836	ret = repl[args[1] or args[0]] or ''
2837elseif type(repl) == 'function' then
2838	if #args > 0 then
2839		ret = repl(unpack(args, 1)) or ''
2840	else
2841		ret = repl(args[0]) or ''
2842	end
2843end
2844return ret
2845end
2846-- string.gsub
2847local function utf8gsub(str, regex, repl, limit)
2848limit = limit or -1
2849local ret = ''
2850local prevEnd = 1
2851local it = utf8gmatch(str, regex, true)
2852local found = {it()}
2853local n = 0
2854while #found > 0 and limit ~= n do
2855	local args = {[0] = utf8sub(str, found[1], found[2]), unpack(found, 3)}
2856	ret = ret .. utf8sub(str, prevEnd, found[1] - 1)
2857	.. replace(repl, args)
2858	prevEnd = found[2] + 1
2859	n = n + 1
2860	found = {it()}
2861end
2862return ret .. utf8sub(str, prevEnd), n
2863end
2864
2865utf8.sub = utf8sub
2866utf8.reverse = utf8reverse
2867utf8.char = utf8char
2868utf8.unicode = utf8unicode
2869utf8.gensub = utf8gensub
2870utf8.byte = utf8unicode
2871utf8.find    = utf8find
2872utf8.match   = utf8match
2873utf8.gmatch  = utf8gmatch
2874utf8.gsub    = utf8gsub
2875utf8.dump    = dump
2876utf8.format = format
2877utf8.lower = utf8lower
2878utf8.upper = utf8upper
2879utf8.rep     = rep
2880
2881return utf8