本文整理汇总了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))
}
}
示例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()
}
示例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
}
示例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
}
示例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)))
}
}
}
示例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
}
示例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
}
示例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)
}
}
示例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
}
示例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)
}
示例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
}
示例12: ExampleQuoteToASCII
func ExampleQuoteToASCII() {
s := strconv.QuoteToASCII(`"Fran & Freddie's Diner ☺"`)
fmt.Println(s)
// Output:
// "\"Fran & Freddie's Diner\t\u263a\""
}
示例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)
}
示例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)
}
})
}
示例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
}