当前位置: 首页>>代码示例>>Golang>>正文


Golang Writer.WriteRune方法代码示例

本文整理汇总了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('"')
}
开发者ID:hlandau,项目名称:sx,代码行数:27,代码来源:sx.go

示例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('"')
}
开发者ID:ChristophPech,项目名称:servertest,代码行数:27,代码来源:default.go

示例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('|')
}
开发者ID:hlandau,项目名称:sx,代码行数:7,代码来源:sx.go

示例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)
	}
}
开发者ID:johnvilsack,项目名称:golang-stuff,代码行数:7,代码来源:writing.go

示例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
	}
}
开发者ID:uiri,项目名称:bombertcp,代码行数:32,代码来源:player.go

示例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
}
开发者ID:hlandau,项目名称:sx,代码行数:9,代码来源:sx.go

示例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)
	}
}
开发者ID:urdak,项目名称:tables,代码行数:10,代码来源:internals.go

示例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
}
开发者ID:eZanmoto,项目名称:Bake,代码行数:11,代码来源:template.go

示例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")
}
开发者ID:natefinch,项目名称:go-flags,代码行数:53,代码来源:help.go

示例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)
}
开发者ID:hlandau,项目名称:sx,代码行数:16,代码来源:sx.go

示例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
}
开发者ID:yinyin,项目名称:text2goquoted,代码行数:17,代码来源:quoter.go

示例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()
}
开发者ID:najeira,项目名称:testbed,代码行数:18,代码来源:testbed.go

示例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
}
开发者ID:hlandau,项目名称:sx,代码行数:42,代码来源:sx.go

示例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
}
开发者ID:jonboulle,项目名称:fleet,代码行数:20,代码来源:bridge.go

示例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)
	}
}
开发者ID:urdak,项目名称:tables,代码行数:18,代码来源:internals.go


注:本文中的bufio.Writer.WriteRune方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。