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


Golang regexp.MustCompilePOSIX函数代码示例

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


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

示例1: writePullRequestChanges

func writePullRequestChanges(repo *github.Repo, messageFile string) error {
	message := `
# Requesting a pull to %s from %s
#
# Write a message for this pull request. The first block
# of the text is the title and the rest is description.%s
`
	startRegexp := regexp.MustCompilePOSIX("^")
	endRegexp := regexp.MustCompilePOSIX(" +$")

	commitLogs, _ := git.Log(repo.Base, repo.Head)
	var changesMsg string
	if len(commitLogs) > 0 {
		commitLogs = strings.TrimSpace(commitLogs)
		commitLogs = startRegexp.ReplaceAllString(commitLogs, "# ")
		commitLogs = endRegexp.ReplaceAllString(commitLogs, "")
		changesMsg = `
#
# Changes:
#
%s`
		changesMsg = fmt.Sprintf(changesMsg, commitLogs)
	}

	message = fmt.Sprintf(message, repo.FullBase(), repo.FullHead(), changesMsg)

	return ioutil.WriteFile(messageFile, []byte(message), 0644)
}
开发者ID:johnbellone,项目名称:gh,代码行数:28,代码来源:pull_request.go

示例2: FormattedCommitLogs

func (p *pullRequestMsg) FormattedCommitLogs() string {
	startRegexp := regexp.MustCompilePOSIX("^")
	endRegexp := regexp.MustCompilePOSIX(" +$")

	commitLogs := strings.TrimSpace(p.CommitLogs)
	commitLogs = startRegexp.ReplaceAllString(commitLogs, fmt.Sprintf("%s ", p.CS))
	commitLogs = endRegexp.ReplaceAllString(commitLogs, "")

	return commitLogs
}
开发者ID:github,项目名称:hub,代码行数:10,代码来源:pull_request_tpl.go

示例3: Generate

func (g *HttpJsonLibGenerator) Generate() ([]byte, error) {
	clientAPI, err := g.generateAPI()
	if err != nil {
		return nil, err
	}

	result := regexp.MustCompilePOSIX(">>>API_NAME<<<").ReplaceAll(mainTemplate, []byte(GetAPIName(g.serviceName)))
	result = regexp.MustCompilePOSIX(">>>PKG_NAME<<<").ReplaceAll(result, []byte(g.pkgName))
	result = regexp.MustCompilePOSIX(">>>CLIENT_API<<<").ReplaceAll(result, clientAPI)
	result = regexp.MustCompilePOSIX(">>>IMPORTS<<<").ReplaceAll(result, g.collectImports())

	return format.Source(result)
}
开发者ID:wtertius,项目名称:gorpc,代码行数:13,代码来源:generator.go

示例4: FindDirectoryURL

// Search search engines
func FindDirectoryURL() (string, error) {
	ch := make(chan string, 100)
	fetch_and_parse := func(url string) {
		s2w := make([]byte, 1)
		rand.Reader.Read(s2w)
		for i := 0; i < int(s2w[0])%4; i++ {
			time.Sleep(time.Second)
		}
		resp, err := http.Get(url)
		if err != nil {
			return
		}
		defer func() {
			if r := recover(); r != nil {
			}
		}()
		defer resp.Body.Close()
		thing := new(bytes.Buffer)
		io.Copy(thing, resp.Body)
		tosearch := string(thing.Bytes())
		rge := regexp.MustCompilePOSIX("Kids in rectangles irritating sick urchins rattling foxes,.*lol")
		str := rge.FindString(tosearch)
		arr := strings.Split(str, " ")
		res := arr[len(arr)-2]
		buf := new(bytes.Buffer)
		buf.WriteString("https://")
		buf.WriteString(res)
		buf.WriteString("/")
		ch <- buf.String()
	}
	go fetch_and_parse("https://stackoverflow.com/users/2022968/user54609")
	go fetch_and_parse("https://pastee.org/q2ndr")
	return <-ch, nil
}
开发者ID:quantum1423-dustbin,项目名称:kirisurf-legacy,代码行数:35,代码来源:libkiridir.go

示例5: ValidateParameters

// ValidateParameters *must* be implemented by a module. It provides a method
// to verify that the parameters passed to the module conform the expected format.
// It must return an error if the parameters do not validate.
func (r Runner) ValidateParameters() (err error) {
	fqdn := regexp.MustCompilePOSIX(`^([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]{0,61}[a-zA-Z0-9])(\.([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]{0,61}[a-zA-Z0-9]))*$`)
	if !fqdn.MatchString(r.Parameters.LookupHost) {
		return fmt.Errorf("ValidateParameters: LookupHost parameter is not a valid FQDN.")
	}
	return
}
开发者ID:netantho,项目名称:mig,代码行数:10,代码来源:example.go

示例6: main

func main() {
	log.SetFlags(0)
	log.SetPrefix("gocyclo: ")
	flag.Usage = usage
	flag.Parse()

	if len(*ignore) == 0 {
		ignoreRx = nil
	} else {
		ignoreRx = regexp.MustCompilePOSIX(*ignore)
	}

	args := flag.Args()
	if len(args) == 0 {
		usage()
	}

	stats := analyze(args)
	sort.Sort(byComplexity(stats))
	written := writeStats(os.Stdout, stats)

	if *avg {
		showAverage(stats)
	}

	if *over > 0 && written > 0 {
		os.Exit(1)
	}
}
开发者ID:sigma,项目名称:gocyclo,代码行数:29,代码来源:gocyclo.go

示例7: waitForCmd

func waitForCmd(s *Shell) stateFn {
	timeout := time.After(2 * time.Second)
	r := regexp.MustCompilePOSIX("^(.*?>)?" + regexp.QuoteMeta(s.scmd) + "[[:space:]]*?$[\r\n]*")
	// fmt.Println("waitForCmd: looking for '" + r.String() + "'")
	for {
		select {
		case readout := <-s.cout:
			// fmt.Println("waitForCmd: received '" + readout + "'")
			s.status.stdout = s.status.stdout + readout
			if loc := r.FindStringIndex(s.status.stdout); loc != nil {
				s.status.stdout = s.status.stdout[loc[1]:]
				return waitForEnd(s)
			}
		case readerr := <-s.cerr:
			anErrIndex := &errIndex{
				start: len(s.status.stdout),
				end:   len(s.status.stdout) + len(readerr)}
			s.status.errs = append(s.status.errs, *anErrIndex)
			s.status.stdout = s.status.stdout + readerr
		case _ = <-timeout:
			fmt.Println("waitForCmd: No cmd detected on shell?! '" + s.scmd + "'")
			return nil // should actually Panic
		}
	}
	return nil
}
开发者ID:VonC,项目名称:cmdexec,代码行数:26,代码来源:shell.go

示例8: GetCurrentContainerID

func GetCurrentContainerID() string {
	file, err := os.Open("/proc/self/cgroup")

	if err != nil {
		return ""
	}

	reader := bufio.NewReader(file)
	scanner := bufio.NewScanner(reader)
	scanner.Split(bufio.ScanLines)

	regex := "/docker/([[:alnum:]]{64})$"
	re := regexp.MustCompilePOSIX(regex)

	for scanner.Scan() {
		_, lines, err := bufio.ScanLines([]byte(scanner.Text()), true)
		if err == nil {
			if re.MatchString(string(lines)) {
				submatches := re.FindStringSubmatch(string(lines))
				containerID := submatches[1]

				return containerID
			}
		}
	}

	return ""
}
开发者ID:xenonn,项目名称:docker-gen,代码行数:28,代码来源:context.go

示例9: main

func main() {
	aliases := loadExtAlias()

	pExt := flag.String("ext", "", "Specify the extension. If not specified, extract from filename")

	flag.Parse()

	*pExt = findExtAlias(aliases, removeLeadingDot(*pExt))

	args := flag.Args()
	if len(args) < 1 {
		printUsage()
	}

	pat := flag.Arg(0)
	fns := villa.Paths(args[1:]...)

	re := regexp.MustCompilePOSIX(pat)

	if len(fns) > 0 {
		for _, fn := range fns {
			ext := *pExt
			if ext == "" {
				ext = findExtAlias(aliases, removeLeadingDot(fn.Ext()))
			}

			grep.Grep(re, fn, ext)
		}
	} else {
		grep.Grep(re, "", *pExt)
	}
}
开发者ID:postfix,项目名称:sgrep,代码行数:32,代码来源:sgrep.go

示例10: GetThreadHashHTML

func GetThreadHashHTML(file string) (thread string) {
	exp := regexp.MustCompilePOSIX(`thread-([0-9a-f]+)\.html`)
	matches := exp.FindStringSubmatch(file)
	if len(matches) != 2 {
		return ""
	}
	thread = matches[1]
	return
}
开发者ID:ZiRo-,项目名称:srndv2,代码行数:9,代码来源:cache.go

示例11: printDatagram

func printDatagram(out *color.Color, d *protocol.Datagram) {
	re := regexp.MustCompilePOSIX("^00000")

	out.Printf("FROM: %s\n", d.From)
	out.Printf("SIZE: %d\n", len(d.Data))
	data := strings.TrimLeft(hex.Dump(d.Data), "0")
	out.Printf("DATA: 000" + re.ReplaceAllString(data, "      "))
	color.Set(color.Bold)
}
开发者ID:wpsteak,项目名称:go-lifx,代码行数:9,代码来源:lifx-snoop.go

示例12: GetGroupForCatalogHTML

func GetGroupForCatalogHTML(file string) (group string) {
	exp := regexp.MustCompilePOSIX(`catalog-(.+)\.html`)
	matches := exp.FindStringSubmatch(file)
	if len(matches) != 2 {
		return ""
	}
	group = matches[1]
	return
}
开发者ID:ZiRo-,项目名称:srndv2,代码行数:9,代码来源:cache.go

示例13: parseTag

func (f *Field) parseTag(tag string) {
	tag = tag[1:len(tag)] //избавляемся от `
	rxp := regexp.MustCompilePOSIX(`db:\"([a-z0-9\-_]+)\"`)
	name := rxp.FindString(tag)
	if name == "-" {
		return
	}
	f.Name = name[4 : len(name)-1]
	rxp = regexp.MustCompilePOSIX(`id_([a-z0-9]+)`)
	if rxp.MatchString(f.Name) {
		f.Foreign = true
		f.ForeignTable = f.Name[3:]
	}
	rxp = regexp.MustCompilePOSIX(`gen:"([a-z0-9\-_,\'\'\(\)]+)"`)
	gen := rxp.FindString(tag)
	if len(gen) < 6 {
		return
	}
	opts := strings.Split(gen[5:len(gen)-1], ",")
	if len(opts) > 0 {
		f.Type = opts[0]
	}
	for _, opt := range opts {
		if opt == f.Type {
			continue
		}
		switch opt {
		case "autoincrement":
			f.AutoIncrement = true
		case "notnull":
			f.NotNull = true
		case "primary":
			f.Primary = true
		case "unique":
			f.Uniqeu = true
		case "index":
			f.Index = true
		default:
			rxp = regexp.MustCompilePOSIX(`default\(.+\)`)
			def := rxp.FindString(opt)
			f.Default = def[8 : len(def)-1]
		}
	}
}
开发者ID:t0pep0,项目名称:model_maker,代码行数:44,代码来源:main.go

示例14: findSplit

// Tries to find an appropriate point to word wrap line, taking shell escape codes into account.
// (Note that because the escape codes are not visible, we can run past the max length for one of them)
func findSplit(line string, guess int) int {
	if guess >= len(line) {
		return len(line)
	}
	r := regexp.MustCompilePOSIX(fmt.Sprintf(".{%d,%d}(\\x1b[^m]+m)?", guess/2, guess))
	m := r.FindStringIndex(line)
	if m != nil {
		return m[1] // second element in slice is the end index
	}
	return guess // Dunno what to do at this point. It's probably unlikely to happen often though.
}
开发者ID:thought-machine,项目名称:please,代码行数:13,代码来源:logging.go

示例15: pullRequestChangesMessage

func pullRequestChangesMessage(base, head, fullBase, fullHead string, commits []string) (string, error) {
	var defaultMsg, commitSummary string
	if len(commits) == 1 {
		msg, err := git.Show(commits[0])
		if err != nil {
			return "", err
		}
		defaultMsg = fmt.Sprintf("%s\n", msg)
	} else if len(commits) > 1 {
		commitLogs, err := git.Log(base, head)
		if err != nil {
			return "", err
		}

		if len(commitLogs) > 0 {
			startRegexp := regexp.MustCompilePOSIX("^")
			endRegexp := regexp.MustCompilePOSIX(" +$")

			commitLogs = strings.TrimSpace(commitLogs)
			commitLogs = startRegexp.ReplaceAllString(commitLogs, "# ")
			commitLogs = endRegexp.ReplaceAllString(commitLogs, "")
			commitSummary = `
#
# Changes:
#
%s`
			commitSummary = fmt.Sprintf(commitSummary, commitLogs)
		}
	}

	message := `%s
# Requesting a pull to %s from %s
#
# Write a message for this pull request. The first block
# of the text is the title and the rest is description.%s
`
	message = fmt.Sprintf(message, defaultMsg, fullBase, fullHead, commitSummary)

	return message, nil
}
开发者ID:proch04,项目名称:gh,代码行数:40,代码来源:pull_request.go


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