1
// Copyright 2008 The RE2 Authors. All Rights Reserved.
2
// Use of this source code is governed by a BSD-style
3
// license that can be found in the LICENSE file.
5
// Unicode case folding tables.
7
// The Unicode case folding tables encode the mapping from one Unicode point
8
// to the next largest Unicode point with equivalent folding. The largest
9
// point wraps back to the first. For example, the tables map:
15
// 'k' -> 'K' (Kelvin symbol)
18
// Like everything Unicode, these tables are big. If we represent the table
19
// as a sorted list of uint32 pairs, it has 2049 entries and is 16 kB.
20
// Most table entries look like the ones around them:
21
// 'A' maps to 'A'+32, 'B' maps to 'B'+32, etc.
22
// Instead of listing all the pairs explicitly, we make a list of ranges
23
// and deltas, so that the table entries for 'A' through 'Z' can be represented
24
// as a single entry { 'A', 'Z', +32 }.
26
// In addition to blocks that map to each other (A-Z mapping to a-z)
27
// there are blocks of pairs that individually map to each other
28
// (for example, 0100<->0101, 0102<->0103, 0104<->0105, ...).
29
// For those, the special delta value EvenOdd marks even/odd pairs
30
// (if even, add 1; if odd, subtract 1), and OddEven marks odd/even pairs.
32
// In this form, the table has 274 entries, about 3kB. If we were to split
33
// the table into one for 16-bit codes and an overflow table for larger ones,
34
// we could get it down to about 1.5kB, but that's not worth the complexity.
36
// The grouped form also allows for efficient fold range calculations
37
// rather than looping one character at a time.
39
#ifndef RE2_UNICODE_CASEFOLD_H__
40
#define RE2_UNICODE_CASEFOLD_H__
42
#include "util/util.h"
59
extern CaseFold unicode_casefold[];
60
extern int num_unicode_casefold;
62
extern CaseFold unicode_tolower[];
63
extern int num_unicode_tolower;
65
// Returns the CaseFold* in the tables that contains rune.
66
// If rune is not in the tables, returns the first CaseFold* after rune.
67
// If rune is larger than any value in the tables, returns NULL.
68
extern CaseFold* LookupCaseFold(CaseFold*, int, Rune rune);
70
// Returns the result of applying the fold f to the rune r.
71
extern Rune ApplyFold(CaseFold *f, Rune r);
75
#endif // RE2_UNICODE_CASEFOLD_H__