diff options
author | bptato <nincsnevem662@gmail.com> | 2024-01-04 18:59:08 +0100 |
---|---|---|
committer | bptato <nincsnevem662@gmail.com> | 2024-01-04 18:59:48 +0100 |
commit | 4c81d51a304fea9d9e902ad8b5a28d1d3b9a9a03 (patch) | |
tree | 27e6145f493f70071e334fa5ebed99eff5135838 /src/types | |
parent | d4409baee1a510bf3361820cbdf4118ed09baffd (diff) | |
download | chawan-4c81d51a304fea9d9e902ad8b5a28d1d3b9a9a03.tar.gz |
Merge data/idna with types/url
No need to have a separate directory for just 3 functions.
Diffstat (limited to 'src/types')
-rw-r--r-- | src/types/url.nim | 50 |
1 files changed, 49 insertions, 1 deletions
diff --git a/src/types/url.nim b/src/types/url.nim index ee3f168e..75bc162e 100644 --- a/src/types/url.nim +++ b/src/types/url.nim @@ -7,14 +7,16 @@ import std/tables import std/unicode import bindings/libunicode -import data/idna import js/error import js/javascript import lib/punycode import types/blob import utils/luwrap +import utils/map import utils/twtstr +include res/map/idna_gen + type URLState = enum SCHEME_START_STATE, SCHEME_STATE, NO_SCHEME_STATE, FILE_STATE, @@ -256,6 +258,52 @@ func cmpRange(x: u32pair, y: uint32): int = return -1 return 0 +type + IDNATableStatus = enum + IDNA_VALID, IDNA_IGNORED, IDNA_MAPPED, IDNA_DEVIATION, IDNA_DISALLOWED + +func getIdnaTableStatus(r: Rune): IDNATableStatus = + let i = uint32(r) + if i <= high(uint16): + let u = uint16(i) + if u in IgnoredLow: + return IDNA_IGNORED + if u in DisallowedLow: + return IDNA_DISALLOWED + for item in Deviation: + if item[0] == u: + return IDNA_DEVIATION + if DisallowedRangesLow.isInRange(u): + return IDNA_DISALLOWED + if MappedMapLow.isInMap(u): + return IDNA_MAPPED + else: + if i in IgnoredHigh: + return IDNA_IGNORED + if i in DisallowedHigh: + return IDNA_DISALLOWED + if DisallowedRangesHigh.isInRange(i): + return IDNA_DISALLOWED + if MappedMapHigh.isInMap(uint32(i)): + return IDNA_MAPPED + return IDNA_VALID + +func getIdnaMapped(r: Rune): string = + let i = uint32(r) + if i <= high(uint16): + let u = uint16(i) + let n = MappedMapLow.searchInMap(u) + if n != -1: + return $MappedMapLow[n].mapped + let n = MappedMapHigh.searchInMap(i) + return $MappedMapHigh[n].mapped + +func getDeviationMapped(r: Rune): string = + for item in Deviation: + if item[0] == uint16(r): + return $item[1] + return "" + func processIdna(str: string, checkhyphens, checkbidi, checkjoiners, transitionalprocessing: bool): Option[string] = var mapped: seq[Rune] |