當前位置: 首頁>>代碼示例>>Golang>>正文


Golang strconv.QuoteRuneToASCII函數代碼示例

本文整理匯總了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
}
開發者ID:henrykhadass,項目名稱:Year2Compiler,代碼行數:26,代碼來源:lex.go

示例2: ExampleQuoteRuneToASCII

func ExampleQuoteRuneToASCII() {
	s := strconv.QuoteRuneToASCII('☺')
	fmt.Println(s)

	// Output:
	// '\u263a'
}
開發者ID:RajibTheKing,項目名稱:gcc,代碼行數:7,代碼來源:example_test.go

示例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
}
開發者ID:wwek,項目名稱:ncgo,代碼行數:30,代碼來源:utils.go

示例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")
	}
}
開發者ID:Maphardam,項目名稱:DailyProgrammer,代碼行數:33,代碼來源:solution.go

示例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)
}
開發者ID:WXB506,項目名稱:golang,代碼行數:11,代碼來源:format.go

示例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])
	}
}
開發者ID:pda,項目名稱:go6502,代碼行數:10,代碼來源:via6522.go

示例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)
	}
}
開發者ID:raff,項目名稱:eval,代碼行數:10,代碼來源:constnumber.go

示例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
}
開發者ID:wwek,項目名稱:ncgo,代碼行數:13,代碼來源:utils.go

示例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
}
開發者ID:mattdotmatt,項目名稱:gauge,代碼行數:13,代碼來源:specItemFilter.go

示例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:])
}
開發者ID:wmak,項目名稱:Talon,代碼行數:22,代碼來源:talon.go

示例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
}
開發者ID:ngaut,項目名稱:ddtxn,代碼行數:14,代碼來源:worker.go

示例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
}
開發者ID:muhang,項目名稱:daily-programmer,代碼行數:16,代碼來源:7-06.go

示例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, '\''))
}
開發者ID:notedit,項目名稱:eightfoot,代碼行數:21,代碼來源:utils.go

示例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
	}
}
開發者ID:luck02,項目名稱:StackCalcTests,代碼行數:39,代碼來源:split.go

示例15: rtoa

func rtoa(r rune) string {
	return strconv.QuoteRuneToASCII(r)
}
開發者ID:nstratos,項目名稱:mdt,代碼行數:3,代碼來源:helpers.go


注:本文中的strconv.QuoteRuneToASCII函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。