forked from rebolsource/r3
-
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
FEAT:
to-ascii
module - Latin to ASCII characters transliteration
- Loading branch information
Showing
2 changed files
with
251 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,250 @@ | ||
Rebol [ | ||
title: "to-ascii" | ||
purpose: "Latin to ASCII characters transliteration" | ||
name: to-ascii | ||
type: module | ||
options: [delay] | ||
version: 0.1.0 | ||
exports: [to-ascii] | ||
author: @Oldes | ||
file: %to-ascii.reb | ||
home: https://src.rebol.tech/modules/to-ascii.reb | ||
] | ||
to-ascii: function [ | ||
"Return a string with characters transliterated to ASCII" | ||
text [string!] "String to be converted" | ||
/keep "Keep unhandled non-ASCII characters" | ||
][ | ||
out: make string! length? text | ||
parse text [any [ | ||
copy s: some ascii-chars (append out s) | ||
| set s: convert ( | ||
append out pick replacements select/case table s | ||
) | ||
| set s: skip (if keep [append out s]) | ||
]] | ||
out | ||
] | ||
|
||
ascii-chars: make bitset! #{FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF} | ||
replacements: [ | ||
#"a" #"A" "ae" "AE" #"c" #"C" #"D" #"d" #"E" #"e" #"f" #"G" #"g" #"H" #"h" | ||
#"i" #"I" "IJ" "ij" #"J" #"j" #"K" #"k" #"L" #"l" #"N" #"n" #"o" #"O" "oe" | ||
"OE" #"r" #"R" #"s" #"S" #"T" #"t" #"u" #"U" #"W" #"w" #"Y" #"y" #"Z" #"z" | ||
] | ||
table: make map! [ | ||
#"á" 1 ;= a | ||
#"â" 1 | ||
#"ą" 1 | ||
#"ă" 1 | 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