summaryrefslogtreecommitdiff
path: root/src/pkg/net/parse.go
diff options
context:
space:
mode:
authorRobert Griesemer <gri@golang.org>2009-12-15 15:35:38 -0800
committerRobert Griesemer <gri@golang.org>2009-12-15 15:35:38 -0800
commite4bd81f903362d998f7bfc02095935408aff0bc5 (patch)
tree05f75a90e239d33be427da4f9c5596d2fcb3dc96 /src/pkg/net/parse.go
parentd9527dd16f72598b54a64550607bf892efa12384 (diff)
downloadgolang-e4bd81f903362d998f7bfc02095935408aff0bc5.tar.gz
1) Change default gofmt default settings for
parsing and printing to new syntax. Use -oldparser to parse the old syntax, use -oldprinter to print the old syntax. 2) Change default gofmt formatting settings to use tabs for indentation only and to use spaces for alignment. This will make the code alignment insensitive to an editor's tabwidth. Use -spaces=false to use tabs for alignment. 3) Manually changed src/exp/parser/parser_test.go so that it doesn't try to parse the parser's source files using the old syntax (they have new syntax now). 4) gofmt -w src misc test/bench 3rd set of files. R=rsc CC=golang-dev http://codereview.appspot.com/180048
Diffstat (limited to 'src/pkg/net/parse.go')
-rw-r--r--src/pkg/net/parse.go118
1 files changed, 59 insertions, 59 deletions
diff --git a/src/pkg/net/parse.go b/src/pkg/net/parse.go
index c93f8335c..a7dcb35f0 100644
--- a/src/pkg/net/parse.go
+++ b/src/pkg/net/parse.go
@@ -8,34 +8,34 @@
package net
import (
- "io";
- "os";
+ "io"
+ "os"
)
type file struct {
- file *os.File;
- data []byte;
+ file *os.File
+ data []byte
}
-func (f *file) close() { f.file.Close() }
+func (f *file) close() { f.file.Close() }
func (f *file) getLineFromData() (s string, ok bool) {
- data := f.data;
+ data := f.data
for i := 0; i < len(data); i++ {
if data[i] == '\n' {
- s = string(data[0:i]);
- ok = true;
+ s = string(data[0:i])
+ ok = true
// move data
- i++;
- n := len(data) - i;
+ i++
+ n := len(data) - i
for j := 0; j < n; j++ {
data[j] = data[i+j]
}
- f.data = data[0:n];
- return;
+ f.data = data[0:n]
+ return
}
}
- return;
+ return
}
func (f *file) readLine() (s string, ok bool) {
@@ -43,22 +43,22 @@ func (f *file) readLine() (s string, ok bool) {
return
}
if len(f.data) < cap(f.data) {
- ln := len(f.data);
- n, _ := io.ReadFull(f.file, f.data[ln:cap(f.data)]);
+ ln := len(f.data)
+ n, _ := io.ReadFull(f.file, f.data[ln:cap(f.data)])
if n >= 0 {
f.data = f.data[0 : ln+n]
}
}
- s, ok = f.getLineFromData();
- return;
+ s, ok = f.getLineFromData()
+ return
}
func open(name string) (*file, os.Error) {
- fd, err := os.Open(name, os.O_RDONLY, 0);
+ fd, err := os.Open(name, os.O_RDONLY, 0)
if err != nil {
return nil, err
}
- return &file{fd, make([]byte, 1024)[0:0]}, nil;
+ return &file{fd, make([]byte, 1024)[0:0]}, nil
}
func byteIndex(s string, c byte) int {
@@ -67,42 +67,42 @@ func byteIndex(s string, c byte) int {
return i
}
}
- return -1;
+ return -1
}
// Count occurrences in s of any bytes in t.
func countAnyByte(s string, t string) int {
- n := 0;
+ n := 0
for i := 0; i < len(s); i++ {
if byteIndex(t, s[i]) >= 0 {
n++
}
}
- return n;
+ return n
}
// Split s at any bytes in t.
func splitAtBytes(s string, t string) []string {
- a := make([]string, 1+countAnyByte(s, t));
- n := 0;
- last := 0;
+ a := make([]string, 1+countAnyByte(s, t))
+ n := 0
+ last := 0
for i := 0; i < len(s); i++ {
if byteIndex(t, s[i]) >= 0 {
if last < i {
- a[n] = string(s[last:i]);
- n++;
+ a[n] = string(s[last:i])
+ n++
}
- last = i + 1;
+ last = i + 1
}
}
if last < len(s) {
- a[n] = string(s[last:]);
- n++;
+ a[n] = string(s[last:])
+ n++
}
- return a[0:n];
+ return a[0:n]
}
-func getFields(s string) []string { return splitAtBytes(s, " \r\t\n") }
+func getFields(s string) []string { return splitAtBytes(s, " \r\t\n") }
// Bigger than we need, not too big to worry about overflow
const big = 0xFFFFFF
@@ -110,9 +110,9 @@ const big = 0xFFFFFF
// Decimal to integer starting at &s[i0].
// Returns number, new offset, success.
func dtoi(s string, i0 int) (n int, i int, ok bool) {
- n = 0;
+ n = 0
for i = i0; i < len(s) && '0' <= s[i] && s[i] <= '9'; i++ {
- n = n*10 + int(s[i]-'0');
+ n = n*10 + int(s[i]-'0')
if n >= big {
return 0, i, false
}
@@ -120,23 +120,23 @@ func dtoi(s string, i0 int) (n int, i int, ok bool) {
if i == i0 {
return 0, i, false
}
- return n, i, true;
+ return n, i, true
}
// Hexadecimal to integer starting at &s[i0].
// Returns number, new offset, success.
func xtoi(s string, i0 int) (n int, i int, ok bool) {
- n = 0;
+ n = 0
for i = i0; i < len(s); i++ {
if '0' <= s[i] && s[i] <= '9' {
- n *= 16;
- n += int(s[i] - '0');
+ n *= 16
+ n += int(s[i] - '0')
} else if 'a' <= s[i] && s[i] <= 'f' {
- n *= 16;
- n += int(s[i]-'a') + 10;
+ n *= 16
+ n += int(s[i]-'a') + 10
} else if 'A' <= s[i] && s[i] <= 'F' {
- n *= 16;
- n += int(s[i]-'A') + 10;
+ n *= 16
+ n += int(s[i]-'A') + 10
} else {
break
}
@@ -147,49 +147,49 @@ func xtoi(s string, i0 int) (n int, i int, ok bool) {
if i == i0 {
return 0, i, false
}
- return n, i, true;
+ return n, i, true
}
// Integer to decimal.
func itoa(i int) string {
- var buf [30]byte;
- n := len(buf);
- neg := false;
+ var buf [30]byte
+ n := len(buf)
+ neg := false
if i < 0 {
- i = -i;
- neg = true;
+ i = -i
+ neg = true
}
- ui := uint(i);
+ ui := uint(i)
for ui > 0 || n == len(buf) {
- n--;
- buf[n] = byte('0' + ui%10);
- ui /= 10;
+ n--
+ buf[n] = byte('0' + ui%10)
+ ui /= 10
}
if neg {
- n--;
- buf[n] = '-';
+ n--
+ buf[n] = '-'
}
- return string(buf[n:]);
+ return string(buf[n:])
}
// Number of occurrences of b in s.
func count(s string, b byte) int {
- n := 0;
+ n := 0
for i := 0; i < len(s); i++ {
if s[i] == b {
n++
}
}
- return n;
+ return n
}
// Index of rightmost occurrence of b in s.
func last(s string, b byte) int {
- i := len(s);
+ i := len(s)
for i--; i >= 0; i-- {
if s[i] == b {
break
}
}
- return i;
+ return i
}