Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
G
golang
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
go
golang
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
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
22 additions
and
0 deletions
+22
-0
utf8.go
src/lib/utf8.go
+11
-0
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 {
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
// encodings are treated as single runes of width 1 byte.
func
RuneCount
(
p
[]
byte
)
int
{
...
...
src/lib/utf8_test.go
View file @
b923b016
...
...
@@ -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
)
{
for
i
:=
0
;
i
<
len
(
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