當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。