-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreadrune.go
51 lines (44 loc) · 1.01 KB
/
readrune.go
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
51
package base64
import (
"errors"
"io"
"github.com/reiver/go-ascii"
"sourcecode.social/reiver/go-erorr"
"sourcecode.social/reiver/go-utf8"
)
// readRune returns the next rune that isn't a LF, CR, or SP.
//
// The decoding of something base64-encoded ignores LF, CR. and SP.
// So, readRune keeps reading runes until it receives a rune that isn't
// a LF, CR, or SP. I.e., it ignores LF, CR, or SP.
func readRune(reader io.Reader) (rune, error) {
if nil == reader {
return 0, errNilReader
}
var r rune
loop: for {
var size int
var err error
r, size, err = utf8.ReadRune(reader)
if errors.Is(err, io.EOF) {
return 0, io.EOF
}
if nil != err {
return 0, erorr.Errorf("base64: problem reading rune: %w", err)
}
if size <= 0 {
return 0, erorr.Errorf("base64: expected size of read rune to be greater-than 0 but actually was %d", size)
}
switch r {
case ascii.LF:
continue loop
case ascii.CR:
continue loop
case ascii.SP:
continue loop
default:
break loop
}
}
return r, nil
}