-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
bc78697
commit 3163363
Showing
8 changed files
with
648 additions
and
147 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
#= | ||
Case folding for Unicode characters | ||
Copyright 2018 Gandalf Software, Inc., Scott P. Jones | ||
Licensed under MIT License, see LICENSE.md | ||
=# | ||
|
||
module CaseTables | ||
include("maketables.jl") | ||
|
||
const ct, tupvec, offvec, bitvec, sizvecl, sizvecu = case_tables() | ||
end # module CaseTables | ||
|
||
using .CaseTables | ||
|
||
const ct = CaseTables.ct | ||
|
||
using ModuleInterfaceTools | ||
@api extend ChrBase | ||
|
||
_can_upper_lat(c) = ifelse(c > (V6_COMPAT ? 0xdf : 0xde), c != 0xf7, c == 0xb5) | ||
|
||
_wide_lower_latin(ch) = (ch == 0xb5) | (ch == 0xff) | (!V6_COMPAT && (ch == 0xdf)) | ||
|
||
_wide_out_upper(ch) = | ||
ifelse(ch == 0xb5, 0x39c, | ||
ifelse(ch == 0xff, 0x178, ifelse(!V6_COMPAT && ch == 0xdf, 0x1e9e, ch%UInt16))) | ||
|
||
_check_tab(off, ch) = | ||
off != 0 && (CaseTables.bitvec[off][((ch >>> 5) & 0xf) + 1] & (UInt32(1) << (ch & 0x1f))) != 0 | ||
|
||
@inline _get_tab(off, ch) = | ||
off == 0 ? ch : (off = CaseTables.offvec[off][((ch >>> 5) & 0x1f) + 1]) == 0 ? ch : | ||
CaseTables.tupvec[off][(ch & 0x1f) + 1] | ||
|
||
@inline _upper_lat(ch) = _get_tab(ct.u_tab[1], ch) | ||
|
||
@inline _upper_bmp(ch) = | ||
(t = (ch >>> 9); ((ct.can_u >>> t) & 1) == 0 ? ch : _get_tab(ct.u_tab[(t>>1)+1], ch)) | ||
|
||
@inline _lower_bmp(ch) = | ||
(t = (ch >>> 9); ((ct.can_l >>> t) & 1) == 0 ? ch : _get_tab(ct.l_tab[(t>>1)+1], ch)) | ||
|
||
@inline _title_bmp(ch) = | ||
(t = (ch >>> 9); ((ct.can_u >>> t) & 1) == 0 ? ch : _get_tab(ct.t_tab[(t>>1)+1], ch)) | ||
|
||
@inline _upper_slp(ch) = | ||
(t = (ch >>> 9); ((ct.s_can_u >>> (t & 0x7f)) & 1) == 0 ? ch : _get_tab(ct.u_tab[(t>>1)+1], ch)) | ||
|
||
@inline _lower_slp(ch) = | ||
(t = (ch >>> 9); ((ct.s_can_l >>> (t & 0x7f)) & 1) == 0 ? ch : _get_tab(ct.l_tab[(t>>1)+1], ch)) | ||
|
||
# Handle range 0x0000-0xffff | ||
@inline _can_lower_bmp(ch) = | ||
(t = (ch >>> 9); ((ct.can_l >>> t) & 1) != 0 && _check_tab(ct.can_l_tab[t+1], ch)) | ||
|
||
# Handle range 0x10000-0x1ffff | ||
@inline _can_lower_slp(ch) = | ||
(t = (ch >>> 9); ((ct.s_can_l >>> (t & 0x7f)) & 1) != 0 && _check_tab(ct.can_l_tab[t+1], ch)) | ||
|
||
# Handle range 0x0000-0xffff | ||
@inline _can_upper_bmp(ch) = | ||
(t = (ch >>> 9); ((ct.can_u >>> t) & 1) != 0 && _check_tab(ct.can_u_tab[t+1], ch)) | ||
|
||
# Handle range 0x10000-0x1ffff | ||
@inline _can_upper_slp(ch) = | ||
(t = (ch >>> 9); ((ct.s_can_u >>> (t & 0x7f)) & 1) != 0 && _check_tab(ct.can_u_tab[t+1], ch)) | ||
|
||
#= | ||
# Handle range 0x0000-0xffff | ||
@inline _can_title_bmp(ch) = | ||
(t = (ch >>> 9); ((ct.can_t >>> t) & 1) != 0 && _check_tab(ct.can_t_tab[t+1], ch)) | ||
=# | ||
const _can_title_bmp = _can_upper_bmp | ||
|
||
# Handle range 0x0000-0xffff | ||
@inline _is_lower_bmp(ch) = | ||
(t = (ch >>> 9); ((ct.can_l >>> t) & 1) != 0 && _check_tab(ct.can_l_tab[t+1], ch)) | ||
|
||
# Handle range 0x10000-0x1ffff | ||
@inline _is_lower_slp(ch) = | ||
(t = (ch >>> 9); ((ct.s_can_l >>> (t & 0x7f)) & 1) != 0 && _check_tab(ct.can_l_tab[t+1], ch)) | ||
|
||
# Handle range 0x0000-0xffff | ||
@inline _is_upper_bmp(ch) = | ||
(t = (ch >>> 9); ((ct.can_u >>> t) & 1) != 0 && _check_tab(ct.can_u_tab[t+1], ch)) | ||
|
||
@inline _is_lower_ch(ch) = | ||
ch <= 0x7f ? _islower_a(ch) : | ||
ch <= 0xff ? _islower_l(ch) : | ||
ch <= 0xffff ? _is_lower_bmp(ch) : | ||
ch <= 0x1ffff ? _is_lower_slp(ch) : false | ||
|
||
@inline _is_upper_ch(ch) = | ||
ch <= 0x7f ? _isupper_a(ch) : | ||
ch <= 0xff ? _isupper_l(ch) : | ||
ch <= 0xffff ? _is_upper_bmp(ch) : | ||
ch <= 0x1ffff ? _is_upper_slp(ch) : false | ||
|
||
@inline _can_lower_ch(ch) = | ||
ch <= 0x7f ? _isupper_a(ch) : | ||
ch <= 0xff ? _isupper_l(ch) : | ||
ch <= 0xffff ? _can_lower_bmp(ch) : | ||
ch <= 0x1ffff ? _can_lower_slp(ch) : false | ||
|
||
@inline _can_upper_ch(ch) = | ||
ch <= 0x7f ? _islower_a(ch) : | ||
ch <= 0xff ? _can_upper_lat(ch) : | ||
ch <= 0xffff ? _can_upper_bmp(ch) : | ||
ch <= 0x1ffff ? _can_upper_slp(ch) : false | ||
|
||
const _can_title_ch = _can_upper_ch | ||
|
||
@inline _lower_ch(ch) = | ||
ch <= 0x7f ? (_isupper_a(ch) ? ch + 0x20 : ch) : | ||
ch <= 0xff ? (_isupper_l(ch) : ch + 0x20 : ch) : | ||
ch <= 0xffff ? _lower_bmp(ch) : | ||
ch <= 0x1ffff ? _lower_slp(ch) : ch | ||
|
||
@inline _upper_ch(ch) = | ||
ch <= 0x7f ? (_islower_a(ch) ? ch - 0x20 : ch) : | ||
ch <= 0xff ? _upper_lat(ch) : | ||
ch <= 0xffff ? _upper_bmp(ch) : | ||
ch <= 0x1ffff ? _upper_slp(ch) : ch | ||
|
||
@inline _title_ch(ch) = | ||
ch <= 0x7f ? (_islower_a(ch) ? ch - 0x20 : ch) : | ||
ch <= 0xff ? _upper_lat(ch) : | ||
ch <= 0xffff ? _title_bmp(ch) : | ||
ch <= 0x1ffff ? _upper_slp(ch) : ch |
Oops, something went wrong.