mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
rearrange some constants. unicode package now defines MaxRune and ReplacementChar.
utf8 package imports unicode to get those definitions. regenerate dependencies. R=rsc DELTA=41 (19 added, 3 deleted, 19 changed) OCL=34123 CL=34129
This commit is contained in:
parent
4962e7ee9b
commit
149e3d332c
8 changed files with 37 additions and 21 deletions
|
|
@ -48,14 +48,14 @@ regexp.install: bytes.install container/vector.install io.install os.install run
|
||||||
rpc.install: bufio.install fmt.install gob.install http.install io.install log.install net.install os.install reflect.install sort.install strconv.install strings.install sync.install template.install unicode.install utf8.install
|
rpc.install: bufio.install fmt.install gob.install http.install io.install log.install net.install os.install reflect.install sort.install strconv.install strings.install sync.install template.install unicode.install utf8.install
|
||||||
runtime.install:
|
runtime.install:
|
||||||
sort.install:
|
sort.install:
|
||||||
strconv.install: bytes.install math.install os.install utf8.install
|
strconv.install: bytes.install math.install os.install unicode.install utf8.install
|
||||||
strings.install: utf8.install
|
strings.install: utf8.install
|
||||||
sync.install:
|
sync.install:
|
||||||
syscall.install: sync.install
|
syscall.install: sync.install
|
||||||
tabwriter.install: bytes.install container/vector.install io.install os.install utf8.install
|
tabwriter.install: bytes.install container/vector.install io.install os.install utf8.install
|
||||||
template.install: bytes.install container/vector.install fmt.install io.install os.install reflect.install runtime.install strings.install
|
template.install: bytes.install container/vector.install fmt.install io.install os.install reflect.install runtime.install strings.install
|
||||||
testing.install: flag.install fmt.install os.install runtime.install utf8.install
|
testing.install: flag.install fmt.install os.install runtime.install utf8.install
|
||||||
testing/iotest.install: io.install log.install os.install
|
testing/iotest.install: bytes.install io.install log.install os.install
|
||||||
time.install: io.install once.install os.install syscall.install
|
time.install: io.install once.install os.install syscall.install
|
||||||
unicode.install:
|
unicode.install:
|
||||||
utf8.install:
|
utf8.install: unicode.install
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@ package strconv
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"os";
|
"os";
|
||||||
|
"unicode";
|
||||||
"utf8";
|
"utf8";
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -175,7 +176,7 @@ func UnquoteChar(s string, quote byte) (value int, multibyte bool, tail string,
|
||||||
value = v;
|
value = v;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if v > utf8.RuneMax {
|
if v > unicode.MaxRune {
|
||||||
err = os.EINVAL;
|
err = os.EINVAL;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,9 +2,10 @@
|
||||||
// Use of this source code is governed by a BSD-style
|
// Use of this source code is governed by a BSD-style
|
||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
package strings
|
package strings_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
. "strings";
|
||||||
"testing";
|
"testing";
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -92,7 +93,7 @@ var explodetests = []ExplodeTest {
|
||||||
}
|
}
|
||||||
func TestExplode(t *testing.T) {
|
func TestExplode(t *testing.T) {
|
||||||
for _, tt := range explodetests {
|
for _, tt := range explodetests {
|
||||||
a := explode(tt.s, tt.n);
|
a := Split(tt.s, "", tt.n);
|
||||||
if !eq(a, tt.a) {
|
if !eq(a, tt.a) {
|
||||||
t.Errorf("explode(%q, %d) = %v; want %v", tt.s, tt.n, a, tt.a);
|
t.Errorf("explode(%q, %d) = %v; want %v", tt.s, tt.n, a, tt.a);
|
||||||
continue;
|
continue;
|
||||||
|
|
|
||||||
|
|
@ -2,9 +2,12 @@
|
||||||
// Use of this source code is governed by a BSD-style
|
// Use of this source code is governed by a BSD-style
|
||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
package unicode
|
package unicode_test
|
||||||
|
|
||||||
import "testing"
|
import (
|
||||||
|
"testing";
|
||||||
|
. "unicode";
|
||||||
|
)
|
||||||
|
|
||||||
var testDigit = []int {
|
var testDigit = []int {
|
||||||
0x0030,
|
0x0030,
|
||||||
|
|
|
||||||
|
|
@ -3,9 +3,14 @@
|
||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
// This package provides data and functions to test some properties of Unicode code points.
|
// This package provides data and functions to test some properties of Unicode code points.
|
||||||
// It is rudimentary but will improve.
|
|
||||||
package unicode
|
package unicode
|
||||||
|
|
||||||
|
const (
|
||||||
|
MaxRune = 0x10FFFF; // Maximum valid Unicode code point.
|
||||||
|
ReplacementChar = 0xFFFD; // Represents invalid code points.
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
// The representation of a range of Unicode code points. The range runs from Lo to Hi
|
// The representation of a range of Unicode code points. The range runs from Lo to Hi
|
||||||
// inclusive and has the specified stride.
|
// inclusive and has the specified stride.
|
||||||
type Range struct {
|
type Range struct {
|
||||||
|
|
@ -42,8 +47,7 @@ type d [MaxCase]int32 // to make the CaseRanges text shorter
|
||||||
// this CaseRange represents a sequence of the form (say)
|
// this CaseRange represents a sequence of the form (say)
|
||||||
// Upper Lower Upper Lower.
|
// Upper Lower Upper Lower.
|
||||||
const (
|
const (
|
||||||
MaxChar = 0x10FFFF; // Maximum valid Unicode character value.
|
UpperLower = MaxRune + 1; // (Cannot be a valid delta.)
|
||||||
UpperLower = MaxChar + 1; // (Cannot be a valid delta.)
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// Is tests whether rune is in the specified table of ranges.
|
// Is tests whether rune is in the specified table of ranges.
|
||||||
|
|
@ -113,10 +117,10 @@ func IsLetter(rune int) bool {
|
||||||
return Is(Letter, rune);
|
return Is(Letter, rune);
|
||||||
}
|
}
|
||||||
|
|
||||||
// To maps the rune to the specified case, UpperCase, LowerCase, or TitleCase
|
// To maps the rune to the specified case: UpperCase, LowerCase, or TitleCase
|
||||||
func To(_case int, rune int) int {
|
func To(_case int, rune int) int {
|
||||||
if _case < 0 || MaxCase <= _case {
|
if _case < 0 || MaxCase <= _case {
|
||||||
return 0xFFFD // as reasonable an error as any
|
return ReplacementChar // as reasonable an error as any
|
||||||
}
|
}
|
||||||
// binary search over ranges
|
// binary search over ranges
|
||||||
lo := 0;
|
lo := 0;
|
||||||
|
|
@ -126,7 +130,7 @@ func To(_case int, rune int) int {
|
||||||
r := CaseRanges[m];
|
r := CaseRanges[m];
|
||||||
if r.Lo <= rune && rune <= r.Hi {
|
if r.Lo <= rune && rune <= r.Hi {
|
||||||
delta := int(r.Delta[_case]);
|
delta := int(r.Delta[_case]);
|
||||||
if delta > MaxChar {
|
if delta > MaxRune {
|
||||||
// In an Upper-Lower sequence, which always starts with
|
// In an Upper-Lower sequence, which always starts with
|
||||||
// an UpperCase letter, the real deltas always look like:
|
// an UpperCase letter, the real deltas always look like:
|
||||||
// {0, 1, 0} UpperCase (Lower is next)
|
// {0, 1, 0} UpperCase (Lower is next)
|
||||||
|
|
|
||||||
|
|
@ -2,9 +2,12 @@
|
||||||
// Use of this source code is governed by a BSD-style
|
// Use of this source code is governed by a BSD-style
|
||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
package unicode
|
package unicode_test
|
||||||
|
|
||||||
import "testing"
|
import (
|
||||||
|
"testing";
|
||||||
|
. "unicode";
|
||||||
|
)
|
||||||
|
|
||||||
var upperTest = []int{
|
var upperTest = []int{
|
||||||
0x41,
|
0x41,
|
||||||
|
|
|
||||||
|
|
@ -2,9 +2,12 @@
|
||||||
// Use of this source code is governed by a BSD-style
|
// Use of this source code is governed by a BSD-style
|
||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
package unicode
|
package unicode_test
|
||||||
|
|
||||||
import "testing"
|
import (
|
||||||
|
"testing";
|
||||||
|
. "unicode";
|
||||||
|
)
|
||||||
|
|
||||||
type T struct {
|
type T struct {
|
||||||
rune int;
|
rune int;
|
||||||
|
|
|
||||||
|
|
@ -6,11 +6,12 @@
|
||||||
// This package calls a Unicode character a rune for brevity.
|
// This package calls a Unicode character a rune for brevity.
|
||||||
package utf8
|
package utf8
|
||||||
|
|
||||||
|
import "unicode" // only needed for a couple of constants
|
||||||
|
|
||||||
// Numbers fundamental to the encoding.
|
// Numbers fundamental to the encoding.
|
||||||
const (
|
const (
|
||||||
RuneError = 0xFFFD; // the "error" Rune or "replacement character".
|
RuneError = unicode.ReplacementChar; // the "error" Rune or "replacement character".
|
||||||
RuneSelf = 0x80; // characters below Runeself are represented as themselves in a single byte.
|
RuneSelf = 0x80; // characters below Runeself are represented as themselves in a single byte.
|
||||||
RuneMax = 0x10FFFF; // maximum Unicode code point.
|
|
||||||
UTFMax = 4; // maximum number of bytes of a UTF-8 encoded Unicode character.
|
UTFMax = 4; // maximum number of bytes of a UTF-8 encoded Unicode character.
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -239,7 +240,7 @@ func EncodeRune(rune int, p []byte) int {
|
||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
if rune > RuneMax {
|
if rune > unicode.MaxRune {
|
||||||
rune = RuneError
|
rune = RuneError
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue