stefanspringer1/fastreplace
This package offers an efficient way to replace certain Unicode code points (either represented by `UnicodeScalar` or `UInt32`) with other values. Those methods might be more efficient than the replacement methods of the Swift standard library where grapheme clusters are consider
Duplicate keys produced by a macro
Be careful not to produce duplicate keys by using e.g. the #codepoint or #codepointForEntity macro: The following code compiles without a warning (at least with Swift version 6.0.0, cf. the bug report):
text.replacing([
#codepointForEntity("½"): " 1 / 2 ",
#codepointForEntity("½"): " 1 / 2 ",
#codepointForEntity("⅓"): " 1 / 3 ",
])But #codepointForEntity("½") and #codepointForEntity("½") are both expanded to 0xBD, so we have defined a dictionary with duplicate keys. If you used this value directly as keys, this would produce the warning “Dictionary literal of type '[UInt32 : String]' has duplicate entries for integer literal key '0xBD'”. The lack of warning in the case of the macro usage is fatal, because during the run the program then crashes with a Trace/BPT trap ... error.
Package Metadata
Repository: stefanspringer1/fastreplace
Default branch: main
README: README.md