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

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

示例1: lineDiff

// lineDiff returns b with all lines added or changed from a highlighted.
// It discards spaces within lines when comparing lines, so subtle
// gofmt-induced alignment changes are not flagged as changes.
// It also handles single-line diffs specially, highlighting only the
// changes within those lines.
func lineDiff(a, b []byte) []byte {
    l := byteLines{bytes.Split(a, []byte("\n")), bytes.Split(b, []byte("\n"))}
    cs := diff.Diff(len(l.a), len(l.b), diff.Data(l))

    var buf bytes.Buffer
    n := 0
    for _, c := range cs {
        for _, b := range l.b[n:c.B] {
            buf.Write(b)
            buf.WriteByte('\n')
        }
        if c.Ins > 0 {
            if c.Ins == 1 && c.Del == 1 {
                buf.Write(byteDiff(l.a[c.A], l.b[c.B]))
                buf.WriteByte('\n')
            } else {
                for _, b := range l.b[c.B : c.B+c.Ins] {
                    buf.Write(colorize(b))
                    buf.WriteByte('\n')
                }
            }
        }
        n = c.B + c.Ins
    }
    for i, b := range l.b[n:] {
        if i > 0 {
            buf.WriteByte('\n')
        }
        buf.Write(b)
    }
    return buf.Bytes()
}

开发者ID:adg,项目名称:dt,代码行数:37,代码来源:dt.go

示例2: runDatCase

func runDatCase(c []byte) int {
    var counter int
    defer func() {
        if e := recover(); e != nil {
            fmt.Println("ERROR while running test case:", e)
            counter++
        }
    }()
    parts := bytes.Split(c, []byte("#"))
    if len(parts) != 4 {
        counter++
    }
    if len(parts) != 4 && *verbose {
        fmt.Printf("Malformed test case: %d, %q\n", len(parts), string(c))
        return counter
    }
    fmt.Println("Running test case:", string(c))
    testData := make(map[string]string)
    for _, p := range parts[1:] {
        t := bytes.Split(p, []byte("\n"))
        testData[string(t[0])] = string(t[1])
    }
    p := h5.NewParserFromString(string(testData["data"]))
    err := p.Parse()
    if err != nil {
        fmt.Println("Test case:", string(c))
        fmt.Println("ERROR parsing: ", err)
        counter++
    } else {
        if *verbose {
            fmt.Println("SUCCESS!!!")
        }
    }
    return counter
}

开发者ID:wjdix,项目名称:go-price-fetcher,代码行数:35,代码来源:acceptance.go

示例3: LoadMap

func LoadMap() error {
    contents, err := ioutil.ReadFile(fileMapPath)
    if err != nil {
        return fmt.Errorf("Could not read file %s: %s", fileMapPath, err.Error())
    }
    lines := bytes.Split(contents, []byte("\n"))

    newMap := make(map[string]string)
    for i, line := range lines {
        lineParts := bytes.Split(bytes.TrimSpace(line), []byte(" "))
        if len(lineParts[0]) == 0 {
            continue
        }

        user := string(lineParts[:1][0])
        host := string(lineParts[len(lineParts)-1:][0])

        if _, alreadyExists := newMap[user]; alreadyExists {
            return fmt.Errorf("User %s was defined more than once on line %d", user, i)
        }

        newMap[user] = host
    }

    if len(newMap) < minEntries {
        return fmt.Errorf("New Map only contains %d entries, which is less than the set minimum %d",
            len(newMap), minEntries)
    }

    fileMapLock.Lock()
    defer fileMapLock.Unlock()
    fileMap = newMap

    return nil
}

开发者ID:Freeaqingme,项目名称:SshReverseProxy,代码行数:35,代码来源:file.go

示例4: Parse

func (fl *FriendsList) Parse(buf []byte) (f map[string]string, err error) {
    f = make(map[string]string)
    for _, l := range bytes.Split(buf, []byte("\n")) {
        if len(l) < 3 {
            continue
        }

        parts := bytes.Split(l, []byte(" "))
        if len(parts) != 2 {
            return f, fmt.Errorf("format error. too many parts. %s", parts)
        }

        user := string(parts[0])
        if len(user) < 1 {
            return f, fmt.Errorf("invalid user: %s", user)
        }

        perm := string(parts[1])
        if !validPerm(perm) {
            return f, fmt.Errorf("invalid perm: %s", perm)
        }
        f[user] = perm
    }

    // ok everything seems good
    return f, nil
}

开发者ID:fczuardi,项目名称:pinbot,代码行数:27,代码来源:friends.go

示例5: loadPerms

func loadPerms(path string) (mperms PermissionsList) {
    file, e := ioutil.ReadFile(path)
    if e != nil {
        fmt.Println("Could not get group permissions for", path, ":", e)
        return
    }
    lines := bytes.Split(file, []byte("\n"), -1)
    mperms = make(PermissionsList, len(lines))
    for i, line := range lines {
        parts := bytes.Split(line, []byte(" "), 2)
        perms := mperms[i]
        for _, perm := range parts[0] {
            switch perm {
            case 'r':
                perms.Read = true
            case 'w':
                perms.Write = true
            default:
                fmt.Println("WARNING: Unrecognized permission", perm)
            }
            perms.Path = string(parts[1])
            mperms[i] = perms
        }
    }
    sort.Sort(mperms)
    if !sort.IsSorted(mperms) {
        fmt.Println("Failed to sort!")
    }
    return
}

开发者ID:wcspromoteam,项目名称:perms,代码行数:30,代码来源:perms.go

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