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


Golang strings.TrimLeft函数代码示例

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


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

示例1: GetMeanings

func (t *LingvoLiveTranslatorResponseFull) GetMeanings() []IParticularMeaning {
	meanings := []IParticularMeaning{}
	for _, v := range t.Articles {
		meaning := &Meaning{Dictionary: v.Dictionary}
		doc, _ := goquery.NewDocumentFromReader(strings.NewReader(v.BodyHtml))

		table := doc.Find(".article .article-body .article-body-items")
		table.Find(".article-body-items").Each(func(i int, s *goquery.Selection) {

			if s.Find(".paragraph-marker-top-level").Text() == "" {
				if s.Find(".parts-of-speech").Text() != "" && len(s.Find(".article-text").Nodes) == 0 {
					return
				}
			}

			value := s.Find(".article-text-wrap .article-text").Text()
			if value == "" {
				// maybe comment
				value = s.Find(".article-text-wrap .comment").Text()
			}
			value = strings.TrimLeft(value, "<-s, ->")
			value = strings.TrimLeft(value, ";")
			value = strings.TrimSpace(value)
			if "" != value {
				meaning.All = append(meaning.All, value)
			}
			if len(meaning.All) > 0 && meaning.Text == "" {

				meaning.Text = meaning.All[0]
			}
		})
		meanings = append(meanings, meaning)
	}
	return meanings
}
开发者ID:unitrans,项目名称:unitrans,代码行数:35,代码来源:abbyy_lingvo_live.go

示例2: TestEndToEndMkdirNoParentTimestamp

func TestEndToEndMkdirNoParentTimestamp(t *testing.T) {
	tc := NewTestCase(t)
	defer tc.Clean()

	tc.RunSuccess(WorkRequest{
		Argv: []string{"mkdir", "-p", tc.wd + "/dir"},
	})
	rootless := strings.TrimLeft(tc.wd, "/")
	beforeTime := tc.master.attributes.Get(rootless + "/dir").ChangeTime()
	var after *attr.FileAttr
	for i := 0; ; i++ {
		time.Sleep(10e6)
		subdir := fmt.Sprintf(tc.wd+"/dir/subdir%d", i)
		tc.RunSuccess(WorkRequest{
			Argv: []string{"mkdir", subdir},
		})
		after = tc.master.attributes.Get(strings.TrimLeft(subdir, "/"))
		if !after.ChangeTime().Equal(beforeTime) {
			break
		}
	}

	afterDir := tc.master.attributes.Get(rootless + "/dir")
	if afterDir.ChangeTime().Equal(beforeTime) {
		t.Errorf("Forgot to update parent timestamps")
	}
}
开发者ID:hanwen,项目名称:termite,代码行数:27,代码来源:masterrun_test.go

示例3: TrimLeft

// TrimLeft returns a slice of the string s with alll leading Unicode code point
// contained in cutset removed
func TrimLeft(s string, cutset string) string {
	fmt.Printf("[%q]\n", strings.TrimLeft(" !!! Achtung! Achtung! !!! ", "! "))     // ["Achtung! Achtung! !!! "]
	fmt.Printf("[%q]\n", strings.TrimLeft(" !!! Achtung! Achtung! !!! @@@ ", "[email protected]")) // [" !!! Achtung! Achtung! !!! @@@ "]
	fmt.Printf("[%q]\n", strings.TrimLeft(" !!! Achtung! Achtung! !!! ", ""))       // [" !!! Achtung! Achtung! !!! "]
	fmt.Printf("[%q]\n", strings.TrimLeft(" !!! Achtung! Achtung! !!! ", " "))      // ["!!! Achtung! Achtung! !!! "]
	return strings.TrimLeft(s, cutset)
}
开发者ID:upccup,项目名称:cuplearn,代码行数:9,代码来源:stringsTest.go

示例4: PullRequest

// The request message must like:
//{
//    "Event":0,
//    "FileName":"+/path/to/file",  or "FileName":"-/path/to/file"  // +/- means add or remove watch
//    ....
//}
func (em *Distributer) PullRequest() (map[string]string, error) {
	str, err := em.Read()
	if err != nil {
		logging.Debug("Pull request:", err)
		return nil, err
	}
	m, err := router.ParseMessage(str)
	if err != nil {
		logging.Debug("Pull request:", err)
		return nil, err
	}
	if m.Event != 0 {
		return nil, errors.New("Invalid request")
	}
	msg := make(map[string]string)
	if strings.HasPrefix(m.FileName, "+") {
		msg["ACTION"] = "ADD"
		msg["PATH"] = strings.TrimLeft(m.FileName, "+")
		return msg, nil
	} else if strings.HasPrefix(m.FileName, "-") {
		msg["ACTION"] = "REMOVE"
		msg["PATH"] = strings.TrimLeft(m.FileName, "-")
		return msg, nil
	}
	return nil, errors.New("Shouldn't come here")
}
开发者ID:qjpcpu,项目名称:watchman,代码行数:32,代码来源:alfred.go

示例5: goodOSArchConstraints

func goodOSArchConstraints(file *ast.File) (ok bool) {
	max := file.Package

	for _, comment := range file.Comments {
		if comment.Pos() >= max {
			break
		}

		if len(comment.List) == 0 {
			continue
		}

		line := comment.List[0].Text
		line = strings.TrimLeft(line, "/")
		line = strings.TrimSpace(line)

		if !strings.HasPrefix(line, "+build ") {
			continue
		}

		// Loop over lines == AND
		for _, cmt := range comment.List {
			line := cmt.Text
			line = strings.TrimLeft(line, "/")
			line = strings.TrimSpace(line)[7:]

			satisfied := false

			// Loop over groups == OR
			for _, group := range strings.Split(line, " ") {
				gSatisfied := true

				// Loop over constraints == AND
				for _, constraint := range strings.Split(group, ",") {
					if constraint == goos || constraint == goarch {
						continue
					}

					if knownOS[constraint] || knownArch[constraint] {
						gSatisfied = false
					}

					if constraint == "ignore" {
						gSatisfied = false
					}
				}

				if gSatisfied {
					satisfied = true
				}
			}

			if !satisfied {
				return false
			}
		}
	}

	return true
}
开发者ID:Grigs-b,项目名称:withmock,代码行数:60,代码来源:constraints.go

示例6: parseArgs

func parseArgs(flags []*Flag, args []string) (map[string]*Flag, []string, error) {
	flagMap := map[string]*Flag{}
	for _, f := range flags {
		ks := strings.Split(f.Key, ",")
		for _, k := range ks {
			k = strings.TrimSpace(k)
			k = strings.TrimLeft(k, "-")
			flagMap[k] = f
		}
	}

	updatedArgs := []string{}
	for i := 0; i < len(args); i++ {
		k := args[i]
		if !isFlag(k) {
			updatedArgs = append(updatedArgs, k)
			continue
		}
		k = strings.TrimLeft(k, "-")
		f, ok := flagMap[k]
		if !ok {
			return nil, nil, errors.New("no flag found: " + k)
		}
		if i+1 == len(args) || isFlag(args[i+1]) {
			f.Value = ptr("")
		} else {
			f.Value = ptr(args[i+1])
			i++
		}
	}
	return flagMap, updatedArgs, nil
}
开发者ID:octavore,项目名称:naga,代码行数:32,代码来源:command.go

示例7: parseRecord

func parseRecord(data string, config *Config) (string, string) {
	va := strings.Split(data, _SEPARATOR_SYMBOL)

	propName := va[0]
	propValue := strings.Join(va[1:], _SEPARATOR_SYMBOL)

	propName = strings.TrimLeft(propName, " ")
	propValue = strings.TrimLeft(propValue, " ")

	if strings.Contains(propValue, _MACRO_SYMBOL) {
		macroses := macroRE.FindAllStringSubmatch(propValue, -1)

		for _, macros := range macroses {
			macroFull := macros[0]
			macroSect := macros[1]
			macroProp := macros[2]

			macroVal := config.GetS(macroSect + _DELIMITER + macroProp)

			propValue = strings.Replace(propValue, macroFull, macroVal, -1)
		}
	}

	return propName, propValue
}
开发者ID:essentialkaos,项目名称:ek,代码行数:25,代码来源:knf.go

示例8: parseSeasonEp

func parseSeasonEp(name string) *showSeasonEp {
	for _, r := range regularShowRegexes {
		reu := types.RegexpUtil{Regex: r}
		m := reu.FindStringSubmatchMap(name)
		if len(m) > 0 {
			sse := &showSeasonEp{}
			if s, ok := m["season"]; ok {
				sse.Season = strings.TrimLeft(s, "0")
			}
			if s, ok := m["episode"]; ok {
				sse.Episode = strings.TrimLeft(s, "0")
			}
			if s, ok := m["lastepisode"]; ok {
				sse.LastEpisode = s
			}
			return sse
		}
	}
	m := seasonEpRegex7.FindStringSubmatch(name)
	if m != nil {
		return &showSeasonEp{
			Season:  m[3] + m[4],
			Episode: m[5] + "/" + m[6],
			Airdate: m[2],
		}
	}
	//TODO: add the rest
	return nil
}
开发者ID:hobeone,项目名称:gonab,代码行数:29,代码来源:tv.go

示例9: ParseEnvFile

// ParseEnvFile reads a file with environment variables enumerated by lines
//
// ``Environment variable names used by the utilities in the Shell and
// Utilities volume of IEEE Std 1003.1-2001 consist solely of uppercase
// letters, digits, and the '_' (underscore) from the characters defined in
// Portable Character Set and do not begin with a digit. *But*, other
// characters may be permitted by an implementation; applications shall
// tolerate the presence of such names.''
// -- http://pubs.opengroup.org/onlinepubs/009695399/basedefs/xbd_chap08.html
//
// As of #16585, it's up to application inside docker to validate or not
// environment variables, that's why we just strip leading whitespace and
// nothing more.
func ParseEnvFile(filename string) ([]string, error) {
	fh, err := os.Open(filename)
	if err != nil {
		return []string{}, err
	}
	defer fh.Close()

	lines := []string{}
	scanner := bufio.NewScanner(fh)
	for scanner.Scan() {
		// trim the line from all leading whitespace first
		line := strings.TrimLeft(scanner.Text(), whiteSpaces)
		// line is not empty, and not starting with '#'
		if len(line) > 0 && !strings.HasPrefix(line, "#") {
			data := strings.SplitN(line, "=", 2)

			// trim the front of a variable, but nothing else
			variable := strings.TrimLeft(data[0], whiteSpaces)
			if strings.ContainsAny(variable, whiteSpaces) {
				return []string{}, ErrBadEnvVariable{fmt.Sprintf("variable '%s' has white spaces", variable)}
			}

			if len(data) > 1 {

				// pass the value through, no trimming
				lines = append(lines, fmt.Sprintf("%s=%s", variable, data[1]))
			} else {
				// if only a pass-through variable is given, clean it up.
				lines = append(lines, fmt.Sprintf("%s=%s", strings.TrimSpace(line), os.Getenv(line)))
			}
		}
	}
	return lines, scanner.Err()
}
开发者ID:CadeLaRen,项目名称:docker-3,代码行数:47,代码来源:envfile.go

示例10: Run

func (c *JoinCommand) Run(v *View, e *Edit) error {
	sel := v.Sel()
	for i := 0; i < sel.Len(); i++ {
		r := sel.Get(i)
		// Removing new line and triming in the selection
		t := v.Buffer().Substr(r)
		t = strings.Replace(t, "\r", "\n", -1)
		slice := strings.Split(t, "\n")
		t = ""
		for j, s := range slice {
			if j == 0 {
				t += s
				continue
			}
			t += " " + strings.TrimLeft(s, " \t")
		}
		v.Replace(e, r, t)
		// Removing the first new line after selection
		liner := v.Buffer().FullLine(r.End())
		line := v.Buffer().Substr(liner)
		line = strings.Replace(line, "\n", "", -1)
		line = strings.Replace(line, "\r", "", -1)
		line = strings.TrimRight(line, " \t")
		// Triming the line after
		nextline := liner.End() + 1
		nextliner := v.Buffer().FullLine(nextline)
		nline := v.Buffer().Substr(nextliner)
		if nline != "" {
			v.Replace(e, nextliner, " "+strings.TrimLeft(nline, " \t"))
		}
		v.Replace(e, liner, line)
	}

	return nil
}
开发者ID:gbbr,项目名称:textmate,代码行数:35,代码来源:line.go

示例11: parseUpdateBody

func parseUpdateBody(body string) (title, text, colstr string) {
	body = strings.TrimLeft(body, "\n")
	v := strings.SplitN(body, "\n", 2)
	if len(v) <= 0 {
		return "", "", ""
	}
	title = v[0]
	if len(v) < 2 {
		return title, "", ""
	}

	if strings.HasPrefix(v[1], TEXT_COLS_SEPARATOR[1:]) {
		text = ""
		colstr = v[1][len(TEXT_COLS_SEPARATOR[1:]):]
		return
	}

	v = strings.SplitN(v[1], TEXT_COLS_SEPARATOR, 2)
	if len(v) <= 0 {
		return title, "", ""
	}
	text = strings.TrimLeft(strings.TrimRight(v[0], "\n"), "\n")
	colstr = ""
	if len(v) > 1 {
		colstr = v[1]
	}
	return
}
开发者ID:aarzilli,项目名称:pooch,代码行数:28,代码来源:nfront.go

示例12: newRequest

func newRequest(method, url1 string, body io.Reader) (req *http.Request, err error) {

	var host string

	// url1 = "-H <Host> http://<ip>[:<port>]/<path>"
	//
	if strings.HasPrefix(url1, "-H") {
		url2 := strings.TrimLeft(url1[2:], " \t")
		pos := strings.Index(url2, " ")
		if pos <= 0 {
			return nil, ErrInvalidRequestURL
		}
		host = url2[:pos]
		url1 = strings.TrimLeft(url2[pos+1:], " \t")
	}

	req, err = http.NewRequest(method, url1, body)
	if err != nil {
		return
	}
	if host != "" {
		req.Host = host
	}
	return
}
开发者ID:crazygit,项目名称:qiniu-manager,代码行数:25,代码来源:rpc_client.go

示例13: update

func (fs *workerFS) update(attrs []*attr.FileAttr) {
	updates := map[string]*termitefs.Result{}
	for _, attr := range attrs {
		path := strings.TrimLeft(attr.Path, "/")
		if !strings.HasPrefix(path, fs.fuseFS.writableRoot) {
			dir, name := filepath.Split(path)

			// As file contents are immutable, we must
			// invalidate the entry instead
			fs.fuseFS.rpcNodeFS.EntryNotify(filepath.Join(fs.id, dir), name)
			continue
		}
		path = strings.TrimLeft(path[len(fs.fuseFS.writableRoot):], "/")

		if attr.Deletion() {
			updates[path] = &termitefs.Result{}
		} else {
			r := termitefs.Result{
				Original: "",
				Backing:  "",
				Link:     attr.Link,
				Attr:     &fuse.Attr{},
			}
			a := *attr.Attr
			r.Attr = &a
			updates[path] = &r
		}
	}
	fs.unionFs.Update(updates)
}
开发者ID:hanwen,项目名称:termite,代码行数:30,代码来源:fuse.go

示例14: policys

func (a *Api) policys(w http.ResponseWriter, r *http.Request) {
	w.Header().Set("content-type", "application/json")

	policies, err := a.store.List(pathPolicy)
	if err != nil {
		http.Error(w, err.Error(), http.StatusInternalServerError)
		return
	}
	var data = map[string]string{}
	for _, policy := range policies {
		peer := strings.Split(policy.Key, "/")
		parts := strings.Split(peer[len(peer)-1], ":")
		pInfo, qInfo, err := a.parsePolicy(parts)
		if err != nil {
			log.Errorf(err.Error())
			continue
		}
		key := strings.Join([]string{
			strings.TrimLeft(pInfo.Name, "/"),
			strings.TrimLeft(qInfo.Name, "/")}, ":")
		data[key] = string(policy.Value)
	}
	if err := json.NewEncoder(w).Encode(data); err != nil {
		http.Error(w, err.Error(), http.StatusInternalServerError)
		return
	}
}
开发者ID:wwenxiang,项目名称:daolinet,代码行数:27,代码来源:networks.go

示例15: update

func (me *workerFuseFs) update(attrs []*attr.FileAttr) {
	updates := map[string]*fs.Result{}
	for _, attr := range attrs {
		path := strings.TrimLeft(attr.Path, "/")
		if !strings.HasPrefix(path, me.writableRoot) {
			me.rpcNodeFs.Notify(path)
			continue
		}
		path = strings.TrimLeft(path[len(me.writableRoot):], "/")

		if attr.Deletion() {
			updates[path] = &fs.Result{}
		} else {
			r := fs.Result{
				Original: "",
				Backing:  "",
				Link:     attr.Link,
				Attr:     &fuse.Attr{},
			}
			a := *attr.Attr
			r.Attr = &a
			updates[path] = &r
		}
	}
	me.unionFs.Update(updates)
}
开发者ID:janneke,项目名称:termite,代码行数:26,代码来源:fuse.go


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