aboutsummaryrefslogtreecommitdiff
path: root/src/pkg/datafmt
diff options
context:
space:
mode:
authorRuss Cox <rsc@golang.org>2009-06-29 15:24:23 -0700
committerRuss Cox <rsc@golang.org>2009-06-29 15:24:23 -0700
commitd3a412a5abf1ee8815b2e70a18ee092154af7672 (patch)
treeed3d700304a76b08cdca0f356605077c58ee0f76 /src/pkg/datafmt
parentb948c437a1173152cc375b5cb98cd322e9eaf30b (diff)
downloadgo-d3a412a5abf1ee8815b2e70a18ee092154af7672.tar.xz
io.StringBytes -> strings.Bytes
io.ByteBuffer -> bytes.Buffer left io.ByteBuffer stub around for now, for protocol compiler. R=r OCL=30861 CL=30872
Diffstat (limited to 'src/pkg/datafmt')
-rw-r--r--src/pkg/datafmt/datafmt.go19
-rw-r--r--src/pkg/datafmt/datafmt_test.go14
-rw-r--r--src/pkg/datafmt/parser.go3
3 files changed, 18 insertions, 18 deletions
diff --git a/src/pkg/datafmt/datafmt.go b/src/pkg/datafmt/datafmt.go
index 0aedbbbb0a..48c24e7264 100644
--- a/src/pkg/datafmt/datafmt.go
+++ b/src/pkg/datafmt/datafmt.go
@@ -12,7 +12,7 @@
A format specification is a set of package declarations and format rules:
Format = [ Entry { ";" Entry } [ ";" ] ] .
- Entry = PackageDecl | FormatRule .
+ Entry = PackageDecl | FormatRule .
(The syntax of a format specification is presented in the same EBNF
notation as used in the Go language specification. The syntax of white
@@ -111,7 +111,7 @@
The following example shows a complete format specification for a
struct 'myPackage.Point'. Assume the package
-
+
package myPackage // in directory myDir/myPackage
type Point struct {
name string;
@@ -155,7 +155,7 @@
Repetition = "{" Body [ "/" Separator ] "}" .
Separator = Expression .
-
+
A repeated expression is evaluated as follows: The body is evaluated
repeatedly and its results are concatenated until the body evaluates
to nil. The result of the repetition is the (possibly empty) concatenation,
@@ -202,6 +202,7 @@
package datafmt
import (
+ "bytes";
"container/vector";
"fmt";
"go/token";
@@ -306,8 +307,8 @@ type State struct {
env Environment; // user-supplied environment
errors chan os.Error; // not chan *Error (errors <- nil would be wrong!)
hasOutput bool; // true after the first literal has been written
- indent io.ByteBuffer; // current indentation
- output io.ByteBuffer; // format output
+ indent bytes.Buffer; // current indentation
+ output bytes.Buffer; // format output
linePos token.Position; // position of line beginning (Column == 0)
default_ expr; // possibly nil
separator expr; // possibly nil
@@ -418,7 +419,7 @@ func getField(val reflect.Value, fieldname string) (reflect.Value, int) {
if val.Kind() != reflect.StructKind {
return nil, 0;
}
-
+
sval, styp := val.(reflect.StructValue), val.Type().(reflect.StructType);
// look for field at the top level
@@ -450,7 +451,7 @@ func getField(val reflect.Value, fieldname string) (reflect.Value, int) {
}
}
}
-
+
return field, level + 1;
}
@@ -668,7 +669,7 @@ func (s *State) eval(fexpr expr, value reflect.Value, index int) bool {
s.restore(mark);
b = false;
}
-
+
// reset indentation
s.indent.Truncate(indentLen);
return b;
@@ -780,7 +781,7 @@ func (f Format) Print(args ...) (int, os.Error) {
// partially formatted result followed by an error message.
//
func (f Format) Sprint(args ...) string {
- var buf io.ByteBuffer;
+ var buf bytes.Buffer;
n, err := f.Fprint(&buf, nil, args);
if err != nil {
fmt.Fprintf(&buf, "--- Sprint(%s) failed: %v", fmt.Sprint(args), err);
diff --git a/src/pkg/datafmt/datafmt_test.go b/src/pkg/datafmt/datafmt_test.go
index 788c013c6e..9535494519 100644
--- a/src/pkg/datafmt/datafmt_test.go
+++ b/src/pkg/datafmt/datafmt_test.go
@@ -7,14 +7,14 @@ package datafmt
import (
"fmt";
"datafmt";
- "io";
"os";
+ "strings";
"testing";
)
func parse(t *testing.T, form string, fmap FormatterMap) Format {
- f, err := Parse(io.StringBytes(form), fmap);
+ f, err := Parse(strings.Bytes(form), fmap);
if err != nil {
t.Errorf("Parse(%s): %v", form, err);
return nil;
@@ -55,7 +55,7 @@ func formatter(s *State, value interface{}, rule_name string) bool {
case "nil":
return false;
case "testing.T":
- s.Write(io.StringBytes("testing.T"));
+ s.Write(strings.Bytes("testing.T"));
return true;
}
panic("unreachable");
@@ -115,7 +115,7 @@ func TestBasicTypes(t *testing.T) {
check(t, ``, ``);
check(t, `bool=":%v"`, `:true:false`, true, false);
check(t, `int="%b %d %o 0x%x"`, `101010 42 52 0x2a`, 42);
-
+
check(t, `int="%"`, `%`, 42);
check(t, `int="%%"`, `%`, 42);
check(t, `int="**%%**"`, `**%**`, 42);
@@ -259,13 +259,13 @@ const F2a =
`string = "%s";`
`ptr = *;`
`datafmt.T2 = s ["-" p "-"];`
-
+
const F2b =
F1 +
`string = "%s";`
`ptr = *;`
`datafmt.T2 = s ("-" p "-" | "empty");`;
-
+
func TestStruct2(t *testing.T) {
check(t, F2a, "foo", T2{"foo", nil});
check(t, F2a, "bar-<17>-", T2{"bar", &T1{17}});
@@ -366,7 +366,7 @@ func TestStructPoint(t *testing.T) {
const FSlice =
`int = "%b";`
`array = { * / ", " }`
-
+
func TestSlice(t *testing.T) {
check(t, FSlice, "10, 11, 101, 111", []int{2, 3, 5, 7});
}
diff --git a/src/pkg/datafmt/parser.go b/src/pkg/datafmt/parser.go
index 0d597dcb5f..17d4be982e 100644
--- a/src/pkg/datafmt/parser.go
+++ b/src/pkg/datafmt/parser.go
@@ -10,7 +10,6 @@ import (
"fmt";
"go/scanner";
"go/token";
- "io";
"os";
"strconv";
"strings";
@@ -194,7 +193,7 @@ func (p *parser) parseString() string {
func (p *parser) parseLiteral() literal {
- s := io.StringBytes(p.parseString());
+ s := strings.Bytes(p.parseString());
// A string literal may contain %-format specifiers. To simplify
// and speed up printing of the literal, split it into segments