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

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

示例1: RenderSpecialLink

func RenderSpecialLink(rawBytes []byte, urlPrefix string) []byte {
    ms := MentionPattern.FindAll(rawBytes, -1)
    for _, m := range ms {
        rawBytes = bytes.Replace(rawBytes, m,
            []byte(fmt.Sprintf(`<a href="/user/%s">%s</a>`, m[1:], m)), -1)
    }
    ms = commitPattern.FindAll(rawBytes, -1)
    for _, m := range ms {
        m = bytes.TrimSpace(m)
        i := strings.Index(string(m), "commit/")
        j := strings.Index(string(m), "#")
        if j == -1 {
            j = len(m)
        }
        rawBytes = bytes.Replace(rawBytes, m, []byte(fmt.Sprintf(
            ` <code><a href="%s">%s</a></code>`, m, ShortSha(string(m[i+7:j])))), -1)
    }
    ms = issueFullPattern.FindAll(rawBytes, -1)
    for _, m := range ms {
        m = bytes.TrimSpace(m)
        i := strings.Index(string(m), "issues/")
        j := strings.Index(string(m), "#")
        if j == -1 {
            j = len(m)
        }
        rawBytes = bytes.Replace(rawBytes, m, []byte(fmt.Sprintf(
            ` <a href="%s">#%s</a>`, m, ShortSha(string(m[i+7:j])))), -1)
    }
    ms = issueIndexPattern.FindAll(rawBytes, -1)
    for _, m := range ms {
        rawBytes = bytes.Replace(rawBytes, m, []byte(fmt.Sprintf(
            `<a href="%s/issues/%s">%s</a>`, urlPrefix, m[1:], m)), -1)
    }
    return rawBytes
}

开发者ID:Julianzz,项目名称:gogs,代码行数:35,代码来源:markdown.go

示例2: create

func create() error {
    pemBytes, err := ioutil.ReadFile(*pem)
    if err != nil {
        return fmt.Errorf("reading -pem key failed: %s", err)
    }

    pubBytes, err := ioutil.ReadFile(*pub)
    if err != nil {
        return fmt.Errorf("reading -pub key failed: %s", err)
    }

    if *id == "" {
        *id = uuid.NewV4().String()
    }

    k := &keycreator.Key{
        KontrolURL:        *kontrolURL,
        KontrolPrivateKey: string(bytes.TrimSpace(pemBytes)),
        KontrolPublicKey:  string(bytes.TrimSpace(pubBytes)),
    }

    kiteKey, err := k.Create(*username, *id)
    if err != nil {
        return fmt.Errorf("signing failed: %s", err)
    }

    if *file == "" {
        fmt.Println(kiteKey)
        return nil
    }

    return ioutil.WriteFile(*file, bytes.TrimSpace([]byte(kiteKey)), 0644)
}

开发者ID:koding,项目名称:koding,代码行数:33,代码来源:main.go

示例3: CommentHtml

func (options *xml2) CommentHtml(out *bytes.Buffer, text []byte) {
    i := bytes.Index(text, []byte("-->"))
    if i > 0 {
        text = text[:i]
    }
    // strip, <!--
    text = text[4:]

    var source []byte
    l := len(text)
    if l > 20 {
        l = 20
    }
    for i := 0; i < l; i++ {
        if text[i] == '-' && text[i+1] == '-' {
            source = text[:i]
            text = text[i+2:]
            break
        }
    }
    // don't output a cref if it is not name -- remark
    if len(source) != 0 {
        source = bytes.TrimSpace(source)
        text = bytes.TrimSpace(text)
        out.WriteString("<t><cref source=\"")
        out.Write(source)
        out.WriteString("\">")
        out.Write(text)
        out.WriteString("</cref></t>\n")
    }
    return
}

开发者ID:paulej,项目名称:mmark,代码行数:32,代码来源:xml2rfcv2.go

示例4: FileGetConfig

func FileGetConfig(filenameOrURL string, timeout ...time.Duration) (map[string]string, error) {
    data, err := FileGetBytes(filenameOrURL, timeout...)
    if err != nil {
        return nil, err
    }

    lines := bytes.Split(data, []byte("\n"))
    config := make(map[string]string, len(lines))
    for _, line := range lines {
        kv := bytes.SplitN(line, []byte("="), 2)
        if len(kv) < 2 {
            continue
        }
        key := string(bytes.TrimSpace(kv[0]))
        if len(key) == 0 || key[0] == '#' {
            continue
        }
        value := string(bytes.TrimSpace(kv[1]))
        if len(value) >= 2 && value[0] == '"' && value[len(value)-1] == '"' {
            value = value[1 : len(value)-1]
        }
        config[key] = value
    }

    return config, nil
}

开发者ID:vincecima,项目名称:just-install,代码行数:26,代码来源:file.go

示例5: AutoLink

func (r *CustomRender) AutoLink(out *bytes.Buffer, link []byte, kind int) {
    if kind != 1 {
        r.Renderer.AutoLink(out, link, kind)
        return
    }

    // This method could only possibly serve one link at a time, no need to find all.
    m := commitPattern.Find(link)
    if m != nil {
        m = bytes.TrimSpace(m)
        i := strings.Index(string(m), "commit/")
        j := strings.Index(string(m), "#")
        if j == -1 {
            j = len(m)
        }
        out.WriteString(fmt.Sprintf(` <code><a href="%s">%s</a></code>`, m, ShortSha(string(m[i+7:j]))))
        return
    }

    m = issueFullPattern.Find(link)
    if m != nil {
        m = bytes.TrimSpace(m)
        i := strings.Index(string(m), "issues/")
        j := strings.Index(string(m), "#")
        if j == -1 {
            j = len(m)
        }
        out.WriteString(fmt.Sprintf(` <a href="%s">#%s</a>`, m, ShortSha(string(m[i+7:j]))))
        return
    }

    r.Renderer.AutoLink(out, link, kind)
}

开发者ID:MaximeFrancoeur,项目名称:gogs,代码行数:33,代码来源:markdown.go

最后编辑: kuteng  文档更新时间: 2021-08-23 19:14   作者:kuteng