当前位置: 首页>>代码示例>>Golang>>正文


Golang utils.StringSlice类代码示例

本文整理汇总了Golang中github.com/corestoreio/csfw/utils.StringSlice的典型用法代码示例。如果您正苦于以下问题:Golang StringSlice类的具体用法?Golang StringSlice怎么用?Golang StringSlice使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: TestStringSliceReduce

func TestStringSliceReduce(t *testing.T) {
	l := utils.StringSlice{"Maybe", "GoLang", "should"}
	assert.EqualValues(t, []string{"GoLang"}, l.Reduce(func(s string) bool {
		return s == "GoLang"
	}).ToString())
	assert.Len(t, l, 1)
}
开发者ID:bom-d-van,项目名称:csfw,代码行数:7,代码来源:string_slice_test.go

示例2: BenchmarkStringSliceUnique

// BenchmarkUnique	 2000000	       612 ns/op	     160 B/op	       2 allocs/op
func BenchmarkStringSliceUnique(b *testing.B) {
	b.ReportAllocs()
	for i := 0; i < b.N; i++ {
		l := utils.StringSlice{"Maybe", "GoLang", "GoLang", "GoLang", "or", "or", "RostLang", "RostLang"}
		l.Unique()
		benchStringSliceUnique = l
	}
}
开发者ID:bom-d-van,项目名称:csfw,代码行数:9,代码来源:string_slice_test.go

示例3: TestStringSliceAny

func TestStringSliceAny(t *testing.T) {
	l := utils.StringSlice{"c", "a", "z", "b"}
	assert.True(t, l.Any(func(s string) bool {
		return s == "z"
	}))
	assert.False(t, l.Any(func(s string) bool {
		return s == "zx"
	}))
}
开发者ID:bom-d-van,项目名称:csfw,代码行数:9,代码来源:string_slice_test.go

示例4: defaultIsCountryAllowed

func defaultIsCountryAllowed(_ *store.Store, c *IPCountry, allowedCountries utils.StringSlice, r *http.Request) bool {
	if false == allowedCountries.Include(c.Country.Country.IsoCode) {
		if PkgLog.IsInfo() {
			PkgLog.Info("geoip.checkAllow", "IPCountry", c, "allowedCountries", allowedCountries, "request", r)
		}
		return false
	}
	return true
}
开发者ID:levcom,项目名称:csfw,代码行数:9,代码来源:service.go

示例5: Human

// Human readable representation of the permissions
func (bits Perm) Human() utils.StringSlice {
	var ret utils.StringSlice
	var i uint
	for i = 0; i < 64; i++ {
		bit := ((bits & (1 << i)) != 0)
		if bit {
			ret.Append(Scope(i).String())
		}
	}
	return ret
}
开发者ID:hafeez3000,项目名称:csfw,代码行数:12,代码来源:perm.go

示例6: Codes

// Codes returns a StringSlice with all store codes
func (s StoreSlice) Codes() utils.StringSlice {
	if len(s) == 0 {
		return nil
	}
	var c utils.StringSlice
	for _, st := range s {
		if st != nil {
			c.Append(st.Data().Code.String)
		}
	}
	return c
}
开发者ID:bom-d-van,项目名称:csfw,代码行数:13,代码来源:store.go

示例7: TestStringSliceFilter

func TestStringSliceFilter(t *testing.T) {
	l := utils.StringSlice{"All", "Go", "Code", "is"}
	rl := l.Filter(func(s string) bool {
		return s == "Go"
	}).ToString()
	assert.EqualValues(t, []string{"Go"}, rl)
	assert.Len(t, l, 4)

	l.Append("incredible", "easy", ",", "sometimes")
	assert.Len(t, l, 8)
	assert.EqualValues(t, []string{"Go"}, rl)
}
开发者ID:bom-d-van,项目名称:csfw,代码行数:12,代码来源:string_slice_test.go

示例8: Codes

// Codes returns a StringSlice with all website codes
func (ws WebsiteSlice) Codes() utils.StringSlice {
	if len(ws) == 0 {
		return nil
	}
	var c utils.StringSlice
	for _, w := range ws {
		if w != nil {
			c.Append(w.Data.Code.String)
		}
	}
	return c
}
开发者ID:hafeez3000,项目名称:csfw,代码行数:13,代码来源:website.go

示例9: BenchmarkStringSliceReduceContains

// BenchmarkReduceContains	 1000000	      1841 ns/op	      96 B/op	       2 allocs/op
func BenchmarkStringSliceReduceContains(b *testing.B) {

	b.ReportAllocs()
	for i := 0; i < b.N; i++ {
		l := utils.StringSlice{
			"IFNULL(`scope_table`.`is_visible`, `additional_table`.`is_visible`) AS `is_visible`",
			"IFNULL(`scope_table`.`is_required`, `main_table`.`is_required`) AS `is_required`",
			"IFNULL(`scope_table`.`default_value`, `main_table`.`default_value`) AS `default_value`",
			"IFNULL(`scope_table`.`multiline_count`, `additional_table`.`multiline_count`) AS `multiline_count`",
		}
		l.ReduceContains(benchStringSliceReduceContainsData...)
		benchStringSliceReduceContains = l
	}
}
开发者ID:bom-d-van,项目名称:csfw,代码行数:15,代码来源:string_slice_test.go

示例10: getImportPaths

func getImportPaths() []string {
	var paths utils.StringSlice

	var getPath = func(s string) string {
		ps, err := codegen.ExtractImportPath(s)
		codegen.LogFatal(err)
		return ps
	}

	for _, et := range codegen.ConfigEntityType {
		paths.Append(
			getPath(et.EntityModel),
			getPath(et.AttributeModel),
			getPath(et.EntityTable),
			getPath(et.IncrementModel),
			getPath(et.AdditionalAttributeTable),
			getPath(et.EntityAttributeCollection),
		)
	}
	return paths.Unique().ToString()
}
开发者ID:hafeez3000,项目名称:csfw,代码行数:21,代码来源:entity_type.go

示例11: TestStringSliceAll

func TestStringSliceAll(t *testing.T) {
	l := utils.StringSlice{"c", "a", "z", "b"}
	assert.True(t, l.All(func(s string) bool {
		return len(s) == 1
	}))
	l.Append("xx")
	assert.False(t, l.All(func(s string) bool {
		return len(s) == 1
	}))
}
开发者ID:bom-d-van,项目名称:csfw,代码行数:10,代码来源:string_slice_test.go

示例12: TestStringSliceSplitStringer8

func TestStringSliceSplitStringer8(t *testing.T) {
	tests := []struct {
		haveName  string
		haveIndex []uint8
		want      utils.StringSlice
	}{
		{
			"ScopeAbsentScopeDefaultScopeWebsiteScopeGroupScopeStore",
			[]uint8{0, 11, 23, 35, 45, 55},
			utils.StringSlice{"ScopeAbsent", "ScopeDefault", "ScopeWebsite", "ScopeGroup", "ScopeStore"},
		},
		{
			"TypeCustomTypeHiddenTypeObscureTypeMultiselectTypeSelectTypeTextTypeTime",
			[]uint8{10, 20, 31, 46, 56, 64, 72},
			utils.StringSlice{"TypeHidden", "TypeObscure", "TypeMultiselect", "TypeSelect", "TypeText", "TypeTime"},
		},
	}
	for _, test := range tests {
		var a utils.StringSlice
		have := a.SplitStringer8(test.haveName, test.haveIndex...)
		assert.Exactly(t, test.want, have)
	}
}
开发者ID:bom-d-van,项目名称:csfw,代码行数:23,代码来源:string_slice_test.go

示例13: TestStringSliceSplit

func TestStringSliceSplit(t *testing.T) {
	l := utils.StringSlice{"a", "b"}
	assert.Equal(t, []string{"a", "b", "c", "d"}, l.Split("c,d", ",").ToString())
	assert.Equal(t, []string{"a", "b", "c", "d", "e", "f", ""}, l.Split("e,f,", ",").ToString())
}
开发者ID:bom-d-van,项目名称:csfw,代码行数:5,代码来源:string_slice_test.go

示例14: TestStringSlice

func TestStringSlice(t *testing.T) {
	l := utils.StringSlice{"Maybe", "GoLang", "should", "have", "generics", "but", "who", "needs", "them", "?", ";-)"}
	assert.Len(t, l, l.Len())
	assert.Equal(t, 1, l.Index("GoLang"))
	assert.Equal(t, -1, l.Index("Golang"))
	assert.True(t, l.Include("GoLang"))
	assert.False(t, l.Include("Golang"))

	l2 := utils.StringSlice{"Maybe", "GoLang"}
	l2.Map(func(s string) string {
		return s + "2"
	})
	assert.Equal(t, []string{"Maybe2", "GoLang2"}, l2.ToString())
	l2.Append("will", "be")
	assert.Equal(t, []string{"Maybe2", "GoLang2", "will", "be"}, l2.ToString())

}
开发者ID:bom-d-van,项目名称:csfw,代码行数:17,代码来源:string_slice_test.go

示例15: TestStringSliceDelete

func TestStringSliceDelete(t *testing.T) {
	l := utils.StringSlice{"Maybe", "GoLang", "should"}
	assert.NoError(t, l.Delete(1))
	assert.Equal(t, []string{"Maybe", "should"}, l.ToString())
	assert.NoError(t, l.Delete(1))
	assert.Equal(t, []string{"Maybe"}, l.ToString())
	assert.EqualError(t, l.Delete(1), utils.ErrOutOfRange.Error())
}
开发者ID:bom-d-van,项目名称:csfw,代码行数:8,代码来源:string_slice_test.go


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