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
b923b016
Commit
b923b016
authored
Mar 26, 2009
by
Robert Griesemer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
EncodeRuneToString
R=rsc DELTA=22 (22 added, 0 deleted, 0 changed) OCL=26779 CL=26792
parent
cc8e4fb4
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
22 additions
and
0 deletions
+22
-0
src/lib/utf8.go
src/lib/utf8.go
+11
-0
src/lib/utf8_test.go
src/lib/utf8_test.go
+11
-0
No files found.
src/lib/utf8.go
View file @
b923b016
...
@@ -256,6 +256,17 @@ func EncodeRune(rune int, p []byte) int {
...
@@ -256,6 +256,17 @@ func EncodeRune(rune int, p []byte) int {
return
4
;
return
4
;
}
}
// EncodeRuneToString returns the string corresponding to the UTF-8 encoding of the rune.
func
EncodeRuneToString
(
rune
int
)
string
{
if
rune
<
_Rune1Max
{
return
string
([
1
]
byte
{
byte
(
rune
)})
}
var
buf
[
UTFMax
]
byte
;
size
:=
EncodeRune
(
rune
,
buf
);
return
string
(
buf
[
0
:
size
]);
}
// RuneCount returns the number of runes in p. Erroneous and short
// RuneCount returns the number of runes in p. Erroneous and short
// encodings are treated as single runes of width 1 byte.
// encodings are treated as single runes of width 1 byte.
func
RuneCount
(
p
[]
byte
)
int
{
func
RuneCount
(
p
[]
byte
)
int
{
...
...
src/lib/utf8_test.go
View file @
b923b016
...
@@ -98,6 +98,17 @@ func TestEncodeRune(t *testing.T) {
...
@@ -98,6 +98,17 @@ func TestEncodeRune(t *testing.T) {
}
}
}
}
func
TestEncodeRuneToString
(
t
*
testing
.
T
)
{
for
i
:=
0
;
i
<
len
(
utf8map
);
i
++
{
m
:=
utf8map
[
i
];
s
:=
m
.
str
;
s1
:=
utf8
.
EncodeRuneToString
(
m
.
rune
);
if
s
!=
s1
{
t
.
Errorf
(
"EncodeRuneToString(0x%04x) = %s want %s"
,
m
.
rune
,
s1
,
s
);
}
}
}
func
TestDecodeRune
(
t
*
testing
.
T
)
{
func
TestDecodeRune
(
t
*
testing
.
T
)
{
for
i
:=
0
;
i
<
len
(
utf8map
);
i
++
{
for
i
:=
0
;
i
<
len
(
utf8map
);
i
++
{
m
:=
utf8map
[
i
];
m
:=
utf8map
[
i
];
...
...
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