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

在下文中一共展示了Replace函数的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: Render

// Render a JSON response.
func (j JSON) Render(ctx *fasthttp.RequestCtx, v interface{}) error {
    if j.StreamingJSON {
        return j.renderStreamingJSON(ctx, v)
    }

    var result []byte
    var err error

    if j.Indent {
        result, err = json.MarshalIndent(v, "", "  ")
        result = append(result, '\n')
    } else {
        result, err = json.Marshal(v)
    }
    if err != nil {
        return err
    }

    // Unescape HTML if needed.
    if j.UnEscapeHTML {
        result = bytes.Replace(result, []byte("\\u003c"), []byte("<"), -1)
        result = bytes.Replace(result, []byte("\\u003e"), []byte(">"), -1)
        result = bytes.Replace(result, []byte("\\u0026"), []byte("&"), -1)
    }
    w := ctx.Response.BodyWriter()
    // JSON marshaled fine, write out the result.
    j.Head.Write(ctx)
    if len(j.Prefix) > 0 {
        w.Write(j.Prefix)
    }
    w.Write(result)
    return nil
}

开发者ID:Carbyn,项目名称:iris,代码行数:34,代码来源:engine.go

示例3: doTerrainMap

func (fieldContext *FieldContextDef) doTerrainMap(websocketConnectionContext *websocketConnectionContextDef) *gkerr.GkErrDef {

    var gkErr *gkerr.GkErrDef

    var singleSession *ses.SingleSessionDef
    singleSession = fieldContext.sessionContext.GetSessionFromId(websocketConnectionContext.sessionId)

    var messageToClient *message.MessageToClientDef = new(message.MessageToClientDef)
    messageToClient.Command = message.SetTerrainMapReq
    var jsonFileName string = fieldContext.terrainSvgDir + string(os.PathSeparator) + "map_terrain_" + strconv.FormatInt(int64(singleSession.GetCurrentPodId()), 10) + ".json"
    messageToClient.JsonData, gkErr = gkcommon.GetFileContents(jsonFileName)
    if gkErr != nil {
        return gkErr
    }
    var lf []byte = []byte("\n")
    var tb []byte = []byte("\t")
    var sp []byte = []byte(" ")
    var nl []byte = []byte("")
    var te []byte = []byte("errain")
    var bj []byte = []byte("bject")
    //  Not typos

    messageToClient.JsonData = bytes.Replace(messageToClient.JsonData, lf, nl, -1)
    messageToClient.JsonData = bytes.Replace(messageToClient.JsonData, sp, nl, -1)
    messageToClient.JsonData = bytes.Replace(messageToClient.JsonData, tb, nl, -1)
    messageToClient.JsonData = bytes.Replace(messageToClient.JsonData, te, nl, -1)
    messageToClient.JsonData = bytes.Replace(messageToClient.JsonData, bj, nl, -1)
    fieldContext.queueMessageToClient(websocketConnectionContext.sessionId, messageToClient)

    return nil
}

开发者ID:gk-turnip,项目名称:server,代码行数:31,代码来源:fieldContext.go

示例4: ExampleReplace

func ExampleReplace() {
    fmt.Printf("%s\n", bytes.Replace([]byte("oink oink oink"), []byte("k"), []byte("ky"), 2))
    fmt.Printf("%s\n", bytes.Replace([]byte("oink oink oink"), []byte("oink"), []byte("moo"), -1))
    // Output:
    // oinky oinky oink
    // moo moo moo
}

开发者ID:achanda,项目名称:go,代码行数:7,代码来源:example_test.go

示例5: CountPinterestPins

func CountPinterestPins(r *Request) *Result {
    var (
        resp    *http.Response
        err     error
        feed    pinterestFeed
        body    []byte
        feedUrl = fmt.Sprintf(pinterestFeedUrl, r.Url())
    )

    if resp, err = http.Get(feedUrl); err != nil {
        return Empty
    }
    if body, err = ioutil.ReadAll(resp.Body); err != nil {
        return Empty
    }

    body = bytes.Replace(body, []byte("receiveCount("), nil, 1)
    body = bytes.Replace(body, []byte(")"), nil, 1)

    if err = json.Unmarshal([]byte(body), &feed); err != nil {
        return Empty
    }

    return &Result{Points: feed.Count}
}

开发者ID:nu7hatch,项目名称:egoistat,代码行数:25,代码来源:count_pinterest_pins.go

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