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


Golang strings.TrimFunc函数代码示例

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


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

示例1: TrimFunc

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

示例2: parse

func (s Store) parse(reader *bufio.Reader, filename string) (err error) {
	lineno := 0
	section := ""
	for err == nil {
		l, _, err := reader.ReadLine()
		if err != nil {
			break
		}
		lineno++
		if len(l) == 0 {
			continue
		}
		line := strings.TrimFunc(string(l), unicode.IsSpace)
		for line[len(line)-1] == '\\' {
			line = line[:len(line)-1]
			l, _, err := reader.ReadLine()
			if err != nil {
				return err
			}
			line += strings.TrimFunc(string(l), unicode.IsSpace)
		}
		section, err = s.parseLine(section, line)
		if err != nil {
			return StoreParseError(filename, lineno)
		}
	}
	return err
}
开发者ID:maiconio,项目名称:flotilla,代码行数:28,代码来源:store.go

示例3: matchImportance

func (q *Query) matchImportance(i int) bool {

	if q.Importance == "" {
		return true
	}

	val, err := strconv.Atoi(strings.TrimFunc(q.Importance, unicode.IsLetter))
	if err != nil {
		//maybe don't fatal
		logger.Criticalf("%+v", err)
		return false
	}

	switch strings.TrimFunc(q.Importance, unicode.IsDigit) {
	case "gte":
		return (i >= val)
	case "gt":
		return (i > val)
	case "lte":
		return (i <= val)
	case "lt":
		return (i < val)
	}
	return (val == i)

}
开发者ID:straumur,项目名称:straumur,代码行数:26,代码来源:query.go

示例4: LoadReader

func LoadReader(reader *bufio.Reader) (dict Dict, err error) {
	dict = make(map[string]map[string]string)
	lineno := 0
	section := ""
	dict[section] = make(map[string]string)

	for err == nil {
		l, _, err := reader.ReadLine()
		if err != nil {
			break
		}
		lineno++
		if len(l) == 0 {
			continue
		}
		line := strings.TrimFunc(string(l), unicode.IsSpace)

		for line[len(line)-1] == '\\' {
			line = line[:len(line)-1]
			l, _, err := reader.ReadLine()
			if err != nil {
				return nil, err
			}
			line += strings.TrimFunc(string(l), unicode.IsSpace)
		}

		section, err = dict.parseLine(section, line)
		if err != nil {
			return nil, newError(
				err.Error() + fmt.Sprintf("':%d'.", lineno))
		}
	}

	return
}
开发者ID:tpot,项目名称:goini,代码行数:35,代码来源:ini.go

示例5: parseLine

func (dict Dict) parseLine(section, line string) (string, error) {
	// comments
	if line[0] == '#' || line[0] == ';' {
		return section, nil
	}

	// section name
	if line[0] == '[' && line[len(line)-1] == ']' {
		sec := strings.TrimFunc(line[1:len(line)-1], unicode.IsSpace)
		sec = strings.ToLower(sec)
		dict[sec] = make(map[string]string)
		return sec, nil
	}

	// key = value
	if m := regDoubleQuote.FindAllStringSubmatch(line, 1); m != nil {
		dict.add(section, m[0][1], m[0][2])
		return section, nil
	} else if m = regSingleQuote.FindAllStringSubmatch(line, 1); m != nil {
		dict.add(section, m[0][1], m[0][2])
		return section, nil
	} else if m = regNoQuote.FindAllStringSubmatch(line, 1); m != nil {
		dict.add(section, m[0][1], strings.TrimFunc(m[0][2], unicode.IsSpace))
		return section, nil
	} else if m = regNoValue.FindAllStringSubmatch(line, 1); m != nil {
		dict.add(section, m[0][1], "")
		return section, nil
	}

	return section, newError("iniparser: syntax error at ")
}
开发者ID:giel,项目名称:goini,代码行数:31,代码来源:ini.go

示例6: parseLine

func (s Store) parseLine(section, line string) (string, error) {
	if line[0] == '#' || line[0] == ';' {
		return section, nil
	}

	if line[0] == '[' && line[len(line)-1] == ']' {
		section := strings.TrimFunc(line[1:len(line)-1], unicode.IsSpace)
		section = strings.ToLower(section)
		return section, nil
	}

	if m := regDoubleQuote.FindAllStringSubmatch(line, 1); m != nil {
		s.add(section, m[0][1], m[0][2])
		return section, nil
	} else if m = regSingleQuote.FindAllStringSubmatch(line, 1); m != nil {
		s.add(section, m[0][1], m[0][2])
		return section, nil
	} else if m = regNoQuote.FindAllStringSubmatch(line, 1); m != nil {
		s.add(section, m[0][1], strings.TrimFunc(m[0][2], unicode.IsSpace))
		return section, nil
	} else if m = regNoValue.FindAllStringSubmatch(line, 1); m != nil {
		s.add(section, m[0][1], "")
		return section, nil
	}
	return section, errors.New("conf parse error")
}
开发者ID:maiconio,项目名称:flotilla,代码行数:26,代码来源:store.go

示例7: command

// command executes an external command in the given directory.
// The command's standard out and error are trimmed and returned as strings
// It may return the type *GitError if the command itself fails.
func command(w io.Writer, name, dir string, args ...string) (stdout, stderr string, err error) {
	cmdOut := &bytes.Buffer{}
	cmdErr := &bytes.Buffer{}

	cmd := exec.Command(name, args...)
	cmd.Dir = dir
	if w != nil {
		cmd.Stdout = w
	} else {
		cmd.Stdout = cmdOut
	}
	cmd.Stderr = cmdErr

	err = cmd.Run()
	if w == nil {
		stdout = strings.TrimFunc(cmdOut.String(), unicode.IsSpace)
	}
	stderr = strings.TrimFunc(cmdErr.String(), unicode.IsSpace)
	if exitErr, ok := err.(*exec.ExitError); ok {
		err = &GitError{
			Err:    exitErr,
			Stdout: stdout,
			Stderr: stderr,
		}
	}
	return
}
开发者ID:hloganathan,项目名称:origin,代码行数:30,代码来源:repository.go

示例8: parseMetadata

func parseMetadata(line string) *metadata {
	index := strings.Index(line, ":")
	if index == -1 {
		return nil
	}

	return &metadata{
		k: strings.TrimFunc(line[:index], unicode.IsSpace),
		v: strings.TrimFunc(line[index+1:], unicode.IsSpace),
	}
}
开发者ID:devsmt,项目名称:blog,代码行数:11,代码来源:parser.go

示例9: UnmarshalJSON

func (mp *mesosPorts) UnmarshalJSON(b []byte) error {
	p := strings.TrimFunc(string(b), func(r rune) bool {
		return r == '[' || r == ']' || r == '"'
	})

	ports := []int{}

	for _, s := range strings.Split(p, " ") {
		r := strings.Split(s, "-")
		if len(r) != 2 {
			return fmt.Errorf("expected port range to be in formate XXXX-YYYY, got %s", r)
		}

		start, err := strconv.Atoi(r[0])
		if err != nil {
			return err
		}

		end, err := strconv.Atoi(r[1])
		if err != nil {
			return err
		}

		for i := start; i <= end; i++ {
			ports = append(ports, i)
		}
	}

	*mp = mesosPorts(ports)

	return nil
}
开发者ID:dec5e,项目名称:zoidberg,代码行数:32,代码来源:mesos.go

示例10: SearchJSON

func SearchJSON(ctx *middleware.Context) {
	q := ctx.Query("q")

	// Clean up keyword.
	q = strings.TrimFunc(q, func(c rune) bool {
		return unicode.IsSpace(c) || c == '"'
	})
	fmt.Println(q)

	pinfos, err := models.SearchPkgInfo(7, q)
	if err != nil {
		log.ErrorD(4, "SearchPkgInfo '%s': %v", q, err)
		return
	}

	results := make([]*searchResult, len(pinfos))
	for i := range pinfos {
		results[i] = &searchResult{
			Title:       pinfos[i].ImportPath,
			Description: pinfos[i].Synopsis,
		}
	}

	ctx.JSON(200, map[string]interface{}{
		"results": results,
	})
}
开发者ID:hexiaochun,项目名称:gowalker,代码行数:27,代码来源:search.go

示例11: Recv

// Recv listens for incoming messages. Two constants have been provided for
// use: IRC_READ_CHUNK should be used in almost all cases, as it listens for
// a fixed size message; IRC_READ_ALL will read until the connection closes.
// The block parameter, if false, will set a timeout on the socket (this
// timeout can be changed by modifying the constant IRC_TIMEOUT), resetting
// the socket to blocking mode after the receive.
func (irc *Irc) Recv(size int, block bool) (reply string, err error) {
	buf := make([]byte, size)

	if !block {
		dur, _ := time.ParseDuration(IRC_TIMEOUT)
		timeo := time.Now().Add(dur)
		irc.conn.SetDeadline(timeo)
	}

	if size == 0 {
		buf, err = ioutil.ReadAll(irc.conn)
	} else {
		_, err = irc.conn.Read(buf)
	}

	if err != nil {
		if err == io.EOF {
			fmt.Println("[+] connection closed.")
			irc.Quit(0)
		} else if err != nil && timeout(err) {
			fmt.Println("[-] timeout: resetting err")
			err = nil
		}
	}
	reply = strings.TrimFunc(string(buf), TrimReply)
	irc.conn.SetDeadline(time.Unix(0, 0))
	return
}
开发者ID:qbit,项目名称:goirc,代码行数:34,代码来源:irc.go

示例12: readData

// readData constructs an in-memory vector with all input strings.
func readData(fn string) []string {
	f, err := os.Open(fn)
	if nil != err {
		fmt.Fprintf(os.Stderr, "!! Unable to open the input file: %s; %s\n", fn, err)
		os.Exit(-1)
	}
	defer f.Close()

	r := bufio.NewReaderSize(f, 4*1024)

	v := make([]string, 0, INIT_INPUT_SIZE)

	for {
		by, _, err := r.ReadLine()
		if nil != err {
			break
		}
		s := strings.TrimFunc(string(by), func(c rune) bool {
			if (' ' == c) || ('\t' == c) {
				return true
			}
			return false
		})
		if len(s) > 0 {
			v = append(v, s)
		}
	}

	return v
}
开发者ID:js-ojus,项目名称:damlevdist.go,代码行数:31,代码来源:similarity.go

示例13: addNodeLinks

func addNodeLinks(nodes map[string]*Node, line string) []byte {
	var buf bytes.Buffer
	scan := bufio.NewScanner(strings.NewReader(line))
	scan.Split(bufio.ScanWords)
	for scan.Scan() {
		word := strings.TrimFunc(scan.Text(), unicode.IsPunct)
		parts := strings.Split(word, ".")
		node := word
		method := ""
		if len(parts) == 2 {
			node = parts[0]
			method = parts[1]
		}
		if nodes[node] != nil && ast.IsExported(node) {
			buf.Write([]byte("["))
			buf.Write(scan.Bytes())
			buf.Write([]byte("]("))
			if method == "" {
				buf.Write([]byte(nodeNameToLink(node)))
			} else {
				buf.Write([]byte(methodNameToLink(node, method)))
			}
			buf.Write([]byte(") "))
		} else {
			buf.Write(scan.Bytes())
			buf.Write([]byte(" "))
		}
	}
	return buf.Bytes()
}
开发者ID:md14454,项目名称:kapacitor,代码行数:30,代码来源:main.go

示例14: parseConfigFile

func parseConfigFile(rd io.Reader) (*configFile, error) {
	scanner := bufio.NewScanner(rd)

	cfg := configFile{[]configFileHost{}}

	for scanner.Scan() {
		fields := strings.Fields(scanner.Text())

		if len(fields) == 2 {
			fields[1] = strings.TrimFunc(fields[1], func(r rune) bool {
				return r == '"'
			})

			if fields[0] == "Host" {
				pattern, err := parsePattern(fields[1])
				if err != nil {
					return nil, err
				}

				cfg.hosts = append(cfg.hosts, configFileHost{
					pattern: pattern,
					options: []configFileOption{},
				})
			} else if len(cfg.hosts) > 0 {
				cfg.hosts[len(cfg.hosts)-1].options = append(
					cfg.hosts[len(cfg.hosts)-1].options,
					configFileOption{fields[0], fields[1]},
				)
			}
		}
	}

	return &cfg, nil
}
开发者ID:postfix,项目名称:sshutil,代码行数:34,代码来源:config.go

示例15: Units

func (lt *logTuple) Units() string {
	_, err := lt.Float64()
	if err != nil {
		return ""
	}
	return strings.TrimFunc(string(lt.Val), trimToChar)
}
开发者ID:pjvds,项目名称:l2met,代码行数:7,代码来源:log_tuple.go


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