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

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

示例1: forwardMsg

func forwardMsg(msg protocol.Message, node nodes.Nodes, readonly bool) (msgAck protocol.Message) {
    var (
        clusterConnPool connection.Pool
        isMaster        bool
    )
    if readonly {
        clusterConnPool, isMaster = node.GetRandom()
    } else {
        clusterConnPool = node.GetMaster()
        isMaster = true
    }
    msgAck = forwardMsgToPool(msg, clusterConnPool, isMaster, false)
    if msgAck.GetProtocolType() == protocol.ErrorsStringsType {
        var msgAckBytesValueSplit [][]byte = bytes.Fields(msgAck.GetBytesValue())
        if len(msgAckBytesValueSplit) == 3 {
            switch {
            case bytes.EqualFold(msgAckBytesValueSplit[0], MOVED):
                msgAck = forwardMsgToPool(msg, cluster.GetClusterParameter().GetNodePool(string(msgAckBytesValueSplit[2])), true, false)
            case bytes.EqualFold(msgAckBytesValueSplit[0], ASK):
                msgAck = forwardMsgToPool(msg, cluster.GetClusterParameter().GetNodePool(string(msgAckBytesValueSplit[2])), true, true)
            }
        }
    }
    return
}

开发者ID:huangzhiyong,项目名称:carrier,代码行数:25,代码来源:proc.go

示例2: Next

func (a loginAuth) Next(fromServer []byte, more bool) ([]byte, error) {
    if more {
        if bytes.EqualFold([]byte("username:"), fromServer) {
            return []byte(a.username), nil
        } else if bytes.EqualFold([]byte("password:"), fromServer) {
            return []byte(a.password), nil
        }
    }
    return nil, nil
}

开发者ID:liumuqi,项目名称:tommyjarvis,代码行数:10,代码来源:auth.go

示例3: findDownloadURL

func findDownloadURL(relTo url.URL, r io.Reader) (string, error) {
    z := html.NewTokenizer(r)
Outer:
    for {
        tt := z.Next()
        if tt == html.ErrorToken {
            if z.Err() == io.EOF {
                break
            }
            Log.Error("parse page", "error", z.Err())
            return "", z.Err()
        }
        if tt != html.StartTagToken {
            continue
        }
        tn, hasAttr := z.TagName()
        if !(hasAttr && bytes.EqualFold(tn, []byte("input"))) {
            continue
        }
        var onClick string
        for {
            key, val, more := z.TagAttr()
            if bytes.EqualFold(key, []byte("name")) && !bytes.Equal(val, []byte("letolt")) {
                continue Outer
            }
            if bytes.EqualFold(key, []byte("onclick")) {
                onClick = string(val)
                if i := strings.IndexAny(onClick, `'"`); i >= 0 {
                    sep := onClick[i]
                    onClick = onClick[i+1:]
                    if i = strings.LastIndex(onClick, string(sep)); i >= 0 {
                        onClick = onClick[:i]
                    }
                }
                nxt, err := url.Parse(onClick)
                if err != nil {
                    return onClick, err
                }
                relTo := &relTo
                return relTo.ResolveReference(nxt).String(), nil
            }
            if !more {
                break
            }
        }
    }
    return "", errors.New("no download URL found")
}

开发者ID:tgulacsi,项目名称:nav,代码行数:48,代码来源:get.go

示例4: needFullReSync

// if no need full resync, returns false and sync offset
func (h *Handler) needFullReSync(c *conn, args [][]byte) (bool, int64) {
    masterRunID := args[0]

    if !bytes.EqualFold(masterRunID, h.runID) {
        if !bytes.Equal(masterRunID, []byte{'?'}) {
            log.Infof("Partial resynchronization not accepted, runid mismatch, server is %s, but client is %s", h.runID, masterRunID)
        } else {
            log.Infof("Full resync requested by slave.")
        }
        return true, 0
    }

    syncOffset, err := strconv.ParseInt(string(args[1]), 10, 64)
    if err != nil {
        log.Errorf("PSYNC parse sync offset err, try full resync - %s", err)
        return true, 0
    }

    r := &h.repl

    h.repl.RLock()
    defer h.repl.RUnlock()

    if r.backlogBuf == nil || syncOffset < r.backlogOffset ||
        syncOffset > (r.backlogOffset+int64(r.backlogBuf.Len())) {
        log.Infof("unable to partial resync with the slave for lack of backlog, slave offset %d", syncOffset)
        if syncOffset > r.masterOffset {
            log.Infof("slave tried to PSYNC with an offset %d larger than master offset %d", syncOffset, r.masterOffset)
        }

        return true, 0
    }

    return false, syncOffset
}

开发者ID:CowLeo,项目名称:qdb,代码行数:36,代码来源:repl.go

示例5: Resume

func (f *backRefNodeFiber) Resume() (output, error) {
    if f.cnt == 0 {
        f.cnt++

        var b []byte
        if f.node.Index > 0 {
            if r, ok := f.I.sub.i[f.node.Index]; ok {
                b = r.b
            }
        } else if len(f.node.Name) > 0 {
            if r, ok := f.I.sub.n[f.node.Name]; ok {
                b = r.b
            }
        }

        l := len(b)
        if l > len(f.I.b) {
            l = len(f.I.b)
        }
        if f.node.Flags&syntax.FoldCase != 0 && bytes.EqualFold(b, f.I.b[:l]) {
            return output{offset: l}, nil
        } else if bytes.Equal(b, f.I.b[:l]) {
            return output{offset: l}, nil
        }
    }
    return output{}, errDeadFiber
}

开发者ID:flyingtime,项目名称:goback,代码行数:27,代码来源:node.go

示例6: ParseFeed

func ParseFeed(c appengine.Context, contentType, origUrl, fetchUrl string, body []byte) (*Feed, []*Story, error) {
    cr := defaultCharsetReader
    if !bytes.EqualFold(body[:len(xml.Header)], []byte(xml.Header)) {
        enc, err := encodingReader(body, contentType)
        if err != nil {
            return nil, nil, err
        }
        if enc != encoding.Nop {
            cr = nilCharsetReader
            body, err = ioutil.ReadAll(transform.NewReader(bytes.NewReader(body), enc.NewDecoder()))
            if err != nil {
                return nil, nil, err
            }
        }
    }
    var feed *Feed
    var stories []*Story
    var atomerr, rsserr, rdferr error
    feed, stories, atomerr = parseAtom(c, body, cr)
    if feed == nil {
        feed, stories, rsserr = parseRSS(c, body, cr)
    }
    if feed == nil {
        feed, stories, rdferr = parseRDF(c, body, cr)
    }
    if feed == nil {
        c.Warningf("atom parse error: %s", atomerr.Error())
        c.Warningf("xml parse error: %s", rsserr.Error())
        c.Warningf("rdf parse error: %s", rdferr.Error())
        return nil, nil, fmt.Errorf("Could not parse feed data")
    }
    feed.Url = origUrl
    return parseFix(c, feed, stories, fetchUrl)
}

开发者ID:kissthink,项目名称:goread,代码行数:34,代码来源:utils.go

示例7: equalFold

func equalFold(a, b []byte) {
    if bytes.EqualFold(a, b) {
        log.Printf("%s and %s are equal", a, b)
    } else {
        log.Printf("%s and %s are NOT equal", a, b)
    }
}

开发者ID:johnvilsack,项目名称:golang-stuff,代码行数:7,代码来源:comparison.go

示例8: longestMatchingPath

func (lm *LocationMuxer) longestMatchingPath(path string) *types.Location {
    pathAsPrefix := patricia.Prefix(path)
    var matchSoFar patricia.Prefix
    var matchedItem *types.Location
    err := lm.locationTrie.Visit(func(prefix patricia.Prefix, item patricia.Item) error {
        if len(prefix) > len(pathAsPrefix) {
            return patricia.SkipSubtree
        } else if len(prefix) > len(matchSoFar) && bytes.EqualFold(prefix, pathAsPrefix[:len(prefix)]) {
            exactMatch := len(prefix) == len(pathAsPrefix)
            matchedLocation := item.(*types.Location)
            if isLocationType(matchedLocation, exact) && !exactMatch {
                return nil
            }

            matchedItem = matchedLocation
            matchSoFar = prefix
            if exactMatch {
                return errExactMatch // not an error, just so the search is canceled
            }
        }
        return nil
    })

    if err != nil && err != errExactMatch {
        panic(err) // an impossible error
    }

    return matchedItem
}

开发者ID:na–,项目名称:nedomi,代码行数:29,代码来源:location_muxer.go

示例9: TestFoldAgainstUnicode

func TestFoldAgainstUnicode(t *testing.T) {
    const bufSize = 5
    buf1 := make([]byte, 0, bufSize)
    buf2 := make([]byte, 0, bufSize)
    var runes []rune
    for i := 0x20; i <= 0x7f; i++ {
        runes = append(runes, rune(i))
    }
    runes = append(runes, kelvin, smallLongEss)

    funcs := []struct {
        name   string
        fold   func(s, t []byte) bool
        letter bool // must be ASCII letter
        simple bool // must be simple ASCII letter (not 'S' or 'K')
    }{
        {
            name: "equalFoldRight",
            fold: equalFoldRight,
        },
        {
            name:   "asciiEqualFold",
            fold:   asciiEqualFold,
            simple: true,
        },
        {
            name:   "simpleLetterEqualFold",
            fold:   simpleLetterEqualFold,
            simple: true,
            letter: true,
        },
    }

    for _, ff := range funcs {
        for _, r := range runes {
            if r >= utf8.RuneSelf {
                continue
            }
            if ff.letter && !isASCIILetter(byte(r)) {
                continue
            }
            if ff.simple && (r == 's' || r == 'S' || r == 'k' || r == 'K') {
                continue
            }
            for _, r2 := range runes {
                buf1 := append(buf1[:0], 'x')
                buf2 := append(buf2[:0], 'x')
                buf1 = buf1[:1+utf8.EncodeRune(buf1[1:bufSize], r)]
                buf2 = buf2[:1+utf8.EncodeRune(buf2[1:bufSize], r2)]
                buf1 = append(buf1, 'x')
                buf2 = append(buf2, 'x')
                want := bytes.EqualFold(buf1, buf2)
                if got := ff.fold(buf1, buf2); got != want {
                    t.Errorf("%s(%q, %q) = %v; want %v", ff.name, buf1, buf2, got, want)
                }
            }
        }
    }
}

开发者ID:josephlewis42,项目名称:njson,代码行数:59,代码来源:fold_test.go

示例10: Equal

// compare two clients: name and network connection
func (c *ClientChat) Equal(cl *ClientChat) bool {
    if bytes.EqualFold([]byte(c.Name), []byte(cl.Name)) {
        if c.Con == cl.Con {
            return true
        }
    }
    return false
}

开发者ID:kuninl,项目名称:go-irc,代码行数:9,代码来源:server.go

示例11: getBase

func getBase(ctx context.Context, page string, client *http.Client) (string, error) {
    resp, err := client.Get(page)
    if err != nil {
        Log.Error("get start page", "url", page, "error", err)
        return "", err
    }
    defer resp.Body.Close()
    select {
    case <-ctx.Done():
        return "", ctx.Err()
    default:
    }
    z := html.NewTokenizer(resp.Body)
    for {
        tt := z.Next()
        if tt == html.ErrorToken {
            if z.Err() == io.EOF {
                break
            }
            Log.Error("parse page", "error", z.Err())
            return "", z.Err()
        }
        if tt != html.StartTagToken {
            continue
        }
        tn, hasAttr := z.TagName()
        if !(hasAttr && bytes.EqualFold(tn, []byte("iframe"))) {
            continue
        }
        for {
            key, val, more := z.TagAttr()
            if bytes.EqualFold(key, []byte("src")) {
                return string(val), nil
            }
            if !more {
                break
            }
        }
    }
    return "", errgo.Notef(errgo.New("no iframe found"), "page="+page)
}

开发者ID:tgulacsi,项目名称:nav,代码行数:41,代码来源:get.go

示例12: ReadLDIFEntry

func (lr *LDIFReader) ReadLDIFEntry() (LDIFRecord, *Error) {
    if lr.NoMoreEntries {
        return nil, nil
    }
    ldiflines, err := lr.readLDIFEntryIntoSlice()
    if err != nil {
        return nil, err
    }
    if ldiflines == nil {
        return nil, nil
    }

    if bytes.EqualFold(ldiflines[0][0:7], []byte("version")) {
        lr.Version = string(versionRegex.Find(ldiflines[0]))
        return lr.ReadLDIFEntry()
    }
    if bytes.EqualFold(ldiflines[0][0:7], []byte("charset")) {
        lr.Charset = string(charsetRegex.Find(ldiflines[0]))
        return lr.ReadLDIFEntry()
    }
    return sliceToLDIFRecord(ldiflines)
}

开发者ID:xstevens,项目名称:ldap,代码行数:22,代码来源:ldif.go

示例13: clientsender

// clientsender(): read from stdin and send it via network
func clientsender(cn net.Conn) {
    reader := bufio.NewReader(os.Stdin)
    for {
        fmt.Print("you> ")
        input, _ := reader.ReadBytes('\n')
        if bytes.EqualFold(input, []byte("/quit\n")) {
            cn.Write([]byte("/quit"))
            running = false
            break
        }
        Log("clientsender(): send: ", string(input[0:len(input)-1]))
        cn.Write(input[0 : len(input)-1])
    }
}

开发者ID:vax11780,项目名称:go-irc,代码行数:15,代码来源:client.go

示例14: processEventConnection

func processEventConnection(c io.ReadWriteCloser, decodeEvent bool, hander ipcEventHandler) {
    //test connection type
    magicBuf := make([]byte, 4)
    magic, err := readMagicHeader(c, magicBuf)
    if nil != err {
        if err != io.EOF {
            glog.Errorf("Failed to read magic header for error:%v from %v", err, c)
        }
    } else {
        if bytes.Equal(magic, MAGIC_EVENT_HEADER) {
            processSSFEventConnection(c, decodeEvent, hander)
        } else if bytes.EqualFold(magic, MAGIC_OTSC_HEADER) {
            ots.ProcessTroubleShooting(c)
        } else {
            glog.Errorf("Invalid magic header:%s", string(magic))
            c.Close()
        }
    }
}

开发者ID:yinqiwen,项目名称:ssf,代码行数:19,代码来源:server.go

示例15: UnmarshalFromConfig

// UnmarshalFromConfig strores the data in config in the value pointed to by v.
// v must be a pointer to a struct.
//
// UnmarshalFromConfig matches incoming keys to either the struct field name
// or its tag, preferring an exact match but also accepting
// a case-insensitive match.
// Only exported fields can be populated. The tag value "-" is used to skip
// a field.
//
// If the type indicated in the struct field does not match the type in the
// config the field is skipped. Eg. the field type is int but contains a non
// numerical string value in the config data.
func UnmarshalFromConfig(c *Config, v interface{}) error {
    // Check that the type v we will populate is a struct
    rv := reflect.ValueOf(v)
    if rv.Kind() != reflect.Ptr || rv.Elem().Kind() != reflect.Struct {
        return errors.New("cfg: interface must be a pointer to struct")
    }

    // Dereference the pointer if it is one
    rv = rv.Elem()

    // Loop through all fields of the struct
    for i := 0; i < rv.NumField(); i++ {
        fv := rv.Field(i)        // Save the Value of the field
        sf := rv.Type().Field(i) // Save the StructField of the field

        // Check if the field should be skipped
        if sf.PkgPath != "" { // unexported
            continue
        }
        tag := sf.Tag.Get(tagKey)
        if tag == "-" {
            continue
        }

        // Loop through all keys and match them against the field
        // set the value if it matches.
        for key := range c.values {
            // Check so the tag, or the name case insensitive matches, if not
            // go on to the next key
            if key != tag && bytes.EqualFold([]byte(key), []byte(sf.Name)) == false {
                continue
            }

            err := setValue(&fv, c, key)
            if err != nil {
                return fmt.Errorf("cfg: error setting field value: %s", err)
            }
        }
    }

    return nil
}

开发者ID:walle,项目名称:cfg,代码行数:54,代码来源:decode.go

示例16: clientreceiver

// go routine spun up by clientHandling to manage incoming
// client traffic and terminate upon receipt of /quit command from client
// prints out client string data and thens forwards that data
// to the handlingINOUT routine via a channel notifier
func clientreceiver(client *ClientChat) {
    buf := make([]byte, 2048)

    Log("clientreceiver(): start for: ", client.Name)
    for client.Read(buf) {

        if bytes.EqualFold(buf, []byte("/quit")) {
            client.Close()
            break
        }
        Log("clientreceiver(): received from ", client.Name, " (", string(buf), ")")
        send := client.Name + "> " + string(buf)
        client.OUT <- send
        for i := 0; i < 2048; i++ {
            buf[i] = 0x00
        }
    }

    client.OUT <- client.Name + " has left chat"
    Log("clientreceiver(): stop for: ", client.Name)
}

开发者ID:kuninl,项目名称:go-irc,代码行数:25,代码来源:server.go

示例17: findParts

// read, [match, seek] till empty. repeat. validate
func (s *subset) findParts() (err error) {
    if s.current == nil {
        s.current = &part{offset: []int64{s.offsets[0], s.offsets[1]}, n: len(s.parts)}
    }
    s.Read()
    if s.read[1] > 0 {
        if bytes.EqualFold(s.bufA(), s.bufB()) {
            s.current.length += int64(s.read[0])
            s.offsets[0] += int64(s.read[0])
            s.offsets[1] += int64(s.read[1])
        } else {
            s.overlap()
            s.seak()
        }
        return s.findParts()
    } else {
        if s.current.length > 0 {
            s.parts = append(s.parts, s.current)
        }
    }
    return
}

开发者ID:narayandesai,项目名称:Shock,代码行数:23,代码来源:subset.go

示例18: find_map_key

func (self *Decoder) find_map_key(generic_map map[interface{}]interface{}, keyname string) (res interface{}, ok bool) {
    if len(keyname) == 0 || keyname == "-" {
        return nil, false
    }
    for key, value := range generic_map {
        switch key.(type) {
        case string:
            if key.(string) == keyname {
                return value, true
            }
        case []byte:
            if bytes.Equal(key.([]byte), []byte(keyname)) {
                return value, true
            }
        default:
            if fmt.Sprintf("%v", key) == keyname {
                return value, true
            }
        }
    }
    for key, value := range generic_map {
        switch key.(type) {
        case string:
            if strings.EqualFold(key.(string), keyname) {
                return value, true
            }
        case []byte:
            if bytes.EqualFold(key.([]byte), []byte(keyname)) {
                return value, true
            }
        default:
            if strings.EqualFold(fmt.Sprintf("%v", key), keyname) {
                return value, true
            }
        }
    }
    return nil, false
}

开发者ID:JKSN-format,项目名称:JKSN-Go,代码行数:38,代码来源:jksn.go

示例19: indexTagEnd

// indexTagEnd finds the index of a special tag end in a case insensitive way, or returns -1
func indexTagEnd(s []byte, tag []byte) int {
    res := 0
    plen := len(specialTagEndPrefix)
    for len(s) > 0 {
        // Try to find the tag end prefix first
        i := bytes.Index(s, specialTagEndPrefix)
        if i == -1 {
            return i
        }
        s = s[i+plen:]
        // Try to match the actual tag if there is still space for it
        if len(tag) <= len(s) && bytes.EqualFold(tag, s[:len(tag)]) {
            s = s[len(tag):]
            // Check the tag is followed by a proper separator
            if len(s) > 0 && bytes.IndexByte(tagEndSeparators, s[0]) != -1 {
                return res + i
            }
            res += len(tag)
        }
        res += i + plen
    }
    return -1
}

开发者ID:pjump,项目名称:gcc,代码行数:24,代码来源:transition.go

示例20: main

/*参数列表

s 字节切片
f 过滤函数
返回值

[][]byte 被分割的字节切片的切片
功能说明

FieldsFunc把s解释为UTF-8编码的字符序列,对于每个Unicode字符c,如果f(c)返回true就把c作为分隔字符对s进行拆分。如果所有都字符满足f(c)为true,则返回空的切片。
*/
func main() {
    fmt.Println(bytes.EqualFold([]byte("abc"), []byte("abc")))
    fmt.Println(bytes.EqualFold([]byte("abc"), []byte("abd")))
    fmt.Println(bytes.EqualFold([]byte("abc"), []byte("aBc")))
}

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

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