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

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

示例1: ExampleTrimPrefix

func ExampleTrimPrefix() {
    var b = []byte("Goodbye,, world!")
    b = bytes.TrimPrefix(b, []byte("Goodbye,"))
    b = bytes.TrimPrefix(b, []byte("See ya,"))
    fmt.Printf("Hello%s", b)
    // Output: Hello, world!
}

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

示例2: ReadHeader

// CommitV000
// TreeV000
// XAttrSetV000
func ReadHeader(p *bytes.Buffer) (header *Header, err error) {
    header = &Header{}
    prefix := p.Next(4)
    var version []byte
    if bytes.Equal(prefix, []byte("Comm")) {
        header.Data = append(prefix, p.Next(6)...)
        header.Type = BLOB_TYPE_COMMIT
        version = bytes.TrimPrefix(header.Data, []byte("CommitV"))
    } else if bytes.Equal(prefix, []byte("Tree")) {
        header.Data = append(prefix, p.Next(4)...)
        header.Type = BLOB_TYPE_TREE
        version = bytes.TrimPrefix(header.Data, []byte("TreeV"))
    } else if bytes.Equal(prefix, []byte("XAtt")) {
        header.Data = append(prefix, p.Next(8)...)
        header.Type = BLOB_TYPE_X_ATTR_SET
        version = bytes.TrimPrefix(header.Data, []byte("XAttrSetV"))
    } else {
        err = errors.New(fmt.Sprintf("ReadHeader header %s has unknown type", header.Data))
        return
    }
    if header.Version, err = strconv.Atoi(string(version)); err != nil {
        err = errors.New(fmt.Sprintf("ReadHeader header %s has non-integer version", header.Data))
        return
    }
    return
}

开发者ID:asimihsan,项目名称:arqinator,代码行数:29,代码来源:header.go

示例3: detectLicense

func detectLicense(filepath string) (LicenseType, error) {
    fh, err := os.Open(filepath)
    if err != nil {
        return UNKNOWN, err
    }
    defer fh.Close()

    var buf bytes.Buffer
    scanner := bufio.NewScanner(fh)
    for scanner.Scan() {
        if bytes.HasPrefix(scanner.Bytes(), []byte("package ")) {
            break
        }
        line := bytes.TrimSuffix(bytes.TrimPrefix(bytes.TrimPrefix(scanner.Bytes(),
            []byte("//")), []byte("/*")), []byte("*/"))
        if len(line) > 0 && (line[0] == '+' || bytes.HasPrefix(bytes.TrimSpace(line), []byte("Copyright"))) {
            continue
        }
        buf.Write(bytes.TrimSpace(line))
        buf.WriteByte('\n')
    }
    //fmt.Fprintf(os.Stderr, "DETECT %q\n", strings.TrimSpace(buf.String()))
    l := license.New("", strings.TrimSpace(buf.String()))
    l.File = filepath
    if err = l.GuessType(); err != nil {
        if err.Error() == license.ErrUnrecognizedLicense {
            return UNKNOWN, scanner.Err()
        }
        return UNKNOWN, err
    }

    err = scanner.Err()
    switch l.Type {
    case license.LicenseMIT:
        return MIT, err
    case license.LicenseNewBSD:
        return NewBSD, err
    case license.LicenseFreeBSD:
        return Freebsd, err
    case license.LicenseApache20:
        return Apache2, err
    case license.LicenseMPL20:
        return MPL2, err
    case license.LicenseGPL20:
        return GPL2, err
    case license.LicenseGPL30:
        return GPL3, err
    case license.LicenseLGPL21:
        return LGPL2, err
    case license.LicenseLGPL30:
        return LGPL2, err
    case license.LicenseCDDL10:
        return CDDL, err
    case license.LicenseEPL10:
        return EPL, err
    }
    return UNKNOWN, err
}

开发者ID:tgulacsi,项目名称:licentia,代码行数:58,代码来源:licentia.go

示例4: DetectCode

func DetectCode(first, second Line, detectors Detectors) Handler {
    if !first.hasFourSpacePrefix() {
        return nil
    }
    block := md.CodeBlock{}
    var paused *Line
    return HandlerFunc(func(next Line, ctx Context) (bool, error) {
        if next.EOF() {
            ctx.Emit(block)
            ctx.Emit(md.End{})
            return maybeNull(paused, ctx)
        }
        // TODO(akavel): verify it's coded ok, it was converted from a different approach
        fourspace := []byte("    ")
        switch {
        // previous was blank, next is not tab-indented. Reject both.
        case paused != nil && !next.hasFourSpacePrefix():
            ctx.Emit(block)
            ctx.Emit(md.End{})
            return maybeNull(paused, ctx)
        case next.isBlank():
            if paused != nil {
                block.Raw = append(block.Raw, md.Run(*paused))
                block.Prose = append(block.Prose, md.Run{
                    paused.Line, bytes.TrimPrefix(paused.Bytes, fourspace)})
            }
            paused = &next // note: only case where we pause a line
            return true, nil
        case next.hasFourSpacePrefix():
            if paused != nil {
                block.Raw = append(block.Raw, md.Run(*paused))
                block.Prose = append(block.Prose, md.Run{
                    paused.Line, bytes.TrimPrefix(paused.Bytes, fourspace)})
                paused = nil
            }
            block.Raw = append(block.Raw, md.Run(next))
            block.Prose = append(block.Prose, md.Run{
                next.Line, bytes.TrimPrefix(next.Bytes, fourspace)})
            return true, nil
        // next not blank & not indented. End the block.
        default:
            if paused != nil {
                block.Raw = append(block.Raw, md.Run(*paused))
                block.Prose = append(block.Prose, md.Run{
                    paused.Line, bytes.TrimPrefix(paused.Bytes, fourspace)})
            }
            ctx.Emit(block)
            ctx.Emit(md.End{})
            return false, nil
        }
    })
}

开发者ID:akavel,项目名称:vfmd,代码行数:52,代码来源:code.go

示例5: TrimBOM

func TrimBOM(b []byte, encoding string) []byte {
    bom := boms[encoding]
    if bom != nil {
        b = bytes.TrimPrefix(b, bom)
    }
    return b
}

开发者ID:fanyang01,项目名称:crawler,代码行数:7,代码来源:util.go

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