@@ -23,7 +23,22 @@ PackedEntities(tab::PackedTable) = PackedEntities(tab.offsetvec, tab.namtab)
23
23
Base. getindex (str:: PackedEntities , ind:: Integer ) =
24
24
_unpackword (str. namtab[str. offsetvec[ind]+ 1 : str. offsetvec[ind+ 1 ]])
25
25
26
- include (" unicode_table.jl" )
26
+ VER = UInt32 (1 )
27
+
28
+ immutable Unicode_Table{S,T,V} <: AbstractEntityTable
29
+ ver:: UInt32
30
+ tim:: String
31
+ inf:: String
32
+ base32:: UInt32
33
+ nam:: PackedTable{S,V} # This has packed byte vectors
34
+ ind:: Vector{UInt16}
35
+ wrd1:: StrTable{T} # This has sorted words for 1-byte
36
+ wrd2:: StrTable{T} # This has sorted words for 2-byte
37
+ val16:: Vector{UInt16}
38
+ ind16:: Vector{UInt16}
39
+ val32:: Vector{UInt16}
40
+ ind32:: Vector{UInt16}
41
+ end
27
42
28
43
function __init__ ()
29
44
const global _tab =
@@ -87,31 +102,26 @@ function _get_strings{T}(val::T, tab::Vector{T}, ind::Vector{UInt16})
87
102
_names[ind[rng]]
88
103
end
89
104
90
- """ Given a Unicode name, return the string it represents, or an empty string if not found"""
91
105
function lookupname (str:: AbstractString )
92
106
rng = searchsorted (_names, uppercase (str))
93
107
isempty (rng) ? _empty_str : _get_str (_tab. ind[rng. start])
94
108
end
95
109
96
- """ Given a character, return all exact matches to the character as a vector"""
97
110
matchchar (ch:: Char ) =
98
111
(ch <= ' \u ffff'
99
112
? _get_strings (ch% UInt16, _tab. val16, _tab. ind16)
100
113
: (ch <= ' \U 1ffff' ? _get_strings (ch% UInt16, _tab. val32, _tab. ind32) : _empty_str_vec))
101
114
102
- """ Given a string, return all exact matches to the string as a vector"""
103
- function matches end
104
115
matches (str:: AbstractString ) = matches (convert (Vector{Char}, str))
105
116
matches (vec:: Vector{Char} ) = length (vec) == 1 ? matchchar (vec[1 ]) : _empty_str_vec
106
117
107
- """ Given a string, return all of the longest matches to the beginning of the string as a vector"""
108
- function longestmatches end
109
118
longestmatches (str:: AbstractString ) = longestmatches (convert (Vector{Char},str))
110
119
longestmatches (vec:: Vector{Char} ) = isempty (vec) ? _empty_str_vec : matchchar (uppercase (vec[1 ]))
111
120
112
- """ Given a string, return all of the Unicode entity names that start with that string, if any"""
113
- function completions end
114
121
completions (str:: AbstractString ) = completions (String (str))
115
- completions (str:: String ) = StrTables. matchfirst (_names, uppercase (str))
122
+ function completions (str:: String )
123
+ str = uppercase (str)
124
+ [nam for nam in _names if startswith (nam, str)]
125
+ end
116
126
117
127
end # module
0 commit comments