• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang collate.New函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中golang.org/x/text/collate.New函数的典型用法代码示例。如果您正苦于以下问题:Golang New函数的具体用法?Golang New怎么用?Golang New使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了New函数的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。

示例1: sortAC

func sortAC(r io.Reader) []byte {
	bs := bufio.NewScanner(r)
	var header []string
	var lines []string
	for bs.Scan() {
		t := bs.Text()
		lines = append(lines, t)
		if t == "# Please keep the list sorted." {
			header = lines
			lines = nil
			continue
		}
	}
	if err := bs.Err(); err != nil {
		log.Fatal(err)
	}

	var out bytes.Buffer
	c := collate.New(language.Und, collate.Loose)
	c.SortStrings(lines)
	for _, l := range header {
		fmt.Fprintln(&out, l)
	}
	for _, l := range lines {
		fmt.Fprintln(&out, l)
	}
	return out.Bytes()
}
开发者ID:2thetop,项目名称:go,代码行数:28,代码来源:sortac.go


示例2: BenchmarkNumericWeighter

func BenchmarkNumericWeighter(b *testing.B) {
	c := collate.New(language.English, collate.Numeric)
	input := bytes.Repeat([]byte("Testing, testing 123..."), 100)
	b.SetBytes(int64(2 * len(input)))
	for i := 0; i < b.N; i++ {
		c.Compare(input, input)
	}
}
开发者ID:davidsoloman,项目名称:beats,代码行数:8,代码来源:collate_test.go


示例3: getCacheEntry

func (env *CollationEnvironment) getCacheEntry(locale string) collationEnvironmentCacheEntry {
	entry, ok := env.cache[locale]
	if !ok {
		if env.cache == nil {
			env.cache = make(map[string]collationEnvironmentCacheEntry)
		}
		entry = collationEnvironmentCacheEntry{locale, collate.New(language.MustParse(locale))}
		env.cache[locale] = entry
	}
	return entry
}
开发者ID:nvanbenschoten,项目名称:cockroach,代码行数:11,代码来源:datum.go


示例4: TestNumericCompare

func TestNumericCompare(t *testing.T) {
	c := collate.New(language.English, collate.Loose, collate.Numeric)

	// Iterate over all digits.
	for _, r16 := range unicode.Nd.R16 {
		testDigitCompare(t, c, rune(r16.Lo), rune(r16.Hi))
	}
	for _, r32 := range unicode.Nd.R32 {
		testDigitCompare(t, c, rune(r32.Lo), rune(r32.Hi))
	}
}
开发者ID:davidsoloman,项目名称:beats,代码行数:11,代码来源:collate_test.go


示例5: ExampleCollator_Strings

func ExampleCollator_Strings() {
	c := collate.New(language.Und)
	strings := []string{
		"ad",
		"ab",
		"äb",
		"ac",
	}
	c.SortStrings(strings)
	fmt.Println(strings)
	// Output: [ab äb ac ad]
}
开发者ID:davidsoloman,项目名称:beats,代码行数:12,代码来源:sort_test.go


示例6: TestNonDigits

func TestNonDigits(t *testing.T) {
	c := collate.New(language.English, collate.Loose, collate.Numeric)

	// Verify that all non-digit numbers sort outside of the number range.
	for r, hi := rune(unicode.N.R16[0].Lo), rune(unicode.N.R32[0].Hi); r <= hi; r++ {
		if unicode.In(r, unicode.Nd) || !unicode.In(r, assigned) {
			continue
		}
		if a := string(r); c.CompareString(a, "0") != -1 && c.CompareString(a, "999999") != 1 {
			t.Errorf("%+q non-digit number is collated as digit", a)
		}
	}
}
开发者ID:davidsoloman,项目名称:beats,代码行数:13,代码来源:collate_test.go


示例7: getCollator

// getCollator returns a collate package Collator pointer. This can result in a
// panic, so this function must recover from that if it happens.
func getCollator(locale string) *collate.Collator {

	defer func() {
		recover()
	}()

	tag := language.Make(locale)

	if tag == language.Und {
		return nil
	}
	return collate.New(tag)
}
开发者ID:admpub,项目名称:i18n,代码行数:15,代码来源:sort.go


示例8: TestSort

func TestSort(t *testing.T) {
	c := collate.New(language.English)
	strings := []string{
		"bcd",
		"abc",
		"ddd",
	}
	c.Sort(sorter(strings))
	res := fmt.Sprint(strings)
	want := "[abc bcd ddd]"
	if res != want {
		t.Errorf("found %s; want %s", res, want)
	}
}
开发者ID:davidsoloman,项目名称:beats,代码行数:14,代码来源:sort_test.go


示例9: newPooledCollator

func newPooledCollator() interface{} {
	// Ref: http://www.unicode.org/reports/tr10/#Introduction.
	// Unicode seems to define a universal (or default) order.
	// But various locales have conflicting order,
	// which they have the right to override.
	// Unfortunately, the Go library requires you to specify a locale.
	// So, I chose English assuming that it won't override
	// the Unicode universal order. But I couldn't find an easy
	// way to verify this.
	// Also, the locale differences are not an issue for level 1,
	// because the conservative comparison makes them all equal.
	return pooledCollator{
		col: collate.New(language.English, collate.Loose),
		buf: new(collate.Buffer),
	}
}
开发者ID:jmptrader,项目名称:vitess,代码行数:16,代码来源:unicodeloosemd5.go


示例10: testCollator

func testCollator(c *collate.Collator) {
	c0 := collate.New(language.Und)

	// iterator over all characters for all locales and check
	// whether Key is equal.
	buf := collate.Buffer{}

	// Add all common and not too uncommon runes to the test set.
	for i := rune(0); i < 0x30000; i++ {
		testInput.add(string(i))
	}
	for i := rune(0xE0000); i < 0xF0000; i++ {
		testInput.add(string(i))
	}
	for _, str := range testInput.values() {
		k0 := c0.KeyFromString(&buf, str)
		k := c.KeyFromString(&buf, str)
		if !bytes.Equal(k0, k) {
			failOnError(fmt.Errorf("test:%U: keys differ (%x vs %x)", []rune(str), k0, k))
		}
		buf.Reset()
	}
	fmt.Println("PASS")
}
开发者ID:TriangleGo,项目名称:golang.org,代码行数:24,代码来源:maketables.go


示例11: newGoCollator

func newGoCollator(loc string) (Collator, error) {
	c := &goCollator{c: collate.New(language.Make(loc))}
	return c, nil
}
开发者ID:ChongFeng,项目名称:beats,代码行数:4,代码来源:col.go


示例12: Less

var (
	lastViewedTimeCmpLess = _lessCmper(AttrLastViewedByMeTime)
	md5CmpLess            = _lessCmper(AttrMd5Checksum)
	mimeTypeCmpLess       = _lessCmper(AttrMimeType)
	modTimeCmpLess        = _lessCmper(AttrModTime)
	nameCmpLess           = _lessCmper(AttrName)
	sizeCmpLess           = _lessCmper(AttrSize)
	versionCmpLess        = _lessCmper(AttrVersion)
	typeCmpLess           = _lessCmper(AttrIsDir)
)

var (
	// TODO get collation order from system's locale
	// language.Und seems to work well for common western locales

	collator *collate.Collator = collate.New(language.Und)
)

func (fl modTimeFlist) Less(i, j int) bool {
	return modTimeCmpLess(fl[i], fl[j])
}

func (fl modTimeFlist) Len() int {
	return len(fl)
}

func (fl modTimeFlist) Swap(i, j int) {
	fl[i], fl[j] = fl[j], fl[i]
}

func (fl typeFlist) Less(i, j int) bool {
开发者ID:enzochiau,项目名称:drive,代码行数:31,代码来源:sort.go


示例13: init

func init() {
	simplifyNameRegex = regexp.MustCompile("[^a-zA-Z0-9]")
	collation = collate.New(language.English, collate.Loose, collate.IgnoreCase, collate.Numeric)
}
开发者ID:1Lykaon,项目名称:charactersheets-translator,代码行数:4,代码来源:stack.go



注:本文中的golang.org/x/text/collate.New函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang collate.Collator类代码示例发布时间:2022-05-28
下一篇:
Golang mgr.Service类代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap