本文整理汇总了Golang中bytes.TrimRightFunc函数的典型用法代码### 示例。如果您正苦于以下问题:Golang TrimRightFunc函数的具体用法?Golang TrimRightFunc怎么用?Golang TrimRightFunc使用的例子?那么恭喜您, 这里精选的函数代码### 示例或许可以为您提供帮助。
在下文中一共展示了TrimRightFunc函数的20个代码### 示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码### 示例。
示例1: Read
// Read reads and decodes quoted-printable data from the underlying reader.
func (r *Reader) Read(p []byte) (int, error) {
// Deviations from RFC 2045:
// 1. in addition to "=\r\n", "=\n" is also treated as soft line break.
// 2. it will pass through a '\r' or '\n' not preceded by '=', consistent
// with other broken QP encoders & decoders.
var n int
var err error
for len(p) > 0 {
if len(r.line) == 0 {
if err = r.Fn(); err != nil {
return n, err
}
r.line, r.rerr = r.br.ReadSlice('\n')
r.gerr.addUnrecover(r.rerr)
// Does the line end in CRLF instead of just LF?
hasLF := bytes.HasSuffix(r.line, lf)
hasCR := bytes.HasSuffix(r.line, crlf)
wholeLine := r.line
r.line = bytes.TrimRightFunc(wholeLine, isQPDiscardWhitespace)
if bytes.HasSuffix(r.line, softSuffix) {
rightStripped := wholeLine[len(r.line):]
r.line = r.line[:len(r.line)-1]
if !bytes.HasPrefix(rightStripped, lf) && !bytes.HasPrefix(rightStripped, crlf) {
r.rerr = fmt.Errorf("quotedprintable: invalid bytes after =: %q", rightStripped)
r.gerr.add(r.rerr)
}
} else if hasLF {
if hasCR {
r.line = append(r.line, '\r', '\n')
} else {
r.line = append(r.line, '\n')
}
}
continue
}
b := r.line[0]
switch {
case b == '=':
b, err = readHexByte(r.line[1:])
if err != nil {
b = '='
r.gerr.add(err)
break // this modification allow bad email to be parsed too
//return n, err
}
r.line = r.line[2:] // 2 of the 3; other 1 is done below
case b == '\t' || b == '\r' || b == '\n':
case b < ' ' || b > '~':
//return n, fmt.Errorf("quotedprintable: invalid unescaped byte 0x%02x in body", b)
r.gerr.add(fmt.Errorf("quotedprintable: invalid unescaped byte 0x%02x in body", b))
}
p[0] = b
p = p[1:]
r.line = r.line[1:]
n++
}
return n, r.Fn()
}
开发者ID:cention-sany,项目名称:mime,代码行数:61,代码来源:reader.go
示例2: main
func main() {
s := []byte("123456789")
f := func(r rune) bool {
return r > '7'
}
fmt.Println(string(bytes.TrimRightFunc(s, f)))
}
开发者ID:cwen-coder,项目名称:study-gopkg,代码行数:7,代码来源:TrimRightFunc.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: Listen
func (g *gobot) Listen() (err error) {
start, err := g.slackApi.startRTM()
if err != nil {
return
}
if !start.Okay {
return fmt.Errorf("Real-Time Messaging failed to start, aborting: %s", start.Error)
}
if g.setupFunc != nil {
g.setupFunc(g.slackApi)
}
conn := start.openWebSocket()
healthChecks(conn)
for {
_, msg, err := conn.ReadMessage()
if err != nil {
return err
}
var msgType unmarshalled
if err = json.Unmarshal(bytes.TrimRightFunc(msg, func(r rune) bool { return r == '\x00' }), &msgType); err != nil {
return err
}
go g.delegate(msgType.Type, msg)
}
}
开发者ID:adufrene,项目名称:gobot,代码行数:29,代码来源:gobot.go
示例5: sanitizeText
// sanitizeText tries to make the given string easier to read when presented
// as a single line. It squashes each run of white space into a single
// space, trims leading and trailing white space and trailing full
// stops. If newlineSemi is true, any newlines will be replaced with a
// semicolon.
func sanitizeText(s string, newlineSemi bool) []byte {
out := make([]byte, 0, len(s))
prevWhite := false
for _, r := range s {
if newlineSemi && r == '\n' && len(out) > 0 {
out = append(out, ';')
prevWhite = true
continue
}
if unicode.IsSpace(r) {
if len(out) > 0 {
prevWhite = true
}
continue
}
if prevWhite {
out = append(out, ' ')
prevWhite = false
}
out = append(out, string(r)...)
}
// Remove final space, any full stops and any final semicolon
// we might have added.
out = bytes.TrimRightFunc(out, func(r rune) bool {
return r == '.' || r == ' ' || r == ';'
})
return out
}
开发者ID:bz2,项目名称:httprequest,代码行数:33,代码来源:checkisjson.go
最后编辑: kuteng 文档更新时间: 2021-08-23 19:14 作者:kuteng