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


Golang strconv.QuoteRune函数代码示例

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


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

示例1: bind

func (bnd *bndBool) bind(value bool, position int, c StmtCfg, stmt *Stmt) (err error) {
	//Log.Infof("%s.bind(%t, %d)", bnd, value, position)
	bnd.stmt = stmt
	var str string
	if value {
		str, err = strconv.Unquote(strconv.QuoteRune(c.TrueRune))
	} else {
		str, err = strconv.Unquote(strconv.QuoteRune(c.FalseRune))
	}
	if err != nil {
		return err
	}
	bnd.cString = C.CString(str)
	r := C.OCIBINDBYPOS(
		bnd.stmt.ocistmt,            //OCIStmt      *stmtp,
		(**C.OCIBind)(&bnd.ocibnd),  //OCIBind      **bindpp,
		bnd.stmt.ses.srv.env.ocierr, //OCIError     *errhp,
		C.ub4(position),             //ub4          position,
		unsafe.Pointer(bnd.cString), //void         *valuep,
		C.LENGTH_TYPE(1),            //sb8          value_sz,
		C.SQLT_AFC,                  //ub2          dty,
		nil,                         //void         *indp,
		nil,                         //ub2          *alenp,
		nil,                         //ub2          *rcodep,
		0,                           //ub4          maxarr_len,
		nil,                         //ub4          *curelep,
		C.OCI_DEFAULT)               //ub4          mode );
	if r == C.OCI_ERROR {
		return bnd.stmt.ses.srv.env.ociError()
	}
	return nil
}
开发者ID:optimuse,项目名称:ora,代码行数:32,代码来源:bndBool.go

示例2: validateProjectTaskIdsAndTags

// validateProjectTaskIdsAndTags ensures that task tags and ids only contain valid characters
func validateProjectTaskIdsAndTags(project *model.Project) []ValidationError {
	errs := []ValidationError{}
	// create a map to hold the task names
	for _, task := range project.Tasks {
		// check task name
		if i := strings.IndexAny(task.Name, model.InvalidCriterionRunes); i == 0 {
			errs = append(errs, ValidationError{
				Message: fmt.Sprintf("task '%v' has invalid name: starts with invalid character %v",
					task.Name, strconv.QuoteRune(rune(task.Name[0])))})
		}
		// check tag names
		for _, tag := range task.Tags {
			if i := strings.IndexAny(tag, model.InvalidCriterionRunes); i == 0 {
				errs = append(errs, ValidationError{
					Message: fmt.Sprintf("task '%v' has invalid tag '%v': starts with invalid character %v",
						task.Name, tag, strconv.QuoteRune(rune(tag[0])))})
			}
			if i := util.IndexWhiteSpace(tag); i != -1 {
				errs = append(errs, ValidationError{
					Message: fmt.Sprintf("task '%v' has invalid tag '%v': tag contains white space",
						task.Name, tag)})
			}
		}
	}
	return errs
}
开发者ID:sr527,项目名称:evergreen,代码行数:27,代码来源:project_validator.go

示例3:

func Test한글(t *testing.T) {
	h := "한글"
	assert.Equal(t, 6, len(h))
	assert.Equal(t, 2, utf8.RuneCountInString(h))
	assert.Equal(t, []string{"한", "글"}, strings.Split(h, ""))
	assert.True(t, strings.Contains(h, "한"))
	assert.True(t, strings.Contains(h, "글"))
	assert.True(t, strings.ContainsRune(h, '한'))
	assert.True(t, strings.ContainsRune(h, '글'))
	runes := []rune(h)
	assert.Equal(t, []int32{54620, 44544}, runes)
	assert.Equal(t, "[]int32", reflect.TypeOf(runes).String())
	assert.Equal(t, "int32", reflect.TypeOf(runes[0]).String())
	r := reflect.ValueOf(runes[0])
	assert.Equal(t, "reflect.Value", reflect.TypeOf(r).String())
	assert.Equal(t, "int32", r.Type().String())
	assert.Equal(t, reflect.Int32, r.Kind())
	for i, c := range h {
		assert.True(t, strings.Contains(h, string(c)))
		assert.True(t, strings.ContainsRune(h, c))
		assert.Equal(t, "int32", reflect.TypeOf(c).String())
		assert.Equal(t, "int32", reflect.TypeOf(rune(c)).String())
		assert.Equal(t, "string", reflect.TypeOf(strconv.QuoteRune(c)).String())
		if 0 == i {
			assert.True(t, 54620 == c)
			assert.Equal(t, "한", string(c))
			assert.Equal(t, "'한'", strconv.QuoteRune(c))
		}
	}
}
开发者ID:wookay,项目名称:aheui-go,代码行数:30,代码来源:hangul_test.go

示例4: init

func init() {
	for k, v := range xc.PrintHooks {
		printHooks[k] = v
	}
	lcRT := reflect.TypeOf(lex.Char{})
	lcH := func(f strutil.Formatter, v interface{}, prefix, suffix string) {
		c := v.(lex.Char)
		r := c.Rune
		s := yySymName(int(r))
		if x := s[0]; x >= '0' && x <= '9' {
			s = strconv.QuoteRune(r)
		}
		f.Format("%s%v: %s"+suffix, prefix, xc.FileSet.Position(c.Pos()), s)
	}
	printHooks[lcRT] = lcH
	printHooks[reflect.TypeOf(xc.Token{})] = func(f strutil.Formatter, v interface{}, prefix, suffix string) {
		t := v.(xc.Token)
		if !t.Pos().IsValid() {
			return
		}

		lcH(f, t.Char, prefix, "")
		if s := xc.Dict.S(t.Val); len(s) != 0 {
			f.Format(" %q", s)
		}
		f.Format(suffix)
	}
}
开发者ID:JamesLinus,项目名称:pl0,代码行数:28,代码来源:pl0.go

示例5: escapeCharset

func escapeCharset(r rune) string {
	switch r {
	case '[', ']', '-':
		return `\` + string(r)
	}
	return strings.Trim(strconv.QuoteRune(r), `'`)
}
开发者ID:h12w,项目名称:gombi,代码行数:7,代码来源:dump.go

示例6: escapeLiteral

func escapeLiteral(r rune) string {
	switch r {
	case '(', ')', '[', ']', '-', '{', '}', '+', '*', '?':
		return `\` + string(r)
	}
	return strings.Trim(strconv.QuoteRune(r), `'`)
}
开发者ID:h12w,项目名称:gombi,代码行数:7,代码来源:dump.go

示例7: TestParseToInvocation

func TestParseToInvocation(t *testing.T) {
	ti := time.Time{}
	sync := strconv.QuoteRune(Syncd)

	sample := sync + "" + ti.Format(time.UnixDate) +
		"sorenlaptopbash/home/soren/src/project" +
		"git log --graph --abbrev-commit --decorate --date=relative --all" +
		"[git log graph]0\n"

	expect := IndexEntry{}
	expect.User = "soren"
	expect.Host = "laptop"
	expect.Shell = "bash"
	expect.Timestamp = ti
	expect.Directory = "/home/soren/src/project"
	expect.Command = "git log --graph --abbrev-commit --decorate --date=relative --all"
	expect.Tags = []string{"git", "log", "graph"}
	expect.Status = 0
	expect.HasStatus = true
	expect.IsSynced = true

	res, err := parseToEntry(sample)
	if err != nil {
		t.Fail()
	}

	expectedStr := fmt.Sprint(expect)
	resultStr := fmt.Sprint(res)

	if expectedStr != resultStr {
		t.Fail()
	}

}
开发者ID:warreq,项目名称:gohst,代码行数:34,代码来源:index_test.go

示例8: ExampleQuoteRune

func ExampleQuoteRune() {
	s := strconv.QuoteRune('☺')
	fmt.Println(s)

	// Output:
	// '☺'
}
开发者ID:RajibTheKing,项目名称:gcc,代码行数:7,代码来源:example_test.go

示例9: str

func (j *job) str(expr ebnf.Expression) (s string) {
	switch x := expr.(type) {
	case nil:
		return "/* EMPTY */"
	case *ebnf.Name:
		switch name := x.String; ast.IsExported(name) {
		case true:
			return name
		default:
			return j.term2name[name]
		}
	case ebnf.Sequence:
		a := []string{}
		for _, v := range x {
			a = append(a, j.str(v))
		}
		return strings.Join(a, " ")
	case *ebnf.Token:
		switch s := x.String; len(s) {
		case 1:
			return strconv.QuoteRune(rune(s[0]))
		default:
			hint := ""
			if _, ok := j.rep.Literals[s]; ok && toAscii(s) == "" {
				hint = fmt.Sprintf(" /* %q */", s)
			}
			return fmt.Sprintf("%s%s", j.term2name[s], hint)
		}
	default:
		log.Fatalf("%T(%#v)", x, x)
		panic("unreachable")
	}
}
开发者ID:andaru,项目名称:ebnf2y,代码行数:33,代码来源:ebnf2y.go

示例10: cprotect

//  cprotect returns its argument if printable, else a backslash form.
func cprotect(r rune) string {
	if strconv.IsPrint(r) {
		return string(r)
	} else {
		s := strconv.QuoteRune(r)
		return s[1 : len(s)-1]
	}
}
开发者ID:proebsting,项目名称:re,代码行数:9,代码来源:charset.go

示例11: checkPlausible

// aborts the attempt if a desired character is not a valid base32 digit
func checkPlausible() {
	for _, r := range prefix {
		if !strings.ContainsRune(alphabet, r) {
			fmt.Printf("Invalid prefix: %s is not in the base32 alphabet\n", strconv.QuoteRune(r))
			os.Exit(1)
		}
	}
}
开发者ID:nullstyle,项目名称:go-stellar-base,代码行数:9,代码来源:main.go

示例12: main

func main() {
	filename := "C-large-practice.in"
	lines, err := readLines(filename)
	if err != nil {
		log.Fatalf("readLines: %s", err)
	}
	keyOf := map[string]string{
		"a": "2",
		"b": "22",
		"c": "222",
		"d": "3",
		"e": "33",
		"f": "333",
		"g": "4",
		"h": "44",
		"i": "444",
		"j": "5",
		"k": "55",
		"l": "555",
		"m": "6",
		"n": "66",
		"o": "666",
		"p": "7",
		"q": "77",
		"r": "777",
		"s": "7777",
		"t": "8",
		"u": "88",
		"v": "888",
		"w": "9",
		"x": "99",
		"y": "999",
		"z": "9999",
		" ": "0",
	}

	testCases, err := strconv.Atoi(lines[0])
	var s []string
	ans, pre := "", ""

	for i := 1; i <= testCases; i++ {
		pre, ans = "", ""
		for _, rune := range lines[i] {
			indx, _ := strconv.Unquote(strconv.QuoteRune(rune))
			letterKey := keyOf[indx]
			if pre == strconv.Itoa(int(letterKey[0])) {
				ans += " "
			}
			ans += letterKey
			pre = strconv.Itoa(int(letterKey[0]))
		}
		s = append(s, "Case #"+strconv.Itoa(i)+": "+ans)
	}

	if err := writeLines(s, "C-small-practice.out"); err != nil {
		log.Fatalf("Error!", err)
	}
}
开发者ID:RoyMontoya,项目名称:google-code-jam,代码行数:58,代码来源:tNine.go

示例13: 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

示例14: quote

func quote(b byte) string {
	switch b {
	case '\'', '"', '`':
		return string(rune(b))
	}
	if b < utf8.RuneSelf && strconv.IsPrint(rune(b)) {
		return strconv.QuoteRune(rune(b))
	}
	return fmt.Sprintf(`%.2x`, b)
}
开发者ID:h12w,项目名称:dfa,代码行数:10,代码来源:dump.go

示例15: trimHash

// trimHash slices a hash # from the link
func trimHash(l string) string {
	if strings.Contains(l, "#") {
		var index int
		for n, str := range l {
			if strconv.QuoteRune(str) == "'#'" {
				index = n
				break
			}
		}
		return l[:index]
	}
	return l
}
开发者ID:danielfireman,项目名称:phd,代码行数:14,代码来源:collectlinks.go


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