MCPcopy Create free account
hub / github.com/PageBot/PageBot / distributeUnicodes

Function distributeUnicodes

Lib/pagebot/fonttoolbox/unicodes/unicoderanges.py:172–212  ·  view source on GitHub ↗

Return a dictionary with range names as keys, and subsets of unicodes belonging to the respective range as values. None is used as a key for characters that don't fall into any range. >>> distributeUnicodes([65]) {'Basic Latin': [65]} >>> distributeUnicodes([100000])

(unicodes)

Source from the content-addressed store, hash-verified

170
171
172def distributeUnicodes(unicodes):
173 """Return a dictionary with range names as keys, and subsets of unicodes
174 belonging to the respective range as values. None is used as a key for
175 characters that don't fall into any range.
176
177 >>> distributeUnicodes([65])
178 {'Basic Latin': [65]}
179 >>> distributeUnicodes([100000])
180 {None: [100000]}
181 >>> distributeUnicodes([65, 165])
182 {'Basic Latin': [65], 'Latin-1 Supplement': [165]}
183 >>> unicodes = list(range(65, 70)) + list(range(6000, 6005)) + [100000]
184 >>> ranges = distributeUnicodes(unicodes)
185 >>> sorted(ranges['Basic Latin'])
186 [65, 66, 67, 68, 69]
187 >>> all = set()
188 >>> for unis in ranges.values():
189 ... all.update(unis)
190 ...
191 >>> assert all == set(unicodes)
192 """
193 ranges = {}
194 noneRanges = []
195 unicodes = sorted(unicodes)
196 lo = 0
197 for rangeMinimum in _rangeMinimums:
198 rangeMaximum, bit, name = _byRangeMinimum[rangeMinimum]
199 minIndex = bisect_left(unicodes, rangeMinimum, lo=lo)
200 if minIndex > lo:
201 noneRanges.extend(unicodes[lo:minIndex])
202 if minIndex == len(unicodes):
203 # done.
204 break
205 maxIndex = bisect_right(unicodes, rangeMaximum, lo=minIndex)
206 lo = maxIndex
207 if minIndex == maxIndex:
208 continue
209 ranges[name] = unicodes[minIndex:maxIndex]
210 if noneRanges:
211 ranges[None] = noneRanges
212 return ranges
213
214
215def _distributeUnicodes_ReferenceImplementation(unicodes):

Callers 1

getUnicodeRangeBitsFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected