aboutsummaryrefslogtreecommitdiff
path: root/libgo/go/unicode
diff options
context:
space:
mode:
authorIan Lance Taylor <iant@golang.org>2018-09-24 21:46:21 +0000
committerIan Lance Taylor <ian@gcc.gnu.org>2018-09-24 21:46:21 +0000
commitdd931d9b48647e898dc80927c532ae93cc09e192 (patch)
tree71be2295cd79b8a182f6130611658db8628772d5 /libgo/go/unicode
parent779d8a5ad09b01428726ea5a0e6c87bd9ac3c0e4 (diff)
downloadgcc-dd931d9b48647e898dc80927c532ae93cc09e192.zip
gcc-dd931d9b48647e898dc80927c532ae93cc09e192.tar.gz
gcc-dd931d9b48647e898dc80927c532ae93cc09e192.tar.bz2
libgo: update to Go 1.11
Reviewed-on: https://go-review.googlesource.com/136435 gotools/: * Makefile.am (mostlyclean-local): Run chmod on check-go-dir to make sure it is writable. (check-go-tools): Likewise. (check-vet): Copy internal/objabi to check-vet-dir. * Makefile.in: Rebuild. From-SVN: r264546
Diffstat (limited to 'libgo/go/unicode')
-rw-r--r--libgo/go/unicode/letter.go26
-rw-r--r--libgo/go/unicode/letter_test.go12
-rw-r--r--libgo/go/unicode/utf16/utf16_test.go2
-rw-r--r--libgo/go/unicode/utf8/utf8_test.go21
4 files changed, 43 insertions, 18 deletions
diff --git a/libgo/go/unicode/letter.go b/libgo/go/unicode/letter.go
index 4d9fc67..8be9a7b 100644
--- a/libgo/go/unicode/letter.go
+++ b/libgo/go/unicode/letter.go
@@ -206,9 +206,10 @@ func IsTitle(r rune) bool {
}
// to maps the rune using the specified case mapping.
-func to(_case int, r rune, caseRange []CaseRange) rune {
+// It additionally reports whether caseRange contained a mapping for r.
+func to(_case int, r rune, caseRange []CaseRange) (mappedRune rune, foundMapping bool) {
if _case < 0 || MaxCase <= _case {
- return ReplacementChar // as reasonable an error as any
+ return ReplacementChar, false // as reasonable an error as any
}
// binary search over ranges
lo := 0
@@ -229,9 +230,9 @@ func to(_case int, r rune, caseRange []CaseRange) rune {
// bit in the sequence offset.
// The constants UpperCase and TitleCase are even while LowerCase
// is odd so we take the low bit from _case.
- return rune(cr.Lo) + ((r-rune(cr.Lo))&^1 | rune(_case&1))
+ return rune(cr.Lo) + ((r-rune(cr.Lo))&^1 | rune(_case&1)), true
}
- return r + delta
+ return r + delta, true
}
if r < rune(cr.Lo) {
hi = m
@@ -239,12 +240,13 @@ func to(_case int, r rune, caseRange []CaseRange) rune {
lo = m + 1
}
}
- return r
+ return r, false
}
// To maps the rune to the specified case: UpperCase, LowerCase, or TitleCase.
func To(_case int, r rune) rune {
- return to(_case, r, CaseRanges)
+ r, _ = to(_case, r, CaseRanges)
+ return r
}
// ToUpper maps the rune to upper case.
@@ -282,8 +284,8 @@ func ToTitle(r rune) rune {
// ToUpper maps the rune to upper case giving priority to the special mapping.
func (special SpecialCase) ToUpper(r rune) rune {
- r1 := to(UpperCase, r, []CaseRange(special))
- if r1 == r {
+ r1, hadMapping := to(UpperCase, r, []CaseRange(special))
+ if r1 == r && !hadMapping {
r1 = ToUpper(r)
}
return r1
@@ -291,8 +293,8 @@ func (special SpecialCase) ToUpper(r rune) rune {
// ToTitle maps the rune to title case giving priority to the special mapping.
func (special SpecialCase) ToTitle(r rune) rune {
- r1 := to(TitleCase, r, []CaseRange(special))
- if r1 == r {
+ r1, hadMapping := to(TitleCase, r, []CaseRange(special))
+ if r1 == r && !hadMapping {
r1 = ToTitle(r)
}
return r1
@@ -300,8 +302,8 @@ func (special SpecialCase) ToTitle(r rune) rune {
// ToLower maps the rune to lower case giving priority to the special mapping.
func (special SpecialCase) ToLower(r rune) rune {
- r1 := to(LowerCase, r, []CaseRange(special))
- if r1 == r {
+ r1, hadMapping := to(LowerCase, r, []CaseRange(special))
+ if r1 == r && !hadMapping {
r1 = ToLower(r)
}
return r1
diff --git a/libgo/go/unicode/letter_test.go b/libgo/go/unicode/letter_test.go
index 3fe72ff..19ee535 100644
--- a/libgo/go/unicode/letter_test.go
+++ b/libgo/go/unicode/letter_test.go
@@ -9,6 +9,7 @@ import (
"fmt"
"runtime"
"sort"
+ "strings"
"testing"
. "unicode"
)
@@ -551,3 +552,14 @@ func TestLatinOffset(t *testing.T) {
}
}
}
+
+func TestSpecialCaseNoMapping(t *testing.T) {
+ // Issue 25636
+ // no change for rune 'A', zero delta, under upper/lower/title case change.
+ var noChangeForCapitalA = CaseRange{'A', 'A', [MaxCase]rune{0, 0, 0}}
+ got := strings.ToLowerSpecial(SpecialCase([]CaseRange{noChangeForCapitalA}), "ABC")
+ want := "Abc"
+ if got != want {
+ t.Errorf("got %q; want %q", got, want)
+ }
+}
diff --git a/libgo/go/unicode/utf16/utf16_test.go b/libgo/go/unicode/utf16/utf16_test.go
index d258f0b..4ecaabe 100644
--- a/libgo/go/unicode/utf16/utf16_test.go
+++ b/libgo/go/unicode/utf16/utf16_test.go
@@ -124,7 +124,7 @@ var surrogateTests = []struct {
r rune
want bool
}{
- // from http://en.wikipedia.org/wiki/UTF-16
+ // from https://en.wikipedia.org/wiki/UTF-16
{'\u007A', false}, // LATIN SMALL LETTER Z
{'\u6C34', false}, // CJK UNIFIED IDEOGRAPH-6C34 (water)
{'\uFEFF', false}, // Byte Order Mark
diff --git a/libgo/go/unicode/utf8/utf8_test.go b/libgo/go/unicode/utf8/utf8_test.go
index dc9c425..359461b 100644
--- a/libgo/go/unicode/utf8/utf8_test.go
+++ b/libgo/go/unicode/utf8/utf8_test.go
@@ -212,14 +212,25 @@ func TestSequencing(t *testing.T) {
}
}
-// Check that a range loop and a []int conversion visit the same runes.
+func runtimeRuneCount(s string) int {
+ return len([]rune(s)) // Replaced by gc with call to runtime.countrunes(s).
+}
+
+// Check that a range loop, len([]rune(string)) optimization and
+// []rune conversions visit the same runes.
// Not really a test of this package, but the assumption is used here and
-// it's good to verify
-func TestIntConversion(t *testing.T) {
+// it's good to verify.
+func TestRuntimeConversion(t *testing.T) {
for _, ts := range testStrings {
+ count := RuneCountInString(ts)
+ if n := runtimeRuneCount(ts); n != count {
+ t.Errorf("%q: len([]rune()) counted %d runes; got %d from RuneCountInString", ts, n, count)
+ break
+ }
+
runes := []rune(ts)
- if RuneCountInString(ts) != len(runes) {
- t.Errorf("%q: expected %d runes; got %d", ts, len(runes), RuneCountInString(ts))
+ if n := len(runes); n != count {
+ t.Errorf("%q: []rune() has length %d; got %d from RuneCountInString", ts, n, count)
break
}
i := 0