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


Golang strings.LastIndexByte函数代码示例

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


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

示例1: fixupParents

// Ensure that there are either loggers or placeholders all the way
// from the specified logger to the root of the logger hierarchy.
func (m *manager) fixupParents(l *Logger) {

	var parent *Logger
	name := l.name
	i := strings.LastIndexByte(name, '/')

	for i > 0 && parent == nil {
		name = name[:i]
		if node, ok := m.registry[name]; ok {
			if p, ok := node.(*placeholder); ok {
				// The logger will be child of this placeholder
				// if anybody asks later.
				p.append(l)
			} else { // it' s a *Logger
				if n, ok := node.(*Logger); ok {
					parent = n
				} else {
					panic("Bad logger in registry")
				}
			}
		} else {
			m.registry[name] = newPlaceholder(l)
		}
		i = strings.LastIndexByte(name, '/')
	}
	if parent == nil {
		parent = m.root
	}
	l.h.SwapParent(parent)
}
开发者ID:marcelfarres,项目名称:gonelog,代码行数:32,代码来源:manager.go

示例2: LastIndexByte

// LastIndexByte returns the index of the last instance of c in s
// or -f if c is not present in s
func LastIndexByte(s string, c byte) int {
	fmt.Println(strings.LastIndexByte("gogopher", 'o')) // 3
	fmt.Println(strings.LastIndexByte("gogopher", 111)) // 3
	fmt.Println(strings.LastIndexByte("gogopher", 112)) // 4
	fmt.Println(strings.LastIndexByte("gogopher", 113)) // -1
	return strings.LastIndexByte(s, c)
}
开发者ID:upccup,项目名称:cuplearn,代码行数:9,代码来源:stringsTest.go

示例3: fixupParents

// Ensure that there are either loggers or placeholders all the way
// from the specified logger to the root of the logger hierarchy.
func (m *manager) fixupParents(l *Logger) {

	var parent *Logger
	name := l.name
	i := strings.LastIndexByte(name, '/')

	for i > 0 && parent == nil {
		name = name[:i]
		if node, ok := m.registry[name]; ok {
			if p, ok := node.(*placeholder); ok {
				// The logger will be child of this placeholder,
				// somewhere in the subtree.
				// if anybody asks later.
				p.append(l)
			} else { // it' s a *Logger, make it the parent
				if n, ok := node.(*Logger); ok {
					parent = n
				} else {
					// unreachable
					panic("Bad logger in registry")
				}
			}
		} else {
			m.registry[name] = newPlaceholder(l)
		}
		i = strings.LastIndexByte(name, '/')
	}
	if parent == nil {
		// If the logger inherited the root as parent from a child which previous had
		// the root as parent, this will just set it again
		parent = m.root
	}
	l.h.SwapParent(parent)
}
开发者ID:One-com,项目名称:gonelog,代码行数:36,代码来源:manager.go

示例4: GetPackage

// GetPackage finds a package by a given name.
// If package doesn't exist in database, then downloads and saves information about new package.
func GetPackage(name string) *MCPMPackage {
	if !db.o {
		open(db.fn)
	}
	if pkg, ok := db.r[name]; ok {
		return pkg
	}
	ht, hte := get(util.DirPathJoin("http://minecraft.curseforge.com/projects", name))
	if hte != nil {
		return nil
	}
	url := ht.Request.URL
	pn := url.Path[strings.LastIndexByte(url.Path, '/')+1:]
	doc, doce := goquery.NewDocumentFromResponse(ht)
	if doce != nil {
		return nil
	}
	tit := doc.Find("h1.project-title a .overflow-tip").Text()
	oa := doc.Find(".RootGameCategory a").Eq(0)
	ida := doc.Find(".view-on-curse a").Eq(0)
	cat := oa.AttrOr("href", " ")
	id := ida.AttrOr("href", "")
	idn := id[strings.LastIndexByte(id, '/')+1:]
	nid, ner := strconv.ParseUint(idn, 10, 64)
	if ner != nil {
		return nil
	}
	pkg := &MCPMPackage{nid, pn, tit, cat[1:]}
	db.r[pn] = pkg
	db.r[idn] = pkg
	db.a = append(db.a, pkg)
	return pkg
}
开发者ID:Szewek,项目名称:mcpm,代码行数:35,代码来源:mcpmdb.go

示例5: GetParentDir

// GetParentDir returns the parent directory(string) of the passed targetDirectory (string)
func GetParentDir(targetDirectory string) string {
	lastSlashIndex := strings.LastIndexByte(targetDirectory, os.PathSeparator)
	//check if the slash is at the end , if yes then re- check without the last slash, we don't want /path/to/ , we want /path/to in order to get the /path/ which is the parent directory of the /path/to
	if lastSlashIndex == len(targetDirectory)-1 {
		lastSlashIndex = strings.LastIndexByte(targetDirectory[0:lastSlashIndex], os.PathSeparator)
	}

	parentDirectory := targetDirectory[0:lastSlashIndex]
	return parentDirectory
}
开发者ID:toksea,项目名称:iris,代码行数:11,代码来源:file.go

示例6: excludeSubDomain

func (l *SiteList) excludeSubDomain(site string) string {
	i := strings.LastIndexByte(site, '.')
	if i < 0 {
		return site
	}
	i2 := strings.LastIndexByte(site[:i], '.')
	if i2 < 0 {
		return site
	}
	return site[i2+1:]
}
开发者ID:cosiner,项目名称:tunnel,代码行数:11,代码来源:site_list.go

示例7: Leaf

// Get the name of the leftmost account group.
// The account name is assumed to be valid as indicated by Valid().
// Example: "e:food.snacks" -> "snacks", "e:food" -> "food", "e:" -> "expense"
func (name AccountName) Leaf() string {
	lastIndex := strings.LastIndexByte(string(name), '.')
	if lastIndex != -1 {
		return string(name[lastIndex+1:])
	}
	lastIndex = strings.LastIndexByte(string(name), ':')
	if lastIndex != -1 && len(name) > AccountNameTypePrefixLen {
		return string(name[lastIndex+1:])
	}
	return name.Type().String()
}
开发者ID:johan-bolmsjo,项目名称:accounting,代码行数:14,代码来源:account_name.go

示例8: GetPath

func GetPath(url string) string {
	p := strings.LastIndexByte(url, '?')
	if p > 0 {
		url = url[:p]
	}
	p = strings.LastIndexByte(url, '/')
	if p > 0 {
		return url[:p+1]
	}
	return "/"
}
开发者ID:hao1118,项目名称:copyweb,代码行数:11,代码来源:main.go

示例9: ParseVariableQName

func ParseVariableQName(qname string) (ns, name string) {
	i := strings.LastIndexByte(qname, ':')
	if i == -1 {
		return "", qname
	}
	return qname[:i+1], qname[i+1:]
}
开发者ID:zhsj,项目名称:elvish,代码行数:7,代码来源:util.go

示例10: unexpected

// unexpected complains about the token and terminates processing.
func (p *parser) unexpected(tok token, expected ...TokenType) {
	const bufSize = 10
	start := tok.pos - bufSize
	if start < 0 {
		start = 0
	}
	// Skip any new lines just show a single line
	if i := strings.LastIndexByte(p.text[start:tok.pos], '\n'); i != -1 {
		start = start + i + 1
	}
	stop := tok.pos + bufSize
	if stop > len(p.text) {
		stop = len(p.text)
	}
	// Skip any new lines just show a single line
	if i := strings.IndexByte(p.text[tok.pos:stop], '\n'); i != -1 {
		stop = tok.pos + i
	}
	line, char := p.lex.lineNumber(tok.pos)
	expectedStrs := make([]string, len(expected))
	for i := range expected {
		expectedStrs[i] = fmt.Sprintf("%q", expected[i])
	}
	expectedStr := strings.Join(expectedStrs, ",")
	tokStr := tok.typ.String()
	if tok.typ == TokenError {
		tokStr = tok.val
	}
	p.errorf("unexpected %s line %d char %d in \"%s\". expected: %s", tokStr, line, char, p.text[start:stop], expectedStr)
}
开发者ID:influxdata,项目名称:kapacitor,代码行数:31,代码来源:parser.go

示例11: extractConsumerIdFromOwnerInfo

func extractConsumerIdFromOwnerInfo(ownerZnodeData string) (consumerId string) {
	// ownerZnodeData:
	//   for java sdk: $consumerId-$threadNum  $consumerId: $group_$hostname-$timestamp-$uuidSignificantBits
	// for golang sdk: $consumerId
	//         others: $consumerId

	consumerId = ownerZnodeData // by default

	if !strings.Contains(ownerZnodeData, "_") {
		// java consumer group always has the "_"
		return
	}

	lastDash := strings.LastIndexByte(ownerZnodeData, '-')
	if lastDash == -1 || lastDash == len(ownerZnodeData)-1 {
		// java consumer group always has the '-' and not ends with '-'
		return
	}

	maybeJavaThreadNum := ownerZnodeData[lastDash+1:]
	if len(maybeJavaThreadNum) > 3 {
		// not a java consumer group because thread num never above 999
		return
	}

	for _, c := range maybeJavaThreadNum {
		if c < '0' || c > '9' {
			// not a java consumer group because threadNum is digit
			return
		}
	}

	// confirmed, it IS java api consumer group: discard the threadNum section
	return ownerZnodeData[:lastDash]
}
开发者ID:funkygao,项目名称:gafka,代码行数:35,代码来源:util.go

示例12: init

func init() {

	// set the current working dir
	if d, err := os.Getwd(); err != nil {
		panic(err)
	} else {
		workingDir = d
	}

	// defaultInstallDir is the default directory which the create will copy and run the package when finish downloading
	// it's just the last path part of the workingDir
	defaultInstallDir := workingDir[strings.LastIndexByte(workingDir, os.PathSeparator)+1:]

	// init the cli app
	app = cli.NewApp("iris", "Command line tool for Iris web framework", Version)
	// version command
	app.Command(cli.Command("version", "\t      prints your iris version").Action(func(cli.Flags) error { app.Printf("%s", iris.Version); return nil }))

	// create command/-/create.go
	createCmd := cli.Command("create", "create a project to a given directory").
		Flag("offline", false, "set to true to disable the packages download on each create command").
		Flag("dir", defaultInstallDir, "$GOPATH/src/$dir the directory to install the sample package").
		Flag("type", "basic", "creates a project based on the -t package. Currently, available types are 'basic' & 'static'").
		Action(create)

	// run command/-/run.go
	runAndWatchCmd := cli.Command("run", "runs and reload on source code changes, example: iris run main.go").Action(runAndWatch)

	// register the commands
	app.Command(createCmd)
	app.Command(runAndWatchCmd)

	// init the logger
	printer = logger.New(config.DefaultLogger())
}
开发者ID:Carbyn,项目名称:iris,代码行数:35,代码来源:main.go

示例13: Get

// Get splits the specified name by the stored delimiter, and attempts to retrieve the nested value
// corresponding to the nested fields.
func (rc *RecordCache) Get(name string) (interface{}, error) {
	if val, ok := rc.db[name]; ok {
		return val, nil
	}

	var err error
	var val interface{}
	var parent interface{} = rc.top
	var parentName, childName string

	if index := strings.LastIndexByte(name, rc.delim); index >= 0 {
		parentName, childName = name[:index], name[index+1:]
		parent, err = rc.Get(parentName)
		if err != nil {
			return nil, err
		}
		rc.db[parentName] = parent
		if _, ok := parent.(*Record); !ok {
			return nil, ErrNotRecord{datum: parent}
		}
		name = childName
	}

	val, err = parent.(*Record).GetQualified(name)
	if err != nil {
		if nerr, ok := err.(ErrNoSuchField); ok {
			nerr.path = parentName
			return nil, nerr
		}
		return nil, err
	}

	rc.db[name] = val
	return val, nil
}
开发者ID:christian-blades-cb,项目名称:goavro,代码行数:37,代码来源:recordCache.go

示例14: Basename

func Basename(s string) string {
	n := strings.LastIndexByte(s, '.')
	if n > 0 {
		return s[:n]
	}
	return s
}
开发者ID:AntonioSun,项目名称:lta,代码行数:7,代码来源:config.go

示例15: getContext

func getContext(content []byte, offset int64) (int, string, int) {
	if offset >= int64(len(content)) || offset < 0 {
		return 0, fmt.Sprintf("[error: Offset %d is out of bounds 0..%d]", offset, len(content)), 0
	}

	lineN := strings.Count(string(content[:offset]), "\n") + 1

	start := strings.LastIndexByte(string(content[:offset]), '\n')
	if start == -1 {
		start = 0
	} else {
		start++
	}

	end := strings.IndexByte(string(content[start:]), '\n')
	l := ""
	if end == -1 {
		l = string(content[start:])
	} else {
		end = end + start
		l = string(content[start:end])
	}

	return lineN, l, (int(offset) - start)
}
开发者ID:cilium-team,项目名称:cilium,代码行数:25,代码来源:main.go


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