本文整理汇总了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)
}
示例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
}
示例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)
}
示例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
}
示例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
}
示例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)
}
}
示例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
}
示例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 ""
}
示例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)
}
}
示例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
}
示例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)
}
示例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
}
示例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]
}
}
}
示例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.
}
示例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
}