示例#1
0
文件: lookup.go 项目: ChongFeng/beats
// index returns the index of the tag for the given base, script and region or
// its parent if the tag is not available. If the match is for a parent entry,
// the excess script and region are returned.
func (ts *tagSet) index(base language.Base, scr language.Script, reg language.Region) (int, language.Script, language.Region) {
	lang := base.String()
	index := -1
	if (scr != language.Script{} || reg != language.Region{}) {
		if scr == zzzz {
			scr = language.Script{}
		}
		if reg == zz {
			reg = language.Region{}
		}

		i := sort.SearchStrings(ts.long, lang)
		// All entries have either a script or a region and not both.
		scrStr, regStr := scr.String(), reg.String()
		for ; i < len(ts.long) && strings.HasPrefix(ts.long[i], lang); i++ {
			if s := ts.long[i][len(lang)+1:]; s == scrStr {
				scr = language.Script{}
				index = i + ts.single.len()
				break
			} else if s == regStr {
				reg = language.Region{}
				index = i + ts.single.len()
				break
			}
		}
	}
	if index == -1 {
		index = ts.single.index(lang)
	}
	return index, scr, reg
}
示例#2
0
文件: locale.go 项目: hafeez3000/csfw
// GetLocale generates a locale from a base and a region and may use an optional script.
// lang
// lang_script
// lang_script_region
// lang_region (aliases to lang_script_region)
func GetLocale(b language.Base, r language.Region, s ...language.Script) string {
	ret := b.String()
	if len(s) == 1 {
		ret += LocaleSeparator + s[0].String()
	}
	return ret + LocaleSeparator + r.String()
}
示例#3
0
文件: common.go 项目: Zhoutall/beats
// regionToCode returns a 16-bit region code. Only two-letter codes are
// supported. (Three-letter codes are not needed.)
func regionToCode(r language.Region) uint16 {
	if s := r.String(); len(s) == 2 {
		return uint16(s[0])<<8 | uint16(s[1])
	}
	return 0
}