@@ -23,7 +23,22 @@ PackedEntities(tab::PackedTable) = PackedEntities(tab.offsetvec, tab.namtab)
2323Base. getindex (str:: PackedEntities , ind:: Integer ) =
2424 _unpackword (str. namtab[str. offsetvec[ind]+ 1 : str. offsetvec[ind+ 1 ]])
2525
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
2742
2843function __init__ ()
2944 const global _tab =
@@ -87,31 +102,26 @@ function _get_strings{T}(val::T, tab::Vector{T}, ind::Vector{UInt16})
87102 _names[ind[rng]]
88103end
89104
90- """ Given a Unicode name, return the string it represents, or an empty string if not found"""
91105function lookupname (str:: AbstractString )
92106 rng = searchsorted (_names, uppercase (str))
93107 isempty (rng) ? _empty_str : _get_str (_tab. ind[rng. start])
94108end
95109
96- """ Given a character, return all exact matches to the character as a vector"""
97110matchchar (ch:: Char ) =
98111 (ch <= ' \u ffff'
99112 ? _get_strings (ch% UInt16, _tab. val16, _tab. ind16)
100113 : (ch <= ' \U 1ffff' ? _get_strings (ch% UInt16, _tab. val32, _tab. ind32) : _empty_str_vec))
101114
102- """ Given a string, return all exact matches to the string as a vector"""
103- function matches end
104115matches (str:: AbstractString ) = matches (convert (Vector{Char}, str))
105116matches (vec:: Vector{Char} ) = length (vec) == 1 ? matchchar (vec[1 ]) : _empty_str_vec
106117
107- """ Given a string, return all of the longest matches to the beginning of the string as a vector"""
108- function longestmatches end
109118longestmatches (str:: AbstractString ) = longestmatches (convert (Vector{Char},str))
110119longestmatches (vec:: Vector{Char} ) = isempty (vec) ? _empty_str_vec : matchchar (uppercase (vec[1 ]))
111120
112- """ Given a string, return all of the Unicode entity names that start with that string, if any"""
113- function completions end
114121completions (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
116126
117127end # module
0 commit comments