本文整理汇总了Golang中strconv.QuoteRuneToASCII函数的典型用法代码示例。如果您正苦于以下问题:Golang QuoteRuneToASCII函数的具体用法?Golang QuoteRuneToASCII怎么用?Golang QuoteRuneToASCII使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了QuoteRuneToASCII函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: lexChar
func lexChar(l *Lexer) stateFn {
Loop:
for {
switch l.next() {
case '"':
fmt.Println(string(l.input[l.pos-2]))
if l.input[l.pos-2] != '\\' {
return l.errorf("unescaped char %s", string(l.input[l.pos-1]))
}
case '\\':
if ok := runeIsEscape(l.peek()); !ok {
return l.errorf("Not an escape character %s", strconv.QuoteRuneToASCII(l.next()))
} else {
l.next()
break
}
fallthrough
case eof, '\n':
return l.errorf("unterminated character constant")
case '\'':
break Loop
}
}
l.emit(CHARACTER)
return lexInsideProgram
}
示例2: ExampleQuoteRuneToASCII
func ExampleQuoteRuneToASCII() {
s := strconv.QuoteRuneToASCII('☺')
fmt.Println(s)
// Output:
// '\u263a'
}
示例3: createFromMixed
// Create normalized array of rows from mixed data (interface{})
func createFromMixed(data [][]interface{}, format byte) []*TabulateRow {
rows := make([]*TabulateRow, len(data))
for index_1, element := range data {
normalized := make([]string, len(element))
for index, el := range element {
switch el.(type) {
case int32:
quoted := strconv.QuoteRuneToASCII(el.(int32))
normalized[index] = quoted[1 : len(quoted)-1]
case int:
normalized[index] = strconv.Itoa(el.(int))
case int64:
normalized[index] = strconv.FormatInt(el.(int64), 10)
case bool:
normalized[index] = strconv.FormatBool(el.(bool))
case float64:
normalized[index] = strconv.FormatFloat(el.(float64), format, -1, 64)
case uint64:
normalized[index] = strconv.FormatUint(el.(uint64), 10)
case nil:
normalized[index] = "nil"
default:
normalized[index] = fmt.Sprintf("%s", el)
}
}
rows[index_1] = &TabulateRow{Elements: normalized}
}
return rows
}
示例4: main
func main() {
file, err := os.Open(os.Args[1])
if err != nil {
log.Fatal(err)
}
defer file.Close()
scanner := bufio.NewScanner(file)
scanner.Scan() //scan line number line
ln, err := strconv.Atoi(scanner.Text())
if err != nil {
log.Fatal(err)
}
var s string
for i := 1; i <= ln; i++ {
scanner.Scan()
tmp := scanner.Text()
tmp = strings.ToLower(tmp)
for _, r := range tmp {
//rc := strconv.QuoteRuneToASCII(r)
if r >= 'a' && r <= 'z' {
s += strconv.QuoteRuneToASCII(r)
}
}
}
if s == reverse(s) {
fmt.Println("Palindrome")
} else {
fmt.Println("Not a Palindrome")
}
}
示例5: fmt_qc
// fmt_qc formats the integer as a single-quoted, escaped Go character constant.
// If the character is not valid Unicode, it will print '\ufffd'.
func (f *fmt) fmt_qc(c int64) {
var quoted string
if f.plus {
quoted = strconv.QuoteRuneToASCII(int(c))
} else {
quoted = strconv.QuoteRune(int(c))
}
f.padString(quoted)
}
示例6: printAsciiByte
// Print a byte as ASCII, using escape sequences where necessary.
func printAsciiByte(b uint8) {
r := rune(b)
if unicode.IsPrint(r) || unicode.IsSpace(r) {
fmt.Print(string(r))
} else {
charStr := strconv.QuoteRuneToASCII(r)
fmt.Print(charStr[1 : len(charStr)-1])
}
}
示例7: StringShow0i
func (z *ConstNumber) StringShow0i(show0i bool) string {
if z.Type == ConstRune && z.Value.Re.Num().BitLen() <= 32 {
r, _, _ := z.Value.Int(32)
return strconv.QuoteRuneToASCII(rune(r))
} else if z.Type == ConstComplex {
return z.Value.StringShow0i(show0i)
} else {
return z.Value.StringShow0i(false)
}
}
示例8: createFromInt32
// Create normalized array from ints32
func createFromInt32(data [][]int32) []*TabulateRow {
rows := make([]*TabulateRow, len(data))
for index_1, arr := range data {
row := make([]string, len(arr))
for index, el := range arr {
quoted := strconv.QuoteRuneToASCII(el)
row[index] = quoted[1 : len(quoted)-1]
}
rows[index_1] = &TabulateRow{Elements: row}
}
return rows
}
示例9: getOperatorsAndOperands
func (filter *ScenarioFilterBasedOnTags) getOperatorsAndOperands() ([]string, []string) {
listOfOperators := make([]string, 0)
listOfTags := strings.FieldsFunc(filter.tagExpression, func(r rune) bool {
isValidOperator := r == '&' || r == '|' || r == '(' || r == ')' || r == '!'
if isValidOperator {
operator, _ := strconv.Unquote(strconv.QuoteRuneToASCII(r))
listOfOperators = append(listOfOperators, operator)
return isValidOperator
}
return false
})
return listOfOperators, listOfTags
}
示例10: Decode
func Decode(code string) (lat, lon float64) {
var _decode = func(character []rune) float64 {
var loc float64
first := strconv.QuoteRuneToASCII(character[0])
second := strconv.QuoteRuneToASCII(character[1])
val, _ := strconv.ParseInt("0x"+first[3:7]+second[3:7], 0, 32)
sval := strconv.FormatInt(val, 10)
loc = 1
if val < 2000000000 {
loc = -1
}
if val > 1000000000 {
val, _ = strconv.ParseInt(sval[2:], 0, 0)
}
fval := math.Mod(float64(val), 1000000000)
if sval[1] == 1 || sval[1] == 3 {
fval += 90
}
return fval / 10000000 * loc
}
return _decode([]rune(code)[:2]), _decode([]rune(code)[2:])
}
示例11: NextKey
func (w *Worker) NextKey(f rune) uint64 {
if !w.PreAllocated {
w.next++
x := uint64(w.next<<16) | uint64(w.ID)<<8 | uint64(w.next%CHUNKS)
return x
}
if w.LastKey[f] == w.CurrKey[f] {
log.Fatalf("%v Ran out of preallocated keys for %v; %v %v", w.ID, strconv.QuoteRuneToASCII(f), w.CurrKey[f], w.LastKey[f])
}
y := uint64(w.CurrKey[f] + w.start)
x := uint64(y<<16) | uint64(w.ID)<<8 | y%CHUNKS
w.CurrKey[f]++
return x
}
示例12: getCenter
func getCenter(w string) string {
result := ""
for idx, letter := range w {
sideA, sideB := w[:idx], w[(idx+1):]
sumA, sumB := sumSides(sideA, sideB)
if sumA-sumB == 0 {
result = fmt.Sprint(sideA, " ", strconv.QuoteRuneToASCII(letter), " ", sideB, " - ", sumA)
break
}
}
if result == "" {
result = fmt.Sprint(w, " DOES NOT BALANCE")
}
return result
}
示例13: HexBuffer1
// http://play.golang.org/p/pKPEeNWsjD
// 用来escape 特殊字符 "Hello, '世界'" => E'Hello, \'\u4e16\u754c\''
func HexBuffer1(input string) string {
output := make([]byte, 0, 3+len(input))
output = append(output, "E'"...)
for _, r := range input {
var s string
switch r {
case '\'':
s = `\'`
case '\\':
s = `\\`
default:
s = strconv.QuoteRuneToASCII(r)
// get rid of surrounding single quote
s = s[1 : len(s)-1]
}
output = append(output, s...)
}
return string(append(output, '\''))
}
示例14: Solution
func Solution(expression string) int {
// write your code in Go 1.4
stack := Stack{}
fmt.Println(expression)
for _, element := range expression {
value, err := strconv.Atoi(string(element))
if err != nil {
operand1, err := stack.Pop()
if err != nil {
return -1
}
operand2, err := stack.Pop()
if err != nil {
return -1
}
operation := strconv.QuoteRuneToASCII(element)
if operation == "'+'" {
total := operand1 + operand2
stack.Push(total)
} else if operation == "'*'" {
total := operand1 * operand2
stack.Push(total)
} else {
return -1
}
} else {
stack.Push(value)
}
}
finalValue, err := stack.Pop()
if err != nil {
return -1
} else {
return finalValue
}
}
示例15: rtoa
func rtoa(r rune) string {
return strconv.QuoteRuneToASCII(r)
}