mirror of
https://github.com/golang/go
synced 2024-11-22 03:34:40 -07:00
container/vector: removed last instances of vector outside of container/vector itself from the core libs
R=gri CC=golang-dev https://golang.org/cl/4810078
This commit is contained in:
parent
68fea34be3
commit
ffc0830c75
@ -5,7 +5,6 @@
|
|||||||
package datafmt
|
package datafmt
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"container/vector"
|
|
||||||
"go/scanner"
|
"go/scanner"
|
||||||
"go/token"
|
"go/token"
|
||||||
"os"
|
"os"
|
||||||
@ -140,14 +139,14 @@ func (p *parser) parseLiteral() literal {
|
|||||||
// and speed up printing of the literal, split it into segments
|
// and speed up printing of the literal, split it into segments
|
||||||
// that start with "%" possibly followed by a last segment that
|
// that start with "%" possibly followed by a last segment that
|
||||||
// starts with some other character.
|
// starts with some other character.
|
||||||
var list vector.Vector
|
var list []interface{}
|
||||||
i0 := 0
|
i0 := 0
|
||||||
for i := 0; i < len(s); i++ {
|
for i := 0; i < len(s); i++ {
|
||||||
if s[i] == '%' && i+1 < len(s) {
|
if s[i] == '%' && i+1 < len(s) {
|
||||||
// the next segment starts with a % format
|
// the next segment starts with a % format
|
||||||
if i0 < i {
|
if i0 < i {
|
||||||
// the current segment is not empty, split it off
|
// the current segment is not empty, split it off
|
||||||
list.Push(s[i0:i])
|
list = append(list, s[i0:i])
|
||||||
i0 = i
|
i0 = i
|
||||||
}
|
}
|
||||||
i++ // skip %; let loop skip over char after %
|
i++ // skip %; let loop skip over char after %
|
||||||
@ -155,12 +154,12 @@ func (p *parser) parseLiteral() literal {
|
|||||||
}
|
}
|
||||||
// the final segment may start with any character
|
// the final segment may start with any character
|
||||||
// (it is empty iff the string is empty)
|
// (it is empty iff the string is empty)
|
||||||
list.Push(s[i0:])
|
list = append(list, s[i0:])
|
||||||
|
|
||||||
// convert list into a literal
|
// convert list into a literal
|
||||||
lit := make(literal, list.Len())
|
lit := make(literal, len(list))
|
||||||
for i := 0; i < list.Len(); i++ {
|
for i := 0; i < len(list); i++ {
|
||||||
lit[i] = list.At(i).([]byte)
|
lit[i] = list[i].([]byte)
|
||||||
}
|
}
|
||||||
|
|
||||||
return lit
|
return lit
|
||||||
@ -231,35 +230,35 @@ func (p *parser) parseOperand() (x expr) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (p *parser) parseSequence() expr {
|
func (p *parser) parseSequence() expr {
|
||||||
var list vector.Vector
|
var list []interface{}
|
||||||
|
|
||||||
for x := p.parseOperand(); x != nil; x = p.parseOperand() {
|
for x := p.parseOperand(); x != nil; x = p.parseOperand() {
|
||||||
list.Push(x)
|
list = append(list, x)
|
||||||
}
|
}
|
||||||
|
|
||||||
// no need for a sequence if list.Len() < 2
|
// no need for a sequence if list.Len() < 2
|
||||||
switch list.Len() {
|
switch len(list) {
|
||||||
case 0:
|
case 0:
|
||||||
return nil
|
return nil
|
||||||
case 1:
|
case 1:
|
||||||
return list.At(0).(expr)
|
return list[0].(expr)
|
||||||
}
|
}
|
||||||
|
|
||||||
// convert list into a sequence
|
// convert list into a sequence
|
||||||
seq := make(sequence, list.Len())
|
seq := make(sequence, len(list))
|
||||||
for i := 0; i < list.Len(); i++ {
|
for i := 0; i < len(list); i++ {
|
||||||
seq[i] = list.At(i).(expr)
|
seq[i] = list[i].(expr)
|
||||||
}
|
}
|
||||||
return seq
|
return seq
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *parser) parseExpression() expr {
|
func (p *parser) parseExpression() expr {
|
||||||
var list vector.Vector
|
var list []interface{}
|
||||||
|
|
||||||
for {
|
for {
|
||||||
x := p.parseSequence()
|
x := p.parseSequence()
|
||||||
if x != nil {
|
if x != nil {
|
||||||
list.Push(x)
|
list = append(list, x)
|
||||||
}
|
}
|
||||||
if p.tok != token.OR {
|
if p.tok != token.OR {
|
||||||
break
|
break
|
||||||
@ -268,17 +267,17 @@ func (p *parser) parseExpression() expr {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// no need for an alternatives if list.Len() < 2
|
// no need for an alternatives if list.Len() < 2
|
||||||
switch list.Len() {
|
switch len(list) {
|
||||||
case 0:
|
case 0:
|
||||||
return nil
|
return nil
|
||||||
case 1:
|
case 1:
|
||||||
return list.At(0).(expr)
|
return list[0].(expr)
|
||||||
}
|
}
|
||||||
|
|
||||||
// convert list into a alternatives
|
// convert list into a alternatives
|
||||||
alt := make(alternatives, list.Len())
|
alt := make(alternatives, len(list))
|
||||||
for i := 0; i < list.Len(); i++ {
|
for i := 0; i < len(list); i++ {
|
||||||
alt[i] = list.At(i).(expr)
|
alt[i] = list[i].(expr)
|
||||||
}
|
}
|
||||||
return alt
|
return alt
|
||||||
}
|
}
|
||||||
|
@ -5,7 +5,6 @@
|
|||||||
package scanner
|
package scanner
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"container/vector"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"go/token"
|
"go/token"
|
||||||
"io"
|
"io"
|
||||||
@ -32,14 +31,18 @@ type ErrorHandler interface {
|
|||||||
// error handling is obtained.
|
// error handling is obtained.
|
||||||
//
|
//
|
||||||
type ErrorVector struct {
|
type ErrorVector struct {
|
||||||
errors vector.Vector
|
errors []interface{}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Reset resets an ErrorVector to no errors.
|
// Reset resets an ErrorVector to no errors.
|
||||||
func (h *ErrorVector) Reset() { h.errors.Resize(0, 0) }
|
func (h *ErrorVector) Reset() {
|
||||||
|
h.errors = h.errors[:0]
|
||||||
|
}
|
||||||
|
|
||||||
// ErrorCount returns the number of errors collected.
|
// ErrorCount returns the number of errors collected.
|
||||||
func (h *ErrorVector) ErrorCount() int { return h.errors.Len() }
|
func (h *ErrorVector) ErrorCount() int {
|
||||||
|
return len(h.errors)
|
||||||
|
}
|
||||||
|
|
||||||
// Within ErrorVector, an error is represented by an Error node. The
|
// Within ErrorVector, an error is represented by an Error node. The
|
||||||
// position Pos, if valid, points to the beginning of the offending
|
// position Pos, if valid, points to the beginning of the offending
|
||||||
@ -110,13 +113,13 @@ const (
|
|||||||
// parameter. If there are no errors, the result is nil.
|
// parameter. If there are no errors, the result is nil.
|
||||||
//
|
//
|
||||||
func (h *ErrorVector) GetErrorList(mode int) ErrorList {
|
func (h *ErrorVector) GetErrorList(mode int) ErrorList {
|
||||||
if h.errors.Len() == 0 {
|
if len(h.errors) == 0 {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
list := make(ErrorList, h.errors.Len())
|
list := make(ErrorList, len(h.errors))
|
||||||
for i := 0; i < h.errors.Len(); i++ {
|
for i := 0; i < len(h.errors); i++ {
|
||||||
list[i] = h.errors.At(i).(*Error)
|
list[i] = h.errors[i].(*Error)
|
||||||
}
|
}
|
||||||
|
|
||||||
if mode >= Sorted {
|
if mode >= Sorted {
|
||||||
@ -144,7 +147,7 @@ func (h *ErrorVector) GetErrorList(mode int) ErrorList {
|
|||||||
// remains nil.
|
// remains nil.
|
||||||
//
|
//
|
||||||
func (h *ErrorVector) GetError(mode int) os.Error {
|
func (h *ErrorVector) GetError(mode int) os.Error {
|
||||||
if h.errors.Len() == 0 {
|
if len(h.errors) == 0 {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -153,7 +156,7 @@ func (h *ErrorVector) GetError(mode int) os.Error {
|
|||||||
|
|
||||||
// ErrorVector implements the ErrorHandler interface.
|
// ErrorVector implements the ErrorHandler interface.
|
||||||
func (h *ErrorVector) Error(pos token.Position, msg string) {
|
func (h *ErrorVector) Error(pos token.Position, msg string) {
|
||||||
h.errors.Push(&Error{pos, msg})
|
h.errors = append(h.errors, &Error{pos, msg})
|
||||||
}
|
}
|
||||||
|
|
||||||
// PrintError is a utility function that prints a list of errors to w,
|
// PrintError is a utility function that prints a list of errors to w,
|
||||||
|
Loading…
Reference in New Issue
Block a user