aboutsummaryrefslogtreecommitdiff
path: root/scripts/regex/grapheme.sh
blob: 0b2b54daa2585995f3f83e48b9da4159c81d6767 (plain)
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
#!/bin/sh

# vim: indentexpr= nosmartindent autoindent
# vim: tabstop=2 shiftwidth=2 softtabstop=2

# This regex was manually written, derived from the rules in UAX #29.
# Particularly, from Table 1c, which lays out a regex for grapheme clusters.

CR="\p{gcb=CR}"
LF="\p{gcb=LF}"
Control="\p{gcb=Control}"
Prepend="\p{gcb=Prepend}"
L="\p{gcb=L}"
V="\p{gcb=V}"
LV="\p{gcb=LV}"
LVT="\p{gcb=LVT}"
T="\p{gcb=T}"
RI="\p{gcb=RI}"
Extend="\p{gcb=Extend}"
ZWJ="\p{gcb=ZWJ}"
SpacingMark="\p{gcb=SpacingMark}"

Any="\p{any}"
ExtendPict="\p{Extended_Pictographic}"

echo "(?x)
$CR $LF
|
$Control
|
$Prepend*
(
  (
    ($L* ($V+ | $LV $V* | $LVT) $T*)
    |
    $L+
    |
    $T+
  )
  |
  $RI $RI
  |
  $ExtendPict ($Extend* $ZWJ $ExtendPict)*
  |
  [^$Control $CR $LF]
)
[$Extend $ZWJ $SpacingMark]*
|
$Any
"