-
Notifications
You must be signed in to change notification settings - Fork 13
Convert functions to use code points #15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
54d4ecf
8bf5762
e38d89a
2926f07
fbfddea
2535356
5a47d12
ef04b33
61fe785
d8bc468
a7bc373
2926aba
ce982f2
bd17380
19bd2e8
fa50131
bff2cce
04a139b
a4fb7ac
2dcb0d1
9c9fca3
40f0ff8
dbf5853
3975999
3886937
b7ccb27
04e348f
6cccaaf
ae100fa
ba77c47
15aed70
f74f50b
dc28cc1
c8ac3e1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| src/Data/CodePoint/Unicode/Internal.purs linguist-generated | ||
| src/Data/CodePoint/Unicode/Internal/Casing.purs linguist-generated |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| #!/bin/bash | ||
| VERSION=$(cat unicode-version) | ||
| for F in UnicodeData SpecialCasing CaseFolding; do | ||
| wget "https://www.unicode.org/Public/$VERSION/ucd/$F.txt" -O $F.txt | ||
| done |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,124 @@ | ||
| #!/usr/bin/env node | ||
|
|
||
| const fs = require("fs"); | ||
|
|
||
| const SpecialCasing = ""+fs.readFileSync("SpecialCasing.txt"); | ||
| const CaseFolding = ""+fs.readFileSync("CaseFolding.txt"); | ||
|
|
||
| const special = | ||
| /^([0-9A-F]+);\s+([0-9A-F]+(?:\s+[0-9A-F]+)*)?;\s+([0-9A-F]+(?:\s+[0-9A-F]+)*)?;\s+([0-9A-F]+(?:\s+[0-9A-F]+)*)?;\s+(#.+?)?$/mg; | ||
|
|
||
| const folding = | ||
| /^([0-9A-F]+);\s+([CFS])?;\s+([0-9A-F]+(?:\s+[0-9A-F]+)*)?;\s+(#.+?)?$/mg; | ||
|
|
||
| const scData = {}; | ||
| const cfData = {}; | ||
|
|
||
| const rhex = a => parseInt(a, 16); | ||
| const sortHex = (a,b) => rhex(a) - rhex(b); | ||
|
|
||
| for (const spec of SpecialCasing.matchAll(special)) { | ||
|
MonoidMusician marked this conversation as resolved.
|
||
| if (scData[spec[1]]) die("Duplicate special case rule"); | ||
| scData[spec[1]] = spec; | ||
| } | ||
| for (const fold of CaseFolding.matchAll(folding)) { | ||
| if (cfData[fold[1]]) { | ||
| cfData[fold[1]][fold[2]] = fold; | ||
| } else { | ||
| cfData[fold[1]] = { [fold[2]]: fold }; | ||
| } | ||
| } | ||
|
|
||
| const scKeys = Object.keys(scData).sort(sortHex); | ||
| const cfKeys = Object.keys(cfData).sort(sortHex); | ||
| const keys = scKeys.concat(cfKeys).sort(sortHex); | ||
|
|
||
| const data = {}; | ||
|
|
||
| const hex = a => a ? '0x'+a : '0'; | ||
| const hexes = a => a ? '[' + a.split(' ').filter(b=>b).map(hex) + ']' : '[]'; | ||
|
|
||
| for (let code of keys) { | ||
| const d = { code: hex(code) }; | ||
| const sc = scData[code]; | ||
| d.lower = hexes(sc?.[2]); | ||
| d.title = hexes(sc?.[3]); | ||
| d.upper = hexes(sc?.[4]); | ||
| const cf = cfData[code]; | ||
| d.fold = hex(cf?.S?.[3] || cf?.C?.[3]); | ||
| d.foldFull = hexes(cf?.F?.[3] || cf?.C?.[3]); | ||
| data[code] = d; | ||
| } | ||
|
|
||
| const lines = keys.map(code => data[code]).map(d => | ||
| `{ code: ${d.code}, lower: ${d.lower}, title: ${d.title}, upper: ${d.upper}, fold: ${d.fold}, foldFull: ${d.foldFull} }` | ||
| ); | ||
|
|
||
|
|
||
|
|
||
| const file = `----------------------------------------------------------- | ||
| -- This is an automatically generated file: do not edit" | ||
| -- Generated by fullcase.js on ${new Date().toDateString()} | ||
| ----------------------------------------------------------- | ||
|
|
||
| module Data.CodePoint.Unicode.Internal.Casing where | ||
|
|
||
| import Prelude | ||
|
|
||
| import Data.Array as Array | ||
| import Data.CodePoint.Unicode.Internal (bsearch, uTowlower, uTowtitle, uTowupper) | ||
| import Data.Maybe (Maybe(..)) | ||
|
|
||
| type CaseRec = | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could we add documentation comments to this and the declarations throughout the file, as this is a public module? Simple ones are fine, but they can help guide maintainers in the future as well.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I moved it to a new Internal folder – users should not use these functions on |
||
| { | ||
| code :: Int, | ||
| lower :: Array Int, | ||
| title :: Array Int, | ||
| upper :: Array Int, | ||
| fold :: Int, | ||
| foldFull :: Array Int | ||
| } | ||
|
|
||
| rules :: Array CaseRec | ||
| rules = [ | ||
| ${lines.join(",\n ")} | ||
| ] | ||
|
|
||
| zeroRec :: Int -> CaseRec | ||
| zeroRec code = { code, lower: [], title: [], upper: [], fold: 0, foldFull: [] } | ||
|
|
||
| recCmp :: CaseRec -> CaseRec -> Ordering | ||
| recCmp { code } { code: code' } = compare code code' | ||
|
|
||
| findRule :: Int -> CaseRec | ||
| findRule code = case bsearch (zeroRec code) rules (Array.length rules) recCmp of | ||
| Nothing -> zeroRec code | ||
| Just r -> r | ||
|
|
||
| fold :: Int -> Int | ||
| fold code = | ||
| let folded = (findRule code).fold | ||
| in if folded == 0 then uTowlower code else folded | ||
|
|
||
| foldFull :: Int -> Array Int | ||
| foldFull code = | ||
| let folded = (findRule code).foldFull | ||
| in if Array.null folded then [uTowlower code] else folded | ||
|
|
||
| lower :: Int -> Array Int | ||
| lower code = | ||
| let lowered = (findRule code).lower | ||
| in if Array.null lowered then [uTowlower code] else lowered | ||
|
|
||
| title :: Int -> Array Int | ||
| title code = | ||
| let titled = (findRule code).title | ||
| in if Array.null titled then [uTowtitle code] else titled | ||
|
|
||
| upper :: Int -> Array Int | ||
| upper code = | ||
| let uppered = (findRule code).upper | ||
| in if Array.null uppered then [uTowupper code] else uppered | ||
| `; | ||
|
|
||
| fs.writeFileSync("src/Data/CodePoint/Unicode/Internal/Casing.purs", file); | ||
This file was deleted.
This file was deleted.
Uh oh!
There was an error while loading. Please reload this page.