diff --git a/src/pkg/old/regexp/regexp.go b/src/pkg/old/regexp/regexp.go index e8d4c087cf8..f18d9c8f592 100644 --- a/src/pkg/old/regexp/regexp.go +++ b/src/pkg/old/regexp/regexp.go @@ -119,7 +119,7 @@ type instr struct { index int // used only in debugging; could be eliminated next *instr // the instruction to execute after this one // Special fields valid only for some items. - char int // iChar + char rune // iChar braNum int // iBra, iEbra cclass *charClass // iCharClass left *instr // iAlt, other branch @@ -172,8 +172,8 @@ type Regexp struct { type charClass struct { negate bool // is character class negated? ([^a-z]) // slice of int, stored pairwise: [a-z] is (a,z); x is (x,x): - ranges []int - cmin, cmax int + ranges []rune + cmin, cmax rune } func (cclass *charClass) print() { @@ -192,7 +192,7 @@ func (cclass *charClass) print() { } } -func (cclass *charClass) addRange(a, b int) { +func (cclass *charClass) addRange(a, b rune) { // range is a through b inclusive cclass.ranges = append(cclass.ranges, a, b) if a < cclass.cmin { @@ -203,7 +203,7 @@ func (cclass *charClass) addRange(a, b int) { } } -func (cclass *charClass) matches(c int) bool { +func (cclass *charClass) matches(c rune) bool { if c < cclass.cmin || c > cclass.cmax { return cclass.negate } @@ -219,7 +219,7 @@ func (cclass *charClass) matches(c int) bool { func newCharClass() *instr { i := &instr{kind: iCharClass} i.cclass = new(charClass) - i.cclass.ranges = make([]int, 0, 4) + i.cclass.ranges = make([]rune, 0, 4) i.cclass.cmin = 0x10FFFF + 1 // MaxRune + 1 i.cclass.cmax = -1 return i @@ -235,7 +235,7 @@ type parser struct { re *Regexp nlpar int // number of unclosed lpars pos int - ch int + ch rune } func (p *parser) error(err Error) { @@ -244,9 +244,9 @@ func (p *parser) error(err Error) { const endOfText = -1 -func (p *parser) c() int { return p.ch } +func (p *parser) c() rune { return p.ch } -func (p *parser) nextc() int { +func (p *parser) nextc() rune { if p.pos >= len(p.re.expr) { p.ch = endOfText } else { @@ -264,7 +264,7 @@ func newParser(re *Regexp) *parser { return p } -func special(c int) bool { +func special(c rune) bool { for _, r := range `\.+*?()|[]^$` { if c == r { return true @@ -273,7 +273,7 @@ func special(c int) bool { return false } -func ispunct(c int) bool { +func ispunct(c rune) bool { for _, r := range "!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~" { if c == r { return true @@ -285,16 +285,16 @@ func ispunct(c int) bool { var escapes = []byte("abfnrtv") var escaped = []byte("\a\b\f\n\r\t\v") -func escape(c int) int { +func escape(c rune) int { for i, b := range escapes { - if int(b) == c { + if rune(b) == c { return i } } return -1 } -func (p *parser) checkBackslash() int { +func (p *parser) checkBackslash() rune { c := p.c() if c == '\\' { c = p.nextc() @@ -304,7 +304,7 @@ func (p *parser) checkBackslash() int { case ispunct(c): // c is as delivered case escape(c) >= 0: - c = int(escaped[escape(c)]) + c = rune(escaped[escape(c)]) default: p.error(ErrBadBackslash) } @@ -319,7 +319,7 @@ func (p *parser) charClass() *instr { cc.negate = true p.nextc() } - left := -1 + left := rune(-1) for { switch c := p.c(); c { case ']', endOfText: @@ -751,8 +751,8 @@ func (a *matchArena) addState(s []state, inst *instr, prefixed bool, match *matc // input abstracts different representations of the input text. It provides // one-character lookahead. type input interface { - step(pos int) (rune int, width int) // advance one rune - canCheckPrefix() bool // can we look ahead without losing info? + step(pos int) (r rune, width int) // advance one rune + canCheckPrefix() bool // can we look ahead without losing info? hasPrefix(re *Regexp) bool index(re *Regexp, pos int) int } @@ -766,7 +766,7 @@ func newInputString(str string) *inputString { return &inputString{str: str} } -func (i *inputString) step(pos int) (int, int) { +func (i *inputString) step(pos int) (rune, int) { if pos < len(i.str) { return utf8.DecodeRuneInString(i.str[pos:len(i.str)]) } @@ -794,7 +794,7 @@ func newInputBytes(str []byte) *inputBytes { return &inputBytes{str: str} } -func (i *inputBytes) step(pos int) (int, int) { +func (i *inputBytes) step(pos int) (rune, int) { if pos < len(i.str) { return utf8.DecodeRune(i.str[pos:len(i.str)]) } @@ -824,7 +824,7 @@ func newInputReader(r io.RuneReader) *inputReader { return &inputReader{r: r} } -func (i *inputReader) step(pos int) (int, int) { +func (i *inputReader) step(pos int) (rune, int) { if !i.atEOT && pos != i.pos { return endOfText, 0 @@ -886,7 +886,7 @@ func (re *Regexp) doExecute(i input, pos int) []int { atBOT: pos == 0, atEOT: nextChar == endOfText, } - for c, startPos := 0, pos; c != endOfText; { + for c, startPos := rune(0), pos; c != endOfText; { if !found && (pos == startPos || !anchored) { // prime the pump if we haven't seen a match yet match := arena.noMatch() @@ -966,7 +966,7 @@ func (re *Regexp) doExecute(i input, pos int) []int { // of the regular expression re. It returns the boolean true if the // literal string comprises the entire regular expression. func (re *Regexp) LiteralPrefix() (prefix string, complete bool) { - c := make([]int, len(re.inst)-2) // minus start and end. + c := make([]rune, len(re.inst)-2) // minus start and end. // First instruction is start; skip that. i := 0 for inst := re.inst[0].next; inst.kind != iEnd; inst = inst.next { @@ -1141,7 +1141,7 @@ func QuoteMeta(s string) string { // A byte loop is correct because all metacharacters are ASCII. j := 0 for i := 0; i < len(s); i++ { - if special(int(s[i])) { + if special(rune(s[i])) { b[j] = '\\' j++ } diff --git a/src/pkg/old/template/parse.go b/src/pkg/old/template/parse.go index dedf9ad8e9f..9f8d1eba338 100644 --- a/src/pkg/old/template/parse.go +++ b/src/pkg/old/template/parse.go @@ -146,8 +146,8 @@ func (t *Template) parseError(err string, args ...interface{}) { // Is this an exported - upper case - name? func isExported(name string) bool { - rune, _ := utf8.DecodeRuneInString(name) - return unicode.IsUpper(rune) + r, _ := utf8.DecodeRuneInString(name) + return unicode.IsUpper(r) } // -- Lexical analysis @@ -419,7 +419,7 @@ func (t *Template) newVariable(words []string) *variableElement { case '"', '`', '\'': v, err := strconv.Unquote(word) if err == nil && word[0] == '\'' { - args[i] = []int(v)[0] + args[i], _ = utf8.DecodeRuneInString(v) } else { args[i], lerr = v, err } diff --git a/src/pkg/template/exec_test.go b/src/pkg/template/exec_test.go index 50b0ad2b75f..6c19f116b81 100644 --- a/src/pkg/template/exec_test.go +++ b/src/pkg/template/exec_test.go @@ -644,7 +644,7 @@ func TestTree(t *testing.T) { if err != nil { t.Fatal("exec error:", err) } - stripSpace := func(r int) int { + stripSpace := func(r rune) rune { if r == '\t' || r == '\n' { return -1 } diff --git a/src/pkg/template/funcs.go b/src/pkg/template/funcs.go index feb1fd82c72..938559eec96 100644 --- a/src/pkg/template/funcs.go +++ b/src/pkg/template/funcs.go @@ -279,7 +279,7 @@ func JSEscape(w io.Writer, b []byte) { for i := 0; i < len(b); i++ { c := b[i] - if !jsIsSpecial(int(c)) { + if !jsIsSpecial(rune(c)) { // fast path: nothing to do continue } @@ -307,12 +307,12 @@ func JSEscape(w io.Writer, b []byte) { } } else { // Unicode rune. - rune, size := utf8.DecodeRune(b[i:]) - if unicode.IsPrint(rune) { + r, size := utf8.DecodeRune(b[i:]) + if unicode.IsPrint(r) { w.Write(b[i : i+size]) } else { // TODO(dsymonds): Do this without fmt? - fmt.Fprintf(w, "\\u%04X", rune) + fmt.Fprintf(w, "\\u%04X", r) } i += size - 1 } @@ -332,12 +332,12 @@ func JSEscapeString(s string) string { return b.String() } -func jsIsSpecial(rune int) bool { - switch rune { +func jsIsSpecial(r rune) bool { + switch r { case '\\', '\'', '"', '<', '>': return true } - return rune < ' ' || utf8.RuneSelf <= rune + return r < ' ' || utf8.RuneSelf <= r } // JSEscaper returns the escaped JavaScript equivalent of the textual diff --git a/src/pkg/template/parse/lex.go b/src/pkg/template/parse/lex.go index 16ff590d3b4..04c105d1610 100644 --- a/src/pkg/template/parse/lex.go +++ b/src/pkg/template/parse/lex.go @@ -131,21 +131,21 @@ type lexer struct { } // next returns the next rune in the input. -func (l *lexer) next() (rune int) { +func (l *lexer) next() (r rune) { if l.pos >= len(l.input) { l.width = 0 return eof } - rune, l.width = utf8.DecodeRuneInString(l.input[l.pos:]) + r, l.width = utf8.DecodeRuneInString(l.input[l.pos:]) l.pos += l.width - return rune + return r } // peek returns but does not consume the next rune in the input. -func (l *lexer) peek() int { - rune := l.next() +func (l *lexer) peek() rune { + r := l.next() l.backup() - return rune + return r } // backup steps back one rune. Can only be called once per call of next. @@ -468,7 +468,7 @@ Loop: } // isSpace reports whether r is a space character. -func isSpace(r int) bool { +func isSpace(r rune) bool { switch r { case ' ', '\t', '\n', '\r': return true @@ -477,6 +477,6 @@ func isSpace(r int) bool { } // isAlphaNumeric reports whether r is an alphabetic, digit, or underscore. -func isAlphaNumeric(r int) bool { +func isAlphaNumeric(r rune) bool { return r == '_' || unicode.IsLetter(r) || unicode.IsDigit(r) }