forked from edicl/cl-unicode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
alias.lisp
135 lines (123 loc) · 5 KB
/
alias.lisp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
;;; -*- Mode: LISP; Syntax: COMMON-LISP; Package: CL-UNICODE; Base: 10 -*-
;;; $Header: /usr/local/cvsrep/cl-unicode/alias.lisp,v 1.9 2012-05-04 21:17:43 edi Exp $
;;; Copyright (c) 2008-2012, Dr. Edmund Weitz. All rights reserved.
;;; Redistribution and use in source and binary forms, with or without
;;; modification, are permitted provided that the following conditions
;;; are met:
;;; * Redistributions of source code must retain the above copyright
;;; notice, this list of conditions and the following disclaimer.
;;; * Redistributions in binary form must reproduce the above
;;; copyright notice, this list of conditions and the following
;;; disclaimer in the documentation and/or other materials
;;; provided with the distribution.
;;; THIS SOFTWARE IS PROVIDED BY THE AUTHOR 'AS IS' AND ANY EXPRESSED
;;; OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
;;; WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
;;; ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
;;; DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
;;; DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
;;; GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
;;; INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
;;; WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
;;; NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
;;; SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
(in-package :cl-unicode)
(defvar *alias-map*
'(("L" . "Letter")
("LC" . "CasedLetter")
("Lu" . "UppercaseLetter")
("Ll" . "LowercaseLetter")
("Lt" . "TitlecaseLetter")
("Lm" . "ModifierLetter")
("Lo" . "OtherLetter")
("M" . "Mark")
("Mn" . "NonspacingMark")
("Mc" . "SpacingMark")
("Me" . "EnclosingMark")
("N" . "Number")
("Nd" . "DecimalNumber")
("Nl" . "LetterNumber")
("No" . "OtherNumber")
("P" . "Punctuation")
("Pc" . "ConnectorPunctuation")
("Pd" . "DashPunctuation")
("Ps" . "OpenPunctuation")
("Pe" . "ClosePunctuation")
("Pi" . "InitialPunctuation")
("Pf" . "FinalPunctuation")
("Po" . "OtherPunctuation")
("S" . "Symbol")
("Sm" . "MathSymbol")
("Sc" . "CurrencySymbol")
("Sk" . "ModifierSymbol")
("So" . "OtherSymbol")
("Z" . "Separator")
("Zs" . "SpaceSeparator")
("Zl" . "LineSeparator")
("Zp" . "ParagraphSeparator")
("C" . "Other")
("Cc" . "Control")
("Cf" . "Format")
("Cs" . "Surrogate")
("Co" . "PrivateUse")
("Cn" . "Unassigned")
("Cn" . "NoncharacterCodePoint")))
(defvar *bidi-alias-map*
'(("L" . "LeftToRight")
("LRE" . "LeftToRightEmbedding")
("LRO" . "LeftToRightOverride")
("R" . "RightToLeft")
("AL" . "RightToLeftArabic")
("RLE" . "RightToLeftEmbedding")
("RLO" . "RightToLeftOverride")
("PDF" . "PopDirectionalFormat")
("EN" . "EuropeanNumber")
("ES" . "EuropeanNumberSeparator")
("ET" . "EuropeanNumberTerminator")
("AN" . "ArabicNumber")
("CS" . "CommonNumberSeparator")
("NSM" . "NonSpacingMark")
("BN" . "BoundaryNeutral")
("B" . "ParagraphSeparator")
("S" . "SegmentSeparator")
("WS" . "Whitespace")
("ON" . "OtherNeutral")))
(defun create-alias (new-name old-name &optional only-if-unambiguous)
(setq new-name (canonicalize-name new-name)
old-name (canonicalize-name old-name))
(unless only-if-unambiguous
(assert (null (gethash new-name *property-map*)) (new-name)
"There is already a property named ~S." new-name))
(when (gethash new-name *property-map*)
(return-from create-alias))
(assert (gethash old-name *property-map*) (old-name)
"There is no property named ~S." old-name)
(setf (gethash new-name *property-map*)
(gethash old-name *property-map*)))
(defun create-aliases ()
(loop for (old-name . new-name) in *alias-map*
do (create-alias new-name old-name))
(loop for (old-name . new-name) in *bidi-alias-map*
do (create-alias (format nil "BidiClass:~A" new-name)
(format nil "BidiClass:~A" old-name)))
(loop for name in (scripts)
do (create-alias (format nil "Script:~A" name) name))
(loop for name in (loop for name being the hash-keys of *property-map*
collect name)
unless (ppcre:scan ":" name)
do (create-alias (format nil "Is~A" name) name))
(loop for name in (code-blocks)
do (create-alias (format nil "In~A" name) (format nil "Block:~A" name)))
(loop for name in (code-blocks)
do (create-alias name (format nil "Block:~A" name) t))
(loop for name in (bidi-classes)
do (create-alias name (format nil "BidiClass:~A" name) t))
(loop for (old-name . new-name) in *bidi-alias-map*
do (create-alias new-name (format nil "BidiClass:~A" old-name) t)))
(defun build-all-property-tests ()
(clrhash *property-map*)
(clrhash *property-tests*)
(install-tests)
(build-derived-test-functions)
(create-aliases))
(build-all-property-tests)