From 54d3d47daf9190275bbdaf8703b84969a4593451 Mon Sep 17 00:00:00 2001 From: Corey Hulen Date: Fri, 24 Mar 2017 23:31:34 -0700 Subject: PLT-6076 Adding viper libs for config file changes (#5871) * Adding viper libs for config file changes * Removing the old fsnotify lib * updating some missing libs --- .../x/text/secure/bidirule/bench_test.go | 54 ++ .../golang.org/x/text/secure/bidirule/bidirule.go | 342 +++++++++ .../x/text/secure/bidirule/bidirule_test.go | 825 +++++++++++++++++++++ 3 files changed, 1221 insertions(+) create mode 100644 vendor/golang.org/x/text/secure/bidirule/bench_test.go create mode 100644 vendor/golang.org/x/text/secure/bidirule/bidirule.go create mode 100644 vendor/golang.org/x/text/secure/bidirule/bidirule_test.go (limited to 'vendor/golang.org/x/text/secure/bidirule') diff --git a/vendor/golang.org/x/text/secure/bidirule/bench_test.go b/vendor/golang.org/x/text/secure/bidirule/bench_test.go new file mode 100644 index 000000000..2db922bfd --- /dev/null +++ b/vendor/golang.org/x/text/secure/bidirule/bench_test.go @@ -0,0 +1,54 @@ +// Copyright 2016 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 bidirule + +import ( + "testing" + + "golang.org/x/text/internal/testtext" +) + +var benchData = []struct{ name, data string }{ + {"ascii", "Scheveningen"}, + {"arabic", "دبي"}, + {"hangul", "다음과"}, +} + +func doBench(b *testing.B, fn func(b *testing.B, data string)) { + for _, d := range benchData { + testtext.Bench(b, d.name, func(b *testing.B) { fn(b, d.data) }) + } +} + +func BenchmarkSpan(b *testing.B) { + r := New() + doBench(b, func(b *testing.B, str string) { + b.SetBytes(int64(len(str))) + data := []byte(str) + for i := 0; i < b.N; i++ { + r.Reset() + r.Span(data, true) + } + }) +} + +func BenchmarkDirectionASCII(b *testing.B) { + doBench(b, func(b *testing.B, str string) { + b.SetBytes(int64(len(str))) + data := []byte(str) + for i := 0; i < b.N; i++ { + Direction(data) + } + }) +} + +func BenchmarkDirectionStringASCII(b *testing.B) { + doBench(b, func(b *testing.B, str string) { + b.SetBytes(int64(len(str))) + for i := 0; i < b.N; i++ { + DirectionString(str) + } + }) +} diff --git a/vendor/golang.org/x/text/secure/bidirule/bidirule.go b/vendor/golang.org/x/text/secure/bidirule/bidirule.go new file mode 100644 index 000000000..a7161bdd9 --- /dev/null +++ b/vendor/golang.org/x/text/secure/bidirule/bidirule.go @@ -0,0 +1,342 @@ +// Copyright 2016 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 bidirule implements the Bidi Rule defined by RFC 5893. +// +// This package is under development. The API may change without notice and +// without preserving backward compatibility. +package bidirule + +import ( + "errors" + "unicode/utf8" + + "golang.org/x/text/transform" + "golang.org/x/text/unicode/bidi" +) + +// This file contains an implementation of RFC 5893: Right-to-Left Scripts for +// Internationalized Domain Names for Applications (IDNA) +// +// A label is an individual component of a domain name. Labels are usually +// shown separated by dots; for example, the domain name "www.example.com" is +// composed of three labels: "www", "example", and "com". +// +// An RTL label is a label that contains at least one character of class R, AL, +// or AN. An LTR label is any label that is not an RTL label. +// +// A "Bidi domain name" is a domain name that contains at least one RTL label. +// +// The following guarantees can be made based on the above: +// +// o In a domain name consisting of only labels that satisfy the rule, +// the requirements of Section 3 are satisfied. Note that even LTR +// labels and pure ASCII labels have to be tested. +// +// o In a domain name consisting of only LDH labels (as defined in the +// Definitions document [RFC5890]) and labels that satisfy the rule, +// the requirements of Section 3 are satisfied as long as a label +// that starts with an ASCII digit does not come after a +// right-to-left label. +// +// No guarantee is given for other combinations. + +// ErrInvalid indicates a label is invalid according to the Bidi Rule. +var ErrInvalid = errors.New("bidirule: failed Bidi Rule") + +type ruleState uint8 + +const ( + ruleInitial ruleState = iota + ruleLTR + ruleLTRFinal + ruleRTL + ruleRTLFinal + ruleInvalid +) + +type ruleTransition struct { + next ruleState + mask uint16 +} + +var transitions = [...][2]ruleTransition{ + // [2.1] The first character must be a character with Bidi property L, R, or + // AL. If it has the R or AL property, it is an RTL label; if it has the L + // property, it is an LTR label. + ruleInitial: { + {ruleLTRFinal, 1 << bidi.L}, + {ruleRTLFinal, 1< 0 { + return + } + + r := New() + src := []byte(tc.in) + + n, err := r.Span(src[:tc.pSrc], tc.pSrc == len(tc.in)) + if err != tc.err0 { + t.Errorf("err0 was %v; want %v", err, tc.err0) + } + if n != tc.nSrc { + t.Fatalf("nSrc was %d; want %d", n, tc.nSrc) + } + + n, err = r.Span(src[n:], true) + if err != tc.err { + t.Errorf("error was %v; want %v", err, tc.err) + } + if got := n + tc.nSrc; got != tc.n { + t.Errorf("n was %d; want %d", got, tc.n) + } + }) +} + +func TestTransform(t *testing.T) { + doTests(t, func(t *testing.T, tc ruleTest) { + r := New() + + src := []byte(tc.in) + dst := make([]byte, len(tc.in)) + if tc.szDst > 0 { + dst = make([]byte, tc.szDst) + } + + // First transform operates on a zero-length string for most tests. + nDst, nSrc, err := r.Transform(dst, src[:tc.pSrc], tc.pSrc == len(tc.in)) + if err != tc.err0 { + t.Errorf("err0 was %v; want %v", err, tc.err0) + } + if nDst != nSrc { + t.Fatalf("nDst (%d) and nSrc (%d) should match", nDst, nSrc) + } + if nSrc != tc.nSrc { + t.Fatalf("nSrc was %d; want %d", nSrc, tc.nSrc) + } + + dst1 := make([]byte, len(tc.in)) + copy(dst1, dst[:nDst]) + + nDst, nSrc, err = r.Transform(dst1[nDst:], src[nSrc:], true) + if err != tc.err { + t.Errorf("error was %v; want %v", err, tc.err) + } + if nDst != nSrc { + t.Fatalf("nDst (%d) and nSrc (%d) should match", nDst, nSrc) + } + n := nSrc + tc.nSrc + if n != tc.n { + t.Fatalf("n was %d; want %d", n, tc.n) + } + if got, want := string(dst1[:n]), tc.in[:tc.n]; got != want { + t.Errorf("got %+q; want %+q", got, want) + } + }) +} -- cgit v1.2.3-1-g7c22