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


Golang strconv.QuoteToASCII函数代码示例

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


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

示例1: dumpInst

func dumpInst(b *bytes.Buffer, i *Inst) {
	switch i.Op {
	case InstAlt:
		bw(b, "alt -> ", u32(i.Out), ", ", u32(i.Arg))
	case InstAltMatch:
		bw(b, "altmatch -> ", u32(i.Out), ", ", u32(i.Arg))
	case InstCapture:
		bw(b, "cap ", u32(i.Arg), " -> ", u32(i.Out))
	case InstEmptyWidth:
		bw(b, "empty ", u32(i.Arg), " -> ", u32(i.Out))
	case InstMatch:
		bw(b, "match")
	case InstFail:
		bw(b, "fail")
	case InstNop:
		bw(b, "nop -> ", u32(i.Out))
	case InstRune:
		if i.Rune == nil {
			// shouldn't happen
			bw(b, "rune <nil>")
		}
		bw(b, "rune ", strconv.QuoteToASCII(string(i.Rune)))
		if Flags(i.Arg)&FoldCase != 0 {
			bw(b, "/i")
		}
		bw(b, " -> ", u32(i.Out))
	case InstRune1:
		bw(b, "rune1 ", strconv.QuoteToASCII(string(i.Rune)), " -> ", u32(i.Out))
	case InstRuneAny:
		bw(b, "any -> ", u32(i.Out))
	case InstRuneAnyNotNL:
		bw(b, "anynotnl -> ", u32(i.Out))
	}
}
开发者ID:raomuming,项目名称:go,代码行数:34,代码来源:prog.go

示例2: TestMixedEncodings

func TestMixedEncodings(t *testing.T) {
	input := testData[0].other + "; " + testData[1].other + "; " + testData[0].other
	expected := testData[0].utf8 + "; " + testData[1].utf8 + "; " + testData[0].utf8

	ic, err := OpenWithFallback(testData[0].otherEncoding, "UTF-8", NEXT_ENC_UNRECOGNIZED)
	if err != nil {
		t.Errorf("Error on opening: %s\n", err)
		return
	}

	fallbackic, err := Open(testData[1].otherEncoding, "UTF-8")
	if err != nil {
		t.Errorf("Error on opening: %s\n", err)
		return
	}
	ic.SetFallback(fallbackic)

	b, err := ic.Conv([]byte(input))
	if err != nil {
		t.Errorf("Error on conversion: %s\n", err)
		return
	}

	println(strconv.QuoteToASCII(expected))
	println(strconv.QuoteToASCII(string(b)))

	if string(b) != expected {
		t.Errorf("mix failed")
	}
	ic.Close()
}
开发者ID:pombredanne,项目名称:goconv,代码行数:31,代码来源:iconv_test.go

示例3: String

func (rr *CAA) String() string {
	s := rr.Hdr.String() + strconv.FormatInt(int64(rr.Flag), 10) + " " + rr.Tag
	for i, s1 := range rr.Value {
		if i > 0 {
			s += " " + strconv.QuoteToASCII(s1)
		} else {
			s += strconv.QuoteToASCII(s1)
		}
	}
	return s
}
开发者ID:raybejjani,项目名称:dns,代码行数:11,代码来源:types.go

示例4: String

func (rr *SPF) String() string {
	s := rr.Hdr.String()
	for i, s1 := range rr.Txt {
		if i > 0 {
			s += " " + strconv.QuoteToASCII(s1)
		} else {
			s += strconv.QuoteToASCII(s1)
		}
	}
	return s
}
开发者ID:soh335,项目名称:dns,代码行数:11,代码来源:types.go

示例5: TestMoveToFront

func TestMoveToFront(t *testing.T) {
	test := func(buffer []byte) {
		input, output := make(chan []byte), make(chan []byte, 1)
		coder := BijectiveBurrowsWheelerCoder(input).MoveToFrontCoder()
		decoder := BijectiveBurrowsWheelerDecoder(output).MoveToFrontDecoder()

		input <- buffer
		close(input)
		output <- buffer
		close(output)
		for out := range coder.Input {
			for _, symbol := range out {
				decoder.Output(symbol)
			}
		}
	}
	for _, v := range TESTS {
		buffer := make([]byte, len(v))
		copy(buffer, []byte(v))
		test(buffer)
		if string(buffer) != v {
			t.Errorf("inverse should be '%v'; got '%v'", v, strconv.QuoteToASCII(string(buffer)))
		}
	}
}
开发者ID:pointlander,项目名称:compress,代码行数:25,代码来源:compress_test.go

示例6: printOut

func (e entry) printOut(w io.Writer, displayTS bool) error {
	var err error
	err = writeHelper(prefix, w, err)
	if displayTS {
		err = writeHelper(tsPrefix, w, err)
		err = writeHelper([]byte(time.Now().String()), w, err)
		err = writeHelper(tsSuffix, w, err)
	}
	err = writeHelper([]byte(e.level.String()), w, err)
	err = writeHelper(separatorSpace, w, err)
	err = writeHelper([]byte(e.msg), w, err)
	if len(e.kv) > 0 {
		err = writeHelper(separator, w, err)
		for _, kve := range e.kv {
			err = writeHelper(space, w, err)
			err = writeHelper([]byte(kve.K), w, err)
			err = writeHelper(equals, w, err)
			vstr := fmt.Sprint(kve.V)
			// TODO this is only here because logstash is dumb and doesn't
			// properly handle escaped quotes. Once
			// https://github.com/elastic/logstash/issues/1645
			// gets figured out this Replace can be removed
			vstr = strings.Replace(vstr, `"`, `'`, -1)
			vstr = strconv.QuoteToASCII(vstr)
			err = writeHelper([]byte(vstr), w, err)
		}
	}
	err = writeHelper(newline, w, err)

	return err
}
开发者ID:levenlabs,项目名称:go-llog,代码行数:31,代码来源:llog.go

示例7: embed

func embed(variable, wrap, filename string, in io.Reader, out io.Writer) error {
	_, err := fmt.Fprintf(out, "var %s = %s(asset.init(asset{Name: %q, Content: \"\" +\n",
		variable, wrap, filename)
	if err != nil {
		return err
	}
	buf := make([]byte, 1*1024*1024)
	eof := false
	for !eof {
		n, err := in.Read(buf)
		switch err {
		case io.EOF:
			eof = true
		case nil:

		default:
			return err
		}
		if n == 0 {
			continue
		}
		s := string(buf[:n])
		s = strconv.QuoteToASCII(s)
		s = "\t" + s + " +\n"
		if _, err := io.WriteString(out, s); err != nil {
			return err
		}
	}
	if _, err := fmt.Fprintf(out, "\t\"\"}))\n"); err != nil {
		return err
	}
	return nil
}
开发者ID:echlebek,项目名称:erickson,代码行数:33,代码来源:asset.go

示例8: TestBurrowsWheeler

func TestBurrowsWheeler(t *testing.T) {
	test := func(input string) {
		buffer := make([]byte, len(input))
		copy(buffer, input)
		tree := BuildSuffixTree(buffer)
		bw, sentinel := tree.BurrowsWheelerCoder()
		index, out_buffer := 0, make([]byte, len(buffer)+1)
		for b := range bw {
			out_buffer[index] = b
			index++
		}
		s := <-sentinel
		for b, c := out_buffer[s], s+1; c < len(out_buffer); c++ {
			out_buffer[c], b = b, out_buffer[c]
		}

		/*fmt.Println(strconv.QuoteToASCII(string(out_buffer)))*/
		original := burrowsWheelerDecoder(out_buffer, s)
		if bytes.Compare(buffer, original) != 0 {
			t.Errorf("should be '%v'; got '%v'", input, strconv.QuoteToASCII(string(original)))
		}
	}
	for _, v := range TESTS {
		test(v)
	}
}
开发者ID:pointlander,项目名称:compress,代码行数:26,代码来源:compress_test.go

示例9: authPassword

// authPassword records any incoming request trying to auth with a username/password
func authPassword(conn ssh.ConnMetadata, password []byte) (*ssh.Permissions, error) {

	r := &AuthEvent{
		Time:        fmt.Sprintf("%d", time.Now().Unix()),
		AuthType:    "sshPass",
		SrcIP:       strings.Split(conn.RemoteAddr().String(), ":")[0],
		DestIP:      extIP,
		User:        conn.User(),
		TypeData:    fmt.Sprintf("client-version: %s", strconv.QuoteToASCII(string(conn.ClientVersion()))),
		Credentials: strconv.QuoteToASCII(string(password)),
	}

	addToBatch(r)

	return nil, errAuthenticationFailed
}
开发者ID:gombadi,项目名称:honeygot,代码行数:17,代码来源:ssh.go

示例10: authHandler

// authHandler is called in a goroutine to handle each incoming request
func authHandler(w http.ResponseWriter, r *http.Request) {

	// pull the auth details from the request
	user, pass, ok := r.BasicAuth()
	if ok == true {

		host, _, err := net.SplitHostPort(r.RemoteAddr)
		if err != nil {
			host = ""
		}
		r := &AuthEvent{
			Time:        fmt.Sprintf("%d", time.Now().Unix()),
			AuthType:    "httpAuth",
			SrcIP:       host,
			DestIP:      extIP,
			User:        user,
			Credentials: strconv.QuoteToASCII(pass),
		}
		addToBatch(r)

	}
	// always return auth fail
	w.Header().Set("WWW-Authenticate", "Basic realm=Restricted")
	http.Error(w, "authorization failed", http.StatusUnauthorized)
}
开发者ID:gombadi,项目名称:honeygot,代码行数:26,代码来源:httpauth.go

示例11: Append

// Append (to satisfy the Appender interface) adds a log message to the internal
// buffer, and translates the log message into a format that is used by the
// remote endpoint.
func (apiLgr *APILogger) Append(log *slogger.Log) error {
	message := strings.TrimRight(log.Message(), "\r\n \t")

	// MCI-972: ensure message is valid UTF-8
	if !utf8.ValidString(message) {
		message = strconv.QuoteToASCII(message)
	}

	logMessage := &model.LogMessage{
		Timestamp: log.Timestamp,
		Severity:  levelToString(log.Level),
		Type:      log.Prefix,
		Version:   evergreen.LogmessageCurrentVersion,
		Message:   message,
	}

	apiLgr.appendLock.Lock()
	defer apiLgr.appendLock.Unlock()
	apiLgr.messages = append(apiLgr.messages, *logMessage)

	if len(apiLgr.messages) < apiLgr.SendAfterLines ||
		time.Since(apiLgr.lastFlush) < apiLgr.SendAfterDuration {
		return nil
	}

	apiLgr.flushInternal()

	return nil
}
开发者ID:himanshugpt,项目名称:evergreen,代码行数:32,代码来源:logger.go

示例12: ExampleQuoteToASCII

func ExampleQuoteToASCII() {
	s := strconv.QuoteToASCII(`"Fran & Freddie's Diner	☺"`)
	fmt.Println(s)

	// Output:
	// "\"Fran & Freddie's Diner\t\u263a\""
}
开发者ID:RajibTheKing,项目名称:gcc,代码行数:7,代码来源:example_test.go

示例13: TestBijectiveBurrowsWheeler

func TestBijectiveBurrowsWheeler(t *testing.T) {
	input, output := make(chan []byte), make(chan []byte, 2)
	coder, decoder := BijectiveBurrowsWheelerCoder(input), BijectiveBurrowsWheelerDecoder(output)
	test := func(buffer []byte) {
		for c := 0; c < repeated; c++ {
			input <- buffer
			<-coder.Input
		}

		in := make([]byte, len(buffer))
		for c := 0; c < repeated; c++ {
			output <- in
			output <- nil
			for _, i := range buffer {
				decoder.Output(i)
			}
			copy(buffer, in)
		}
	}
	for _, v := range TESTS {
		buffer := make([]byte, len(v))
		copy(buffer, []byte(v))
		test(buffer)
		if string(buffer) != v {
			t.Errorf("should be '%v'; got '%v'", v, strconv.QuoteToASCII(string(buffer)))
		}
	}
	close(input)
	close(output)
}
开发者ID:pointlander,项目名称:compress,代码行数:30,代码来源:compress_test.go

示例14: doTest

// doTest performs a single test f(input) and verifies that the output matches
// out and that the returned error is expected. The errors string contains
// all allowed error codes as categorized in
// http://www.unicode.org/Public/idna/9.0.0/IdnaTest.txt:
// P: Processing
// V: Validity
// A: to ASCII
// B: Bidi
// C: Context J
func doTest(t *testing.T, f func(string) (string, error), name, input, want, errors string) {
	errors = strings.Trim(errors, "[]")
	test := "ok"
	if errors != "" {
		test = "err:" + errors
	}
	// Replace some of the escape sequences to make it easier to single out
	// tests on the command name.
	in := strings.Trim(strconv.QuoteToASCII(input), `"`)
	in = strings.Replace(in, `\u`, "#", -1)
	in = strings.Replace(in, `\U`, "#", -1)
	name = fmt.Sprintf("%s/%s/%s", name, in, test)

	testtext.Run(t, name, func(t *testing.T) {
		got, err := f(input)

		if err != nil {
			code := err.(interface {
				code() string
			}).code()
			if strings.Index(errors, code) == -1 {
				t.Errorf("error %q not in set of expected errors {%v}", code, errors)
			}
		} else if errors != "" {
			t.Errorf("no errors; want error in {%v}", errors)
		}

		if want != "" && got != want {
			t.Errorf(`string: got %+q; want %+q`, got, want)
		}
	})
}
开发者ID:luizbafilho,项目名称:fusis,代码行数:41,代码来源:idna_test.go

示例15: Error

func (e *ParseError) Error() (s string) {
	if e.file != "" {
		s = e.file + ": "
	}
	s += "dns: " + e.err + ": " + strconv.QuoteToASCII(e.lex.token) + " at line: " +
		strconv.Itoa(e.lex.line) + ":" + strconv.Itoa(e.lex.column)
	return
}
开发者ID:avalanche123,项目名称:dns,代码行数:8,代码来源:zscan.go


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