Skip to content

Swift Package that provides IDNA Rules

License

LGPL-3.0, GPL-3.0 licenses found

Licenses found

LGPL-3.0
COPYING.LESSER
GPL-3.0
COPYING
Notifications You must be signed in to change notification settings

dns-inspector/IDNARules-Swift

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Swift Package for IDNA Rules

The IdnaRules package contains a list of IDNA compatability rules for IDNA2008 as defined in UTS #46.

Note that valid codepoint ranges are not included for optimization.

Rule lists are built by the update_rules.py script.

Usage

Find potential rules for a given codepoint

Rules are split up by nearby codepoints for faster lookup, however this means that the find_idna_rules method will return rules that don't apply to the codepoint. You will need to check if they apply afterwards.

import IdnaRules

var ruleCount = Int(0)
guard let ptr = IdnaRules.find_idna_rules(codepoint, &ruleCount) else {
    return []
}
if ruleCount <= 0 {
    return []
}
return ptr.withMemoryRebound(to: IDNARule.self, capacity: ruleCount) {
    Array(UnsafeBufferPointer(start: $0, count: ruleCount))
}

Check if a rule applies to a codepoint

codepoint >= rule.codepointStart && codepoint <= rule.codepointEnd

Get replacement codepoints

If the rule action is mapped, then you need to repalce the codepoint with other values.

if rule.replace_len == 0 {
    return []
}
return rule.replace_with.withMemoryRebound(to: UInt32.self, capacity: rule.replace_len) {
    Array(UnsafeBufferPointer(start: $0, count: rule.replace_len))
}

About

Swift Package that provides IDNA Rules

Resources

License

LGPL-3.0, GPL-3.0 licenses found

Licenses found

LGPL-3.0
COPYING.LESSER
GPL-3.0
COPYING

Stars

Watchers

Forks

Languages