diff options
Diffstat (limited to 'src/html/entity.nim')
-rw-r--r-- | src/html/entity.nim | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/src/html/entity.nim b/src/html/entity.nim new file mode 100644 index 00000000..79c57ca0 --- /dev/null +++ b/src/html/entity.nim @@ -0,0 +1,28 @@ +import json + +import ../utils/radixtree + +const entity = staticRead"../../res/entity.json" +when defined(small): + proc genEntityMap(data: seq[tuple[a: string, b: string]]): RadixNode[string] = + result = newRadixTree[string]() + for pair in data: + result[pair.a] = pair.b + + proc genEntityTable(): seq[tuple[a: string, b: string]] = + let entityJson = parseJson(entity) + + for k, v in entityJson: + result.add((k.substr(1), v{"characters"}.getStr())) + const entityTable = genEntityTable() + let entityMap* = genEntityMap(entityTable) +else: + proc genEntityMap(): StaticRadixTree[string] = + let entityJson = parseJson(entity) + var entityMap = newStaticRadixTree[string]() + + for k, v in entityJson: + entityMap[k.substr(1)] = v{"characters"}.getStr() + + return entityMap + const entityMap* = genEntityMap() |