summaryrefslogtreecommitdiff
path: root/libgo/go/bytes
diff options
context:
space:
mode:
authorIan Lance Taylor <iant@google.com>2014-06-04 23:15:33 +0000
committerIan Lance Taylor <ian@gcc.gnu.org>2014-06-04 23:15:33 +0000
commitbae90c989cb020d17a24919ec84c0b8dd2fae2da (patch)
tree89766166feb4ceca2d983169c5360e3f6f521b12 /libgo/go/bytes
parent82b3da6a714493644a4333bfd8205e3341ed3b8e (diff)
downloadgcc-bae90c989cb020d17a24919ec84c0b8dd2fae2da.tar.gz
libgo: Merge from revision 18783:00cce3a34d7e of master library.
This revision was committed January 7, 2014. The next revision deleted runtime/mfinal.c. That will be done in a subsequent merge. This merge changes type descriptors to add a zero field, pointing to a zero value for that type. This is implemented as a common variable. * go-gcc.cc (Gcc_backend::implicit_variable): Add is_common and alignment parameters. Permit init parameter to be NULL. From-SVN: r211249
Diffstat (limited to 'libgo/go/bytes')
-rw-r--r--libgo/go/bytes/bytes.go4
-rw-r--r--libgo/go/bytes/bytes_test.go20
-rw-r--r--libgo/go/bytes/compare_test.go4
3 files changed, 26 insertions, 2 deletions
diff --git a/libgo/go/bytes/bytes.go b/libgo/go/bytes/bytes.go
index 01a5d9ae4ec..644bf75b894 100644
--- a/libgo/go/bytes/bytes.go
+++ b/libgo/go/bytes/bytes.go
@@ -265,8 +265,8 @@ func Fields(s []byte) [][]byte {
// FieldsFunc interprets s as a sequence of UTF-8-encoded Unicode code points.
// It splits the slice s at each run of code points c satisfying f(c) and
-// returns a slice of subslices of s. If no code points in s satisfy f(c), an
-// empty slice is returned.
+// returns a slice of subslices of s. If all code points in s satisfy f(c), or
+// len(s) == 0, an empty slice is returned.
func FieldsFunc(s []byte, f func(rune) bool) [][]byte {
n := 0
inField := false
diff --git a/libgo/go/bytes/bytes_test.go b/libgo/go/bytes/bytes_test.go
index ab5da4fbf08..808655a4a48 100644
--- a/libgo/go/bytes/bytes_test.go
+++ b/libgo/go/bytes/bytes_test.go
@@ -1073,6 +1073,8 @@ var TitleTests = []TitleTest{
{"123a456", "123a456"},
{"double-blind", "Double-Blind"},
{"ÿøû", "Ÿøû"},
+ {"with_underscore", "With_underscore"},
+ {"unicode \xe2\x80\xa8 line separator", "Unicode \xe2\x80\xa8 Line Separator"},
}
func TestTitle(t *testing.T) {
@@ -1160,6 +1162,24 @@ func TestBufferTruncateOutOfRange(t *testing.T) {
b.Truncate(20)
}
+var containsTests = []struct {
+ b, subslice []byte
+ want bool
+}{
+ {[]byte("hello"), []byte("hel"), true},
+ {[]byte("日本語"), []byte("日本"), true},
+ {[]byte("hello"), []byte("Hello, world"), false},
+ {[]byte("東京"), []byte("京東"), false},
+}
+
+func TestContains(t *testing.T) {
+ for _, tt := range containsTests {
+ if got := Contains(tt.b, tt.subslice); got != tt.want {
+ t.Errorf("Contains(%q, %q) = %v, want %v", tt.b, tt.subslice, got, tt.want)
+ }
+ }
+}
+
var makeFieldsInput = func() []byte {
x := make([]byte, 1<<20)
// Input is ~10% space, ~10% 2-byte UTF-8, rest ASCII non-space.
diff --git a/libgo/go/bytes/compare_test.go b/libgo/go/bytes/compare_test.go
index 0a36f5ad39b..63522374ee0 100644
--- a/libgo/go/bytes/compare_test.go
+++ b/libgo/go/bytes/compare_test.go
@@ -1,3 +1,7 @@
+// Copyright 2013 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
package bytes_test
import (