Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
go
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
go
Commits
b18e4184
Commit
b18e4184
authored
Mar 06, 2009
by
Rob Pike
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
document unicode, such as it is
R=rsc DELTA=18 (9 added, 0 deleted, 9 changed) OCL=25817 CL=25832
parent
6b8ac0a9
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
18 additions
and
9 deletions
+18
-9
src/lib/unicode/letter.go
src/lib/unicode/letter.go
+18
-9
No files found.
src/lib/unicode/letter.go
View file @
b18e4184
...
...
@@ -10,14 +10,19 @@
// link in only the tables that are used by the program,
// etc.
// This package provides data and functions to test some properties of Unicode code points.
// It is rudimentary but will improve.
package
unicode
// The representation of a range of Unicode code points. The range runs from Lo to Hi
// inclusive and has the specified stride.
type
Range
struct
{
l
o
int
;
h
i
int
;
s
tride
int
;
L
o
int
;
H
i
int
;
S
tride
int
;
}
// Upper is the set of Unicode upper case letters.
var
Upper
=
[]
Range
{
Range
{
0x0041
,
0x005a
,
1
},
Range
{
0x00c0
,
0x00d6
,
1
},
...
...
@@ -150,6 +155,7 @@ var Upper = []Range{
Range
{
0x1d7ca
,
0x1d7ca
,
1
},
}
// Letter is the set of Unicode letters.
var
Letter
=
[]
Range
{
Range
{
0x0041
,
0x005a
,
1
},
Range
{
0x0061
,
0x007a
,
1
},
...
...
@@ -525,18 +531,19 @@ var Letter = []Range {
Range
{
0x2f800
,
0x2fa1d
,
1
},
}
// Is tests whether rune is in the specified table of ranges.
func
Is
(
ranges
[]
Range
,
rune
int
)
bool
{
// common case: rune is ASCII or Latin-1
if
rune
<
0x100
{
for
i
:=
0
;
i
<
len
(
ranges
);
i
++
{
r
:=
ranges
[
i
];
if
rune
>
r
.
h
i
{
if
rune
>
r
.
H
i
{
continue
;
}
if
rune
<
r
.
l
o
{
if
rune
<
r
.
L
o
{
return
false
;
}
return
(
rune
-
r
.
lo
)
%
r
.
s
tride
==
0
;
return
(
rune
-
r
.
Lo
)
%
r
.
S
tride
==
0
;
}
return
false
;
}
...
...
@@ -547,10 +554,10 @@ func Is(ranges []Range, rune int) bool {
for
lo
<
hi
{
m
:=
lo
+
(
hi
-
lo
)
/
2
;
r
:=
ranges
[
m
];
if
r
.
lo
<=
rune
&&
rune
<=
r
.
h
i
{
return
(
rune
-
r
.
lo
)
%
r
.
s
tride
==
0
;
if
r
.
Lo
<=
rune
&&
rune
<=
r
.
H
i
{
return
(
rune
-
r
.
Lo
)
%
r
.
S
tride
==
0
;
}
if
rune
<
r
.
l
o
{
if
rune
<
r
.
L
o
{
hi
=
m
;
}
else
{
lo
=
m
+
1
;
...
...
@@ -559,10 +566,12 @@ func Is(ranges []Range, rune int) bool {
return
false
;
}
// IsLetter reports whether the rune is an upper case letter.
func
IsUpper
(
rune
int
)
bool
{
return
Is
(
Upper
,
rune
);
}
// IsLetter reports whether the rune is a letter.
func
IsLetter
(
rune
int
)
bool
{
return
Is
(
Letter
,
rune
);
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment