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

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

示例1: consumeParam

func consumeParam(v []byte) (param, value, rest []byte) {
    param, rest = consumeToken(v)
    param = bytes.ToLower(param)
    if param == nil {
        return nil, nil, v
    }

    rest = bytes.TrimLeftFunc(rest, unicode.IsSpace)
    if len(rest) == 0 || rest[0] != '=' {
        return nil, nil, v
    }
    rest = rest[1:] // consume equals sign
    rest = bytes.TrimLeftFunc(rest, unicode.IsSpace)
    if len(rest) == 0 {
        return nil, nil, v
    }
    if rest[0] != '"' {
        value, rest = consumeToken(rest)
    } else {
        value, rest = consumeValue(rest)
    }
    if value == nil {
        return nil, nil, v
    }
    return param, value, rest
}

开发者ID:gitter-badger,项目名称:alkasir,代码行数:26,代码来源:link.go

示例2: Parse

// Parse parses a Link header value into a slice of Links. It does not currently
// implement RFC 2231 handling of non-ASCII character encoding and language
// information.
func Parse(l string) ([]Link, error) {
    v := []byte(l)
    v = bytes.TrimSpace(v)
    if len(v) == 0 {
        return nil, nil
    }

    links := make([]Link, 0, 1)
    for len(v) > 0 {
        if v[0] != '<' {
            return nil, errors.New("link: does not start with <")
        }
        lend := bytes.IndexByte(v, '>')
        if lend == -1 {
            return nil, errors.New("link: does not contain ending >")
        }

        params := make(map[string]string)
        link := Link{URI: string(v[1:lend]), Params: params}
        links = append(links, link)

        // trim off parsed url
        v = v[lend+1:]
        if len(v) == 0 {
            break
        }
        v = bytes.TrimLeftFunc(v, unicode.IsSpace)

        for len(v) > 0 {
            if v[0] != ';' && v[0] != ',' {
                return nil, errors.New(`link: expected ";" or "'", got "` + string(v[0:1]) + `"`)
            }
            var next bool
            if v[0] == ',' {
                next = true
            }
            v = bytes.TrimLeftFunc(v[1:], unicode.IsSpace)
            if next || len(v) == 0 {
                break
            }
            var key, value []byte
            key, value, v = consumeParam(v)
            if key == nil || value == nil {
                return nil, errors.New("link: malformed param")
            }
            if k := string(key); k == "rel" {
                if links[len(links)-1].Rel == "" {
                    links[len(links)-1].Rel = string(value)
                }
            } else {
                params[k] = string(value)
            }
            v = bytes.TrimLeftFunc(v, unicode.IsSpace)
        }
    }

    return links, nil
}

开发者ID:gitter-badger,项目名称:alkasir,代码行数:61,代码来源:link.go

示例3: EncodeKey

func EncodeKey(key []byte) string {
    // we do sloppy work and process safe bytes only at the beginning
    // and end; this avoids many false positives in large binary data

    var left, middle, right string

    {
        mid := bytes.TrimLeftFunc(key, isSafe)
        if len(key)-len(mid) > prettyTheshold {
            left = string(key[:len(key)-len(mid)]) + string(FragSeparator)
            key = mid
        }
    }

    {
        mid := bytes.TrimRightFunc(key, isSafe)
        if len(key)-len(mid) > prettyTheshold {
            right = string(FragSeparator) + string(key[len(mid):])
            key = mid
        }
    }

    if len(key) > 0 {
        middle = "@" + hex.EncodeToString(key)
    }

    return strings.Trim(left+middle+right, string(FragSeparator))
}

开发者ID:voidException,项目名称:bazil,代码行数:28,代码来源:util.go

示例4: main

func main() {
    s := []byte("123456789")
    f := func(r rune) bool {
        return r < '4'
    }
    fmt.Println(string(bytes.TrimLeftFunc(s, f)))
}

开发者ID:cwen-coder,项目名称:study-gopkg,代码行数:7,代码来源:TrimLeftFunc.go

示例5: main

func main() {
    whitespace := " \t\r\n"

    padded := []byte("  \t\r\n\r\n\r\n  hello!!!    \t\t\t\t")
    trimmed := bytes.Trim(padded, whitespace)
    log.Printf("Trim removed runes in %q from the ends of %q to produce %q", whitespace, padded, trimmed)

    rhyme := []byte("aabbccddee")
    trimFunced := bytes.TrimFunc(rhyme, trimOdd)
    log.Printf("TrimFunc removed 'odd' runes from %q to produce %q", rhyme, trimFunced)

    leftTrimmed := bytes.TrimLeft(padded, whitespace)
    log.Printf("TrimLeft removed runes in %q from the left side of %q to produce %q", whitespace, padded, leftTrimmed)

    leftTrimFunced := bytes.TrimLeftFunc(rhyme, trimOdd)
    log.Printf("TrimLeftFunc removed 'odd' runes from the left side of %q to produce %q", rhyme, leftTrimFunced)

    rightTrimmed := bytes.TrimRight(padded, whitespace)
    log.Printf("TrimRight removed runes in %q from the right side of %q to produce %q", whitespace, padded, rightTrimmed)

    rightTrimFunced := bytes.TrimRightFunc(rhyme, trimOdd)
    log.Printf("TrimRightFunc removed 'odd' runes from the right side of %q to produce %q", rhyme, rightTrimFunced)

    spaceTrimmed := bytes.TrimSpace(padded)
    log.Printf("TrimSpace trimmed all whitespace from the ends of %q to produce %q", padded, spaceTrimmed)
}

开发者ID:rif,项目名称:golang-stuff,代码行数:26,代码来源:trimming.go

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