本文整理汇总了Golang中bufio.Writer.WriteRune方法的典型用法代码示例。如果您正苦于以下问题:Golang Writer.WriteRune方法的具体用法?Golang Writer.WriteRune怎么用?Golang Writer.WriteRune使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类bufio.Writer
的用法示例。
在下文中一共展示了Writer.WriteRune方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: writeQuotedString
func writeQuotedString(s string, b *bufio.Writer, f *Format) {
b.WriteRune('"')
for i := range s {
c := s[i] // don't decode as runes
switch c {
case '\r':
b.WriteString(`\r`)
case '\n':
b.WriteString(`\n`)
case '\t':
b.WriteString(`\t`)
case '"':
b.WriteString(`\"`)
case '\\':
b.WriteString(`\\`)
default:
if c < 0x80 && unicode.IsPrint(rune(c)) {
b.WriteRune(rune(c))
} else {
b.WriteString(`\x`)
b.WriteRune(enchex((c >> 4) & 0x0F))
b.WriteRune(enchex(c & 0x0F))
}
}
}
b.WriteRune('"')
}
示例2: CSVWriteVal
func CSVWriteVal(cw *bufio.Writer, i interface{}) {
sVal := fmt.Sprintf("%v", i)
if len(sVal) <= 0 {
return
}
bQuot := strings.IndexRune(sVal, ',') >= 0 || strings.IndexAny(sVal, "\"\r\n") >= 0
if !bQuot {
cw.WriteString(sVal)
return
}
cw.WriteByte('"')
for _, r1 := range sVal {
switch r1 {
case '"':
cw.WriteString(`""`)
case '\r':
cw.WriteByte('\r')
case '\n':
cw.WriteByte('\n')
default:
cw.WriteRune(r1)
}
}
cw.WriteByte('"')
}
示例3: writeBase64String
func writeBase64String(s string, b *bufio.Writer, f *Format) {
b.WriteRune('|')
w := base64.NewEncoder(base64.StdEncoding, b)
w.Write([]byte(s))
w.Close()
b.WriteRune('|')
}
示例4: doWriteRune
func doWriteRune(w *bufio.Writer) {
if written, err := w.WriteRune(rune('o')); err != nil {
log.Fatalf("failed writing a rune: %s", err)
} else {
log.Printf("Wrote rune in %d bytes", written)
}
}
示例5: sendUpdates
func (t *TcpPlayer) sendUpdates(w *bufio.Writer, wg *sync.WaitGroup) {
defer wg.Done()
enc := json.NewEncoder(w)
lastTurnSent := -1
for update := range t.update {
t.stateL.Lock()
t.state = update
t.stateL.Unlock()
if update.Turn == lastTurnSent {
continue
}
if err := enc.Encode(update); err != nil {
t.l.Errorf("[TCP] sending update to player, %v", err)
return
}
if _, err := w.WriteRune('\n'); err != nil {
t.l.Errorf("[TCP] sending EOL to player, %v", err)
return
}
if err := w.Flush(); err != nil {
t.l.Errorf("[TCP] flushing update to player, %v", err)
return
}
lastTurnSent = update.Turn
}
}
示例6: write
func (s *spacer) write(b *bufio.Writer, t rune) {
if s.f.serializationMode == szModeCanonical {
return
}
if s.prevType == 'i' || s.prevType == 's' {
b.WriteRune(' ')
}
s.prevType = t
}
示例7: printHorizontalLine
// Prints a horizontal line for the table based on a row.
func (table Table) printHorizontalLine(w *bufio.Writer, r row) {
if len(r) != 0 {
w.WriteRune(table.CSeparator)
for i, _ := range r {
fmt.Fprintf(w, "%s%s", strings.Repeat(string(table.HSeparator), table.colWidth[i]+2), string(table.CSeparator))
}
w.WriteRune(newline)
}
}
示例8: copyNext
func copyNext(in *scanner.Scanner, out *bufio.Writer) error {
c := in.Next()
if out != nil {
if n, err := out.WriteRune(c); err == nil && n < 1 {
return fmt.Errorf("Couldn't write: %c", c)
} else if err != nil {
return err
}
}
return nil
}
示例9: writeHelpOption
func (p *Parser) writeHelpOption(writer *bufio.Writer, option *Option, maxlen int, hasshort bool, termcol int) {
if option.ShortName != 0 {
writer.WriteString(" -")
writer.WriteRune(option.ShortName)
} else if hasshort {
writer.WriteString(" ")
}
written := 0
prelen := 4
if option.LongName != "" {
if option.ShortName != 0 {
writer.WriteString(", ")
} else {
writer.WriteString(" ")
}
fmt.Fprintf(writer, "--%s", option.LongName)
written = utf8.RuneCountInString(option.LongName)
prelen += written + 4
}
if option.Description != "" {
if written < maxlen {
dw := maxlen - written
writer.WriteString(strings.Repeat(" ", dw))
prelen += dw
}
def := option.Default
if def == "" && !option.isBool() {
def = convertToString(option.Value, option.Field.Tag)
}
var desc string
if def != "" {
desc = fmt.Sprintf("%s (%v)", option.Description, def)
} else {
desc = option.Description
}
writer.WriteString(wrapText(desc,
termcol-prelen,
strings.Repeat(" ", prelen)))
}
writer.WriteString("\n")
}
示例10: writeString
func writeString(s string, b *bufio.Writer, f *Format) {
if f.serializationMode == szModeAdvanced {
if isBinary(s) {
writeBase64String(s, b, f)
} else if usesTokenCharset(s) {
writeToken(s, b, f)
} else {
writeQuotedString(s, b, f)
}
return
}
writeUint(uint64(len(s)), b, f)
b.WriteRune(':')
b.WriteString(s)
}
示例11: outputLine
func outputLine(w *bufio.Writer, line string, suffix string, count int) (err error) {
if count > 0 {
if _, err = w.WriteRune('\t'); nil != err {
return err
}
}
if _, err = w.WriteString(line); nil != err {
return err
}
if _, err = w.WriteString(suffix); nil != err {
return err
}
if _, err = w.WriteRune('\n'); nil != err {
return err
}
return nil
}
示例12: write
// write writes a protocol buffer to the socketAPI socket.
func write(w *bufio.Writer, pb proto.Message) error {
b, err := proto.Marshal(pb)
if err != nil {
return err
}
var buf bytes.Buffer
buf.WriteString(strconv.Itoa(len(b)))
buf.WriteString("\n")
buf.Write(b)
body := base64.StdEncoding.EncodeToString(buf.Bytes())
w.WriteString(body)
w.WriteRune('\n')
return w.Flush()
}
示例13: writeList
func writeList(vs []interface{}, b *bufio.Writer, f *Format) error {
spacer := spacer{f: f}
for _, v := range vs {
switch vv := v.(type) {
case string:
spacer.write(b, 's')
writeString(vv, b, f)
case []byte:
spacer.write(b, 's')
writeString(string(vv), b, f)
case int:
spacer.write(b, 'i')
writeInt(int64(vv), b, f)
if f.serializationMode == szModeCanonical {
b.WriteRune(' ')
}
case int64:
spacer.write(b, 'i')
writeInt(vv, b, f)
if f.serializationMode == szModeCanonical {
b.WriteRune(' ')
}
case uint64:
spacer.write(b, 'i')
writeUint(vv, b, f)
if f.serializationMode == szModeCanonical {
b.WriteRune(' ')
}
case []interface{}:
spacer.write(b, '(')
b.WriteRune('(')
if err := writeList(vv, b, f); err != nil {
return err
}
b.WriteRune(')')
default:
return ErrUnsupportedType
}
}
return nil
}
示例14: writeSanitized
func writeSanitized(buf *bufio.Writer, s string) error {
prevUnderscore := false
for _, c := range s {
c = replaceInvalidRune(c)
if c == '_' {
if prevUnderscore {
continue
}
prevUnderscore = true
} else {
prevUnderscore = false
}
if _, err := buf.WriteRune(c); err != nil {
return err
}
}
return nil
}
示例15: printRowData
// Prints the data that is contained inside the specified row.
func (table Table) printRowData(w *bufio.Writer, r row) {
maxLines := r.maxLines()
for i := 0; i < maxLines; i++ {
w.WriteRune(table.VSeparator)
for j := 0; j < len(r); j++ {
var data string
if i >= len(r[j]) {
data = strings.Repeat(" ", table.colWidth[j])
} else {
data = r[j][i]
}
fmt.Fprintf(w, " %s ", table.Align.align(data, table.colWidth[j]))
w.WriteRune(table.VSeparator)
}
w.WriteRune(newline)
}
}