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


Golang strings.TrimLeftFunc函数代码示例

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


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

示例1: ParseIni

func ParseIni(config_lines []string) map[string]map[string]string {
	config := make(map[string]map[string]string)
	current_seg := "General"
	for _, line := range config_lines {
		line = strings.TrimLeftFunc(line, unicode.IsSpace)
		if len(line) <= 0 || line[0] == ';' {
			continue
		}
		if line[0] == '[' && line[len(line)-1] == ']' {
			current_seg = line[1 : len(line)-1]
			continue
		}
		fields := strings.SplitN(line, "=", 2)
		if len(fields) != 2 {
			log.Fatal("Invalid Config Item: ", line)
			os.Exit(1)
		}
		key := strings.TrimLeftFunc(fields[0], unicode.IsSpace)
		value := strings.TrimLeftFunc(fields[1], unicode.IsSpace)
		if _, found := config[current_seg]; !found {
			config[current_seg] = make(map[string]string)
		}
		config[current_seg][key] = value
	}
	return config
}
开发者ID:kmiku7,项目名称:practice,代码行数:26,代码来源:chap4_exercise.go

示例2: consumeMediaParam

func consumeMediaParam(v string) (param, value, rest string) { // 解析mediatype
	rest = strings.TrimLeftFunc(v, unicode.IsSpace)
	if !strings.HasPrefix(rest, ";") {
		return "", "", v
	}

	rest = rest[1:] // consume semicolon
	rest = strings.TrimLeftFunc(rest, unicode.IsSpace)
	param, rest = consumeToken(rest)
	param = strings.ToLower(param)
	if param == "" {
		return "", "", v
	}

	rest = strings.TrimLeftFunc(rest, unicode.IsSpace)
	if !strings.HasPrefix(rest, "=") {
		return "", "", v
	}
	rest = rest[1:] // consume equals sign
	rest = strings.TrimLeftFunc(rest, unicode.IsSpace)
	value, rest = consumeValue(rest)
	if value == "" {
		return "", "", v
	}
	return param, value, rest
}
开发者ID:wenfang,项目名称:golang1.5-src,代码行数:26,代码来源:mediatype.go

示例3: TrimLeftFunc

// TrimLeftFunc returns a slice of the string s with all leading Unicode code point
// c satisfying f(c) removed
func TrimLeftFunc(s string, f func(rune) bool) string {
	inner_func := func(r rune) bool {
		return r <= 'c' || r >= 'i'
	}
	fmt.Println(strings.TrimLeftFunc("abcdefghijk", inner_func))   // defghijk
	fmt.Println(strings.TrimLeftFunc("agbcdefghijk", inner_func))  // gbcdefghijk
	fmt.Println(strings.TrimLeftFunc("asgbcdefghijk", inner_func)) // gbcdefghijk
	return strings.TrimLeftFunc(s, f)
}
开发者ID:upccup,项目名称:cuplearn,代码行数:11,代码来源:stringsTest.go

示例4: ParseString

func ParseString(ss []string, is_end bool, vs string) (Variable, []string, error) {
	simple_line := strings.TrimSpace(vs)
	if !strings.HasPrefix(simple_line, "\"") {
		return nil, nil, errors.New("parse `" + strings.Join(ss, "\r\n") + "` failed, \"" + simple_line + "\" is not start with \".")
	}
	if 1 < len(simple_line) {
		if strings.HasSuffix(simple_line, "\"") {
			return NewOctetString([]byte(simple_line[1 : len(simple_line)-1])), ss[1:], nil
		}
	}

	p := -1
	for idx, sss := range ss[1:] {
		if re.MatchString(sss) {
			p = idx
			break
		} else if strings.Contains(sss, "MIB search path") ||
			//strings.HasPrefix(sss, "#") ||
			strings.Contains(sss, "Cannot find module") ||
			strings.Contains(sss, "#tools\\snmpwalk.exe") {
			p = idx
			break
		}
	}

	if -1 == p {
		if is_end {
			simple_line = strings.TrimLeftFunc(vs, unicode.IsSpace)
			if 1 != len(ss) {
				simple_line = simple_line[1:] + "\r\n" + strings.Join(ss[1:], "\r\n")
			}
			if strings.HasSuffix(simple_line, "\"") {
				simple_line = simple_line[:len(simple_line)-1]
			}
			if strings.HasPrefix(simple_line, "\"") {
				simple_line = simple_line[1:]
			}
			return NewOctetString([]byte(simple_line)), nil, nil
		}
		return nil, ss, more_line
	}
	p += 1

	simple_line = strings.TrimLeftFunc(vs, unicode.IsSpace)
	if 1 != p {
		simple_line = simple_line + "\r\n" + strings.Join(ss[1:p], "\r\n")
	}
	if strings.HasSuffix(simple_line, "\"") {
		simple_line = simple_line[:len(simple_line)-1]
	}

	if strings.HasPrefix(simple_line, "\"") {
		simple_line = simple_line[1:]
	}

	return NewOctetString([]byte(simple_line)), ss[p:], nil
}
开发者ID:runner-mei,项目名称:snmpclient2,代码行数:57,代码来源:read_line.go

示例5: splitShellCmd

func splitShellCmd(cmd string) (name, args string) {
	cmd = strings.TrimLeftFunc(cmd, unicode.IsSpace)
	switch pre := strings.IndexFunc(cmd, unicode.IsSpace); {
	case pre > 0:
		name, args = cmd[:pre], strings.TrimLeftFunc(cmd[pre:], unicode.IsSpace)
	case pre == -1:
		name = cmd
	default:
		panic("unexpected case (untrimmed)")
	}
	return
}
开发者ID:bmatsuo,项目名称:goline,代码行数:12,代码来源:goline.go

示例6: writeString

func (n *ninjaWriterWithWrap) writeString(s string, space bool) {
	if n.err != nil {
		return
	}

	spaceLen := 0
	if space {
		spaceLen = 1
	}

	if n.writtenLen+len(s)+spaceLen > n.maxLineLen {
		_, n.err = io.WriteString(n.writer, " $\n")
		if n.err != nil {
			return
		}
		_, n.err = io.WriteString(n.writer, indentString[:indentWidth*2])
		if n.err != nil {
			return
		}
		n.writtenLen = indentWidth * 2
		s = strings.TrimLeftFunc(s, unicode.IsSpace)
	} else if space {
		io.WriteString(n.writer, " ")
		n.writtenLen++
	}

	_, n.err = io.WriteString(n.writer, s)
	n.writtenLen += len(s)
}
开发者ID:robinivanka,项目名称:blueprint,代码行数:29,代码来源:ninja_writer.go

示例7: Parse

// Parse is the main parse routine.
// It handles an io.ReadWriteCloser and returns the root of the AST.
func Parse(rwc io.Reader) (*Node, error) {
	directiveEscapeSeen = false
	lookingForDirectives = true
	setTokenEscape(defaultTokenEscape) // Assume the default token for escape
	currentLine := 0
	root := &Node{}
	root.StartLine = -1
	scanner := bufio.NewScanner(rwc)

	for scanner.Scan() {
		scannedLine := strings.TrimLeftFunc(scanner.Text(), unicode.IsSpace)
		currentLine++
		line, child, err := ParseLine(scannedLine)
		if err != nil {
			return nil, err
		}
		startLine := currentLine

		if line != "" && child == nil {
			for scanner.Scan() {
				newline := scanner.Text()
				currentLine++

				if stripComments(strings.TrimSpace(newline)) == "" {
					continue
				}

				line, child, err = ParseLine(line + newline)
				if err != nil {
					return nil, err
				}

				if child != nil {
					break
				}
			}
			if child == nil && line != "" {
				_, child, err = ParseLine(line)
				if err != nil {
					return nil, err
				}
			}
		}

		if child != nil {
			// Update the line information for the current child.
			child.StartLine = startLine
			child.EndLine = currentLine
			// Update the line information for the root. The starting line of the root is always the
			// starting line of the first child and the ending line is the ending line of the last child.
			if root.StartLine < 0 {
				root.StartLine = currentLine
			}
			root.EndLine = currentLine
			root.Children = append(root.Children, child)
		}
	}

	return root, nil
}
开发者ID:marccampbell,项目名称:docker,代码行数:62,代码来源:parser.go

示例8: replaceTagsLi

func replaceTagsLi(c string, n *html.Node) string {
	data := strings.TrimLeftFunc(c, unicode.IsSpace)
	data = strings.Replace(data, "\n", "\n    ", -1)

	pref := "*   "

	p := n.Parent

	if p != nil {
		i := 0
		for c := p.FirstChild; c != nil; c = c.NextSibling {
			if c.DataAtom == atom.Li {
				i++
				if c == n {
					break
				}
			}
		}

		if p.DataAtom == atom.Ol {
			pref = fmt.Sprintf("%d.   ", i)
		}
	}

	return pref + data
}
开发者ID:ph34rd,项目名称:html2md,代码行数:26,代码来源:replacers.go

示例9: Write

func (w wsCollapser) Write(p []byte) (n int, err error) {
	lines := strings.Split(string(p), "\n")
	for i, line := range lines {
		l := line
		if *w.prevNewLine {
			l = strings.TrimLeftFunc(l, unicode.IsSpace)
		}
		curNewLine := (i < len(lines)-1) || (len(p) > 0 && p[len(p)-1] == '\n')
		if curNewLine {
			l = strings.TrimRightFunc(l, unicode.IsSpace)
		}
		if len(l) == 0 {
			*w.prevNewLine = curNewLine
			continue
		}
		if *w.prevNewLine && !*w.prevTag && l[0] != '<' {
			_, err := (*w.writer).Write([]byte(" "))
			if err != nil {
				return 0, err
			}
		}
		_, err := (*w.writer).Write([]byte(l))
		if err != nil {
			return 0, err
		}
		*w.prevTag = l[len(l)-1] == '>'
		*w.prevNewLine = curNewLine
	}
	return len(p), nil
}
开发者ID:hochhaus,项目名称:mammothmail,代码行数:30,代码来源:www.go

示例10: Read

func (r *CommentStripper) Read(p []byte) (int, error) {
	for {
		if r.buf.Len() >= len(p) {
			return r.buf.Read(p)
		}
		line, err := r.r.ReadString(r.Delimiter)
		if len(line) > 0 {
			checkLine := line
			if r.Whitespace {
				checkLine = strings.TrimLeftFunc(checkLine, unicode.IsSpace)
			}
			if strings.HasPrefix(checkLine, r.Comment) {
				// yay, skip this line
				continue
			}
			r.buf.WriteString(line)
		}
		if err != nil {
			if r.buf.Len() > 0 {
				return r.buf.Read(p)
			}
			return 0, err
		}
	}
}
开发者ID:Lightstreamer,项目名称:official-images,代码行数:25,代码来源:comments.go

示例11: parseEngineeringNotation

func parseEngineeringNotation(in string) (uint64, error) {
	if in == "" {
		return 0, nil
	}
	var numerics = func(r rune) bool {
		return r >= '0' && r <= '9'
	}
	var nonNumerics = func(r rune) bool {
		return !numerics(r)
	}
	suffix := strings.TrimLeftFunc(in, numerics)
	numeric := strings.TrimRightFunc(in, nonNumerics)
	val, err := strconv.ParseUint(numeric, 10, 64)
	if err != nil {
		return 0, fmt.Errorf("Parsing engineering notation for '%s'", in)
	}
	switch suffix {
	case "K", "k":
		val *= (1 << 10)
	case "M", "m":
		val *= (1 << 20)
	case "G", "g":
		val *= (1 << 30)
	case "T", "t":
		val *= (1 << 40)
	case "":
		break
	default:
		return 0, fmt.Errorf("Parsing engineering notation for '%s'", in)
	}
	return val, nil
}
开发者ID:eval01-tts,项目名称:serviced,代码行数:32,代码来源:engnotation.go

示例12: ParseCaptions

func ParseCaptions(source string) (*CaptionsConfiguration, error) {
	c := new(CaptionsConfiguration)
	c.Captions = make(map[string]string)
	c.Variables = make(map[string]string)

	source = strings.Replace(source, "\r\n", "\n", -1)
	for i, line := range strings.Split(source, "\n") {
		line = strings.TrimLeftFunc(line, unicode.IsSpace) // remove leading space

		// ignore comments and empty lines
		if strings.HasPrefix(line, "#") || strings.HasPrefix(line, "//") || line == "" {
			continue
		}

		parts := strings.SplitN(line, ": ", 2)

		if len(parts) != 2 {
			return nil, errors.New("Wrong format in line " + strconv.Itoa(i))
		}

		if strings.HasPrefix(line, "$") {
			name := strings.TrimLeft(parts[0], "$")
			c.Variables[name] = parts[1]
			continue
		}

		c.Captions[parts[0]] = parts[1]
	}
	return c, nil
}
开发者ID:Philipp15b,项目名称:Captioneer,代码行数:30,代码来源:config.go

示例13: comment

func comment(text string) string {
	lines := strings.Split(text, "\n")

	var output string
	if len(lines) == 1 && lines[0] == "" {
		return ""
	}

	// Helps to determine if
	// there is an actual comment
	// without screwing newlines
	// in real comments.
	hasComment := false

	for _, line := range lines {
		line = strings.TrimLeftFunc(line, unicode.IsSpace)
		if line != "" {
			hasComment = true
		}
		output += "\n// " + line
	}

	if hasComment {
		return output
	}
	return ""
}
开发者ID:hooklift,项目名称:govsphere,代码行数:27,代码来源:generator.go

示例14: cleanMessage

// Clean a message, remove leading username
func cleanMessage(rawMessage string) string {
	msg := strings.TrimPrefix(rawMessage, conf.Nick)
	msg = strings.TrimLeftFunc(msg, func(char rune) bool {
		return char == ',' || char == ':' || char == '-' || char == ' '
	})
	return msg
}
开发者ID:rnestler,项目名称:moss,代码行数:8,代码来源:moss.go

示例15: parseJSON

// parseJSON converts JSON arrays to an AST.
func parseJSON(rest string) (*Node, map[string]bool, error) {
	rest = strings.TrimLeftFunc(rest, unicode.IsSpace)
	if !strings.HasPrefix(rest, "[") {
		return nil, nil, fmt.Errorf(`Error parsing "%s" as a JSON array`, rest)
	}

	var myJSON []interface{}
	if err := json.NewDecoder(strings.NewReader(rest)).Decode(&myJSON); err != nil {
		return nil, nil, err
	}

	var top, prev *Node
	for _, str := range myJSON {
		s, ok := str.(string)
		if !ok {
			return nil, nil, errDockerfileNotStringArray
		}

		node := &Node{Value: s}
		if prev == nil {
			top = node
		} else {
			prev.Next = node
		}
		prev = node
	}

	return top, map[string]bool{"json": true}, nil
}
开发者ID:azurezk,项目名称:docker,代码行数:30,代码来源:line_parsers.go


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