本文整理汇总了Golang中strings.Reader.Len方法的典型用法代码示例。如果您正苦于以下问题:Golang Reader.Len方法的具体用法?Golang Reader.Len怎么用?Golang Reader.Len使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类strings.Reader
的用法示例。
在下文中一共展示了Reader.Len方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: quotedWordCutter
func quotedWordCutter(reader *strings.Reader) (string, bool) {
var buffer bytes.Buffer
for {
if reader.Len() <= 0 {
return "", false
}
ch, _, _ := reader.ReadRune()
if ch != ' ' {
reader.UnreadRune()
break
}
}
quote := NULQUOTE
yenCount := 0
for reader.Len() > 0 {
ch, _, _ := reader.ReadRune()
if yenCount%2 == 0 {
if quote == NULQUOTE && (ch == '"' || ch == '\'') {
quote = ch
} else if quote != NULQUOTE && ch == quote {
quote = NULQUOTE
}
}
if ch == ' ' && quote == NULQUOTE {
break
}
if ch == '\\' {
yenCount++
} else {
yenCount = 0
}
buffer.WriteRune(ch)
}
return buffer.String(), true
}
示例2: entryCompleted
// Looks ahead to see if the next character completes the entry. Does not read
// any characters from the reader.
func entryCompleted(r *strings.Reader) bool {
if r.Len() > 0 {
b, _ := r.ReadByte()
r.UnreadByte()
return b == lineSeparator || b == entrySeparator
}
return true
}
示例3: consume
// Attempts to consume the wanted character from the reader. Returns true if
// character was read successfully, false otherwise. If the character could
// not be read, then no characters are consumed from the reader.
func consume(r *strings.Reader, wanted byte) bool {
if r.Len() > 0 {
b, _ := r.ReadByte()
if b == wanted {
return true
}
r.UnreadByte()
}
return false
}
示例4: applyHeadersToRequest
func (s *GitUploadPackService) applyHeadersToRequest(req *http.Request, content *strings.Reader) {
req.Header.Add("User-Agent", "git/1.0")
req.Header.Add("Host", "github.com")
if content == nil {
req.Header.Add("Accept", "*/*")
} else {
req.Header.Add("Accept", "application/x-git-upload-pack-result")
req.Header.Add("Content-Type", "application/x-git-upload-pack-request")
req.Header.Add("Content-Length", string(content.Len()))
}
}
示例5: atoi_
func atoi_(reader *strings.Reader) (int, int) {
n := 0
count := 0
for reader.Len() > 0 {
ch, _, _ := reader.ReadRune()
index := strings.IndexRune("0123456789", ch)
if index >= 0 {
n = n*10 + index
count++
} else {
reader.UnreadRune()
break
}
}
return n, count
}
示例6: MatchReader
func (n *Node) MatchReader(reader *strings.Reader) bool {
if reader.Len() == 0 && n.Terminal {
return true
}
r, _, err := reader.ReadRune()
if err != nil {
fmt.Println("Bad rune")
}
next, ok := n.Next(r)
if !ok {
return false
}
return next.MatchReader(reader)
}
示例7: merchantUploadImageFromStringsReader
func (c *Client) merchantUploadImageFromStringsReader(filename string, reader *strings.Reader) (imageURL string, err error) {
originalOffset, err := reader.Seek(0, 1)
if err != nil {
return
}
FormDataFileName := escapeQuotes(filename)
ContentLength := int64(multipart_constPartLen + len(FormDataFileName) + reader.Len())
hasRetry := false
RETRY:
token, err := c.Token()
if err != nil {
return
}
url_ := merchantUploadImageURL(token, filename)
if hasRetry {
if _, err = reader.Seek(originalOffset, 0); err != nil {
return
}
}
mr := io.MultiReader(
strings.NewReader(multipart_formDataFront),
strings.NewReader(FormDataFileName),
strings.NewReader(multipart_formDataMiddle),
reader,
strings.NewReader(multipart_formDataEnd),
)
httpReq, err := http.NewRequest("POST", url_, mr)
if err != nil {
return
}
httpReq.Header.Set("Content-Type", multipart_ContentType)
httpReq.ContentLength = ContentLength
httpResp, err := c.httpClient.Do(httpReq)
if err != nil {
return
}
defer httpResp.Body.Close()
if httpResp.StatusCode != http.StatusOK {
err = fmt.Errorf("http.Status: %s", httpResp.Status)
return
}
var result struct {
Error
ImageURL string `json:"image_url"`
}
if err = json.NewDecoder(httpResp.Body).Decode(&result); err != nil {
return
}
switch result.ErrCode {
case errCodeOK:
imageURL = result.ImageURL
return
case errCodeTimeout:
if !hasRetry {
hasRetry = true
timeoutRetryWait()
goto RETRY
}
fallthrough
default:
err = &result.Error
return
}
}