本文整理汇总了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
}
示例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
}
示例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))
}
}
}
示例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)
}
}
示例5: escapeCharset
func escapeCharset(r rune) string {
switch r {
case '[', ']', '-':
return `\` + string(r)
}
return strings.Trim(strconv.QuoteRune(r), `'`)
}
示例6: escapeLiteral
func escapeLiteral(r rune) string {
switch r {
case '(', ')', '[', ']', '-', '{', '}', '+', '*', '?':
return `\` + string(r)
}
return strings.Trim(strconv.QuoteRune(r), `'`)
}
示例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()
}
}
示例8: ExampleQuoteRune
func ExampleQuoteRune() {
s := strconv.QuoteRune('☺')
fmt.Println(s)
// Output:
// '☺'
}
示例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")
}
}
示例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]
}
}
示例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)
}
}
}
示例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)
}
}
示例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)
}
示例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)
}
示例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
}