Skip to content

Commit 012557b

Browse files
martischbradfitz
authored andcommitted
all: replace magic 0x80 with named constant utf8.RuneSelf
Change-Id: Id1c2e8e9d60588de866e8b6ca59cc83dd28f848f Reviewed-on: https://go-review.googlesource.com/21756 Reviewed-by: Brad Fitzpatrick <[email protected]> Run-TryBot: Brad Fitzpatrick <[email protected]> TryBot-Result: Gobot Gobot <[email protected]>
1 parent 527ffeb commit 012557b

File tree

8 files changed

+11
-10
lines changed

8 files changed

+11
-10
lines changed

src/bufio/bufio.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ func (b *Reader) ReadRune() (r rune, size int, err error) {
266266
return 0, 0, b.readErr()
267267
}
268268
r, size = rune(b.buf[b.r]), 1
269-
if r >= 0x80 {
269+
if r >= utf8.RuneSelf {
270270
r, size = utf8.DecodeRune(b.buf[b.r:b.w])
271271
}
272272
b.r += size

src/cmd/compile/internal/gc/fmt.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ func Vconv(v Val, flag FmtFlag) string {
337337

338338
case CTRUNE:
339339
x := v.U.(*Mpint).Int64()
340-
if ' ' <= x && x < 0x80 && x != '\\' && x != '\'' {
340+
if ' ' <= x && x < utf8.RuneSelf && x != '\\' && x != '\'' {
341341
return fmt.Sprintf("'%c'", int(x))
342342
}
343343
if 0 <= x && x < 1<<16 {

src/encoding/asn1/asn1.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,7 @@ func isPrintable(b byte) bool {
393393
// byte slice and returns it.
394394
func parseIA5String(bytes []byte) (ret string, err error) {
395395
for _, b := range bytes {
396-
if b >= 0x80 {
396+
if b >= utf8.RuneSelf {
397397
err = SyntaxError{"IA5String contains invalid character"}
398398
return
399399
}

src/go/build/build.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1266,7 +1266,7 @@ func safeCgoName(s string, spaces bool) bool {
12661266
safe = safe[len(safeSpaces):]
12671267
}
12681268
for i := 0; i < len(s); i++ {
1269-
if c := s[i]; c < 0x80 && bytes.IndexByte(safe, c) < 0 {
1269+
if c := s[i]; c < utf8.RuneSelf && bytes.IndexByte(safe, c) < 0 {
12701270
return false
12711271
}
12721272
}

src/go/build/read.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"bufio"
99
"errors"
1010
"io"
11+
"unicode/utf8"
1112
)
1213

1314
type importReader struct {
@@ -20,7 +21,7 @@ type importReader struct {
2021
}
2122

2223
func isIdent(c byte) bool {
23-
return 'A' <= c && c <= 'Z' || 'a' <= c && c <= 'z' || '0' <= c && c <= '9' || c == '_' || c >= 0x80
24+
return 'A' <= c && c <= 'Z' || 'a' <= c && c <= 'z' || '0' <= c && c <= '9' || c == '_' || c >= utf8.RuneSelf
2425
}
2526

2627
var (

src/go/scanner/scanner.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ func (s *Scanner) next() {
6464
switch {
6565
case r == 0:
6666
s.error(s.offset, "illegal character NUL")
67-
case r >= 0x80:
67+
case r >= utf8.RuneSelf:
6868
// not ASCII
6969
r, w = utf8.DecodeRune(s.src[s.rdOffset:])
7070
if r == utf8.RuneError && w == 1 {
@@ -255,11 +255,11 @@ func (s *Scanner) findLineEnd() bool {
255255
}
256256

257257
func isLetter(ch rune) bool {
258-
return 'a' <= ch && ch <= 'z' || 'A' <= ch && ch <= 'Z' || ch == '_' || ch >= 0x80 && unicode.IsLetter(ch)
258+
return 'a' <= ch && ch <= 'z' || 'A' <= ch && ch <= 'Z' || ch == '_' || ch >= utf8.RuneSelf && unicode.IsLetter(ch)
259259
}
260260

261261
func isDigit(ch rune) bool {
262-
return '0' <= ch && ch <= '9' || ch >= 0x80 && unicode.IsDigit(ch)
262+
return '0' <= ch && ch <= '9' || ch >= utf8.RuneSelf && unicode.IsDigit(ch)
263263
}
264264

265265
func (s *Scanner) scanIdentifier() string {

src/html/template/css.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ func cssValueFilter(args ...interface{}) string {
243243
return filterFailsafe
244244
}
245245
default:
246-
if c < 0x80 && isCSSNmchar(rune(c)) {
246+
if c < utf8.RuneSelf && isCSSNmchar(rune(c)) {
247247
id = append(id, c)
248248
}
249249
}

src/net/http/cookiejar/punycode.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ func encode(prefix, s string) (string, error) {
3737
delta, n, bias := int32(0), initialN, initialBias
3838
b, remaining := int32(0), int32(0)
3939
for _, r := range s {
40-
if r < 0x80 {
40+
if r < utf8.RuneSelf {
4141
b++
4242
output = append(output, byte(r))
4343
} else {

0 commit comments

Comments
 (0)