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
508277de
Commit
508277de
authored
Nov 24, 2008
by
Robert Griesemer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
bufio.ReadRune
R=rsc DELTA=32 (29 added, 0 deleted, 3 changed) OCL=19809 CL=19913
parent
0432a343
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
32 additions
and
3 deletions
+32
-3
bufio.go
src/lib/bufio.go
+31
-3
utf8.go
src/lib/utf8.go
+1
-0
No files found.
src/lib/bufio.go
View file @
508277de
...
@@ -3,8 +3,12 @@
...
@@ -3,8 +3,12 @@
// license that can be found in the LICENSE file.
// license that can be found in the LICENSE file.
package
bufio
package
bufio
import
"os"
import
"io"
import
(
"os"
;
"io"
;
"utf8"
;
)
// TODO:
// TODO:
...
@@ -65,7 +69,7 @@ func (b *BufRead) Fill() *os.Error {
...
@@ -65,7 +69,7 @@ func (b *BufRead) Fill() *os.Error {
}
}
// Slide existing data to beginning.
// Slide existing data to beginning.
if
b
.
w
>
b
.
r
{
if
b
.
w
>
b
.
r
{
CopySlice
(
b
.
buf
[
0
:
b
.
w
-
b
.
r
],
b
.
buf
[
b
.
r
:
b
.
w
]);
CopySlice
(
b
.
buf
[
0
:
b
.
w
-
b
.
r
],
b
.
buf
[
b
.
r
:
b
.
w
]);
b
.
w
-=
b
.
r
;
b
.
w
-=
b
.
r
;
}
else
{
}
else
{
...
@@ -140,6 +144,30 @@ func (b *BufRead) UnreadByte() *os.Error {
...
@@ -140,6 +144,30 @@ func (b *BufRead) UnreadByte() *os.Error {
return
nil
return
nil
}
}
// Read a single Unicode character; returns the rune and its size.
func
(
b
*
BufRead
)
ReadRune
()
(
rune
int
,
size
int
,
err
*
os
.
Error
)
{
for
b
.
r
+
utf8
.
UTFMax
>
b
.
w
&&
!
utf8
.
FullRune
(
b
.
buf
[
b
.
r
:
b
.
w
])
{
n
:=
b
.
w
-
b
.
r
;
b
.
Fill
();
if
b
.
err
!=
nil
{
return
0
,
0
,
b
.
err
}
if
b
.
w
-
b
.
r
==
n
{
// no bytes read
if
b
.
r
==
b
.
w
{
return
0
,
0
,
EndOfFile
}
break
;
}
}
rune
,
size
=
int
(
b
.
buf
[
b
.
r
]),
1
;
if
rune
>=
0x80
{
rune
,
size
=
utf8
.
DecodeRune
(
b
.
buf
[
b
.
r
:
b
.
w
]);
}
b
.
r
+=
size
;
return
rune
,
size
,
nil
}
// Helper function: look for byte c in array p,
// Helper function: look for byte c in array p,
// returning its index or -1.
// returning its index or -1.
func
FindByte
(
p
*
[]
byte
,
c
byte
)
int
{
func
FindByte
(
p
*
[]
byte
,
c
byte
)
int
{
...
...
src/lib/utf8.go
View file @
508277de
...
@@ -7,6 +7,7 @@
...
@@ -7,6 +7,7 @@
package
utf8
package
utf8
export
const
(
export
const
(
UTFMax
=
4
;
RuneError
=
0xFFFD
;
RuneError
=
0xFFFD
;
RuneSelf
=
0x80
;
RuneSelf
=
0x80
;
RuneMax
=
1
<<
21
-
1
;
RuneMax
=
1
<<
21
-
1
;
...
...
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