本文整理汇总了Golang中unicode.IsPrint函数的典型用法代码示例。如果您正苦于以下问题:Golang IsPrint函数的具体用法?Golang IsPrint怎么用?Golang IsPrint使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了IsPrint函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: main
func main() {
rang, except := scan(0, 0xFFFF)
range16 = to16(rang)
except16 = to16(except)
range32, except32 = scan(0x10000, unicode.MaxRune)
for i := rune(0); i <= unicode.MaxRune; i++ {
if isPrint(i) != unicode.IsPrint(i) {
fmt.Fprintf(os.Stderr, "%U: isPrint=%v, want %v\n", i, isPrint(i), unicode.IsPrint(i))
return
}
}
fmt.Printf(`// Copyright 2013 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.` + "\n\n")
fmt.Printf("// DO NOT EDIT. GENERATED BY\n")
fmt.Printf("// go run makeisprint.go >x && mv x isprint.go\n\n")
fmt.Printf("package strconv\n\n")
fmt.Printf("// (%d+%d+%d)*2 + (%d)*4 = %d bytes\n\n",
len(range16), len(except16), len(except32),
len(range32),
(len(range16)+len(except16)+len(except32))*2+
(len(range32))*4)
fmt.Printf("var isPrint16 = []uint16{\n")
for i := 0; i < len(range16); i += 2 {
fmt.Printf("\t%#04x, %#04x,\n", range16[i], range16[i+1])
}
fmt.Printf("}\n\n")
fmt.Printf("var isNotPrint16 = []uint16{\n")
for _, r := range except16 {
fmt.Printf("\t%#04x,\n", r)
}
fmt.Printf("}\n\n")
fmt.Printf("var isPrint32 = []uint32{\n")
for i := 0; i < len(range32); i += 2 {
fmt.Printf("\t%#06x, %#06x,\n", range32[i], range32[i+1])
}
fmt.Printf("}\n\n")
fmt.Printf("var isNotPrint32 = []uint16{ // add 0x10000 to each entry\n")
for _, r := range except32 {
if r >= 0x20000 {
fmt.Fprintf(os.Stderr, "%U too big for isNotPrint32\n", r)
return
}
fmt.Printf("\t%#04x,\n", r-0x10000)
}
fmt.Printf("}\n")
}
示例2: main
func main() {
rang, except := scan(0, 0xFFFF)
range16 = to16(rang)
except16 = to16(except)
range32, except32 = scan(0x10000, unicode.MaxRune)
for i := rune(0); i <= unicode.MaxRune; i++ {
if isPrint(i) != unicode.IsPrint(i) {
fmt.Fprintf(os.Stderr, "%U: isPrint=%v, want %v\n", i, isPrint(i), unicode.IsPrint(i))
return
}
}
fmt.Printf("// DO NOT EDIT. GENERATED BY\n")
fmt.Printf("// go run makeisprint.go >x && mv x isprint.go\n\n")
fmt.Printf("package strconv\n\n")
fmt.Printf("// (%d+%d+%d)*2 + (%d)*4 = %d bytes\n\n",
len(range16), len(except16), len(except32),
len(range32),
(len(range16)+len(except16)+len(except32))*2+
(len(range32))*4)
fmt.Printf("var isPrint16 = []uint16{\n")
for i := 0; i < len(range16); i += 2 {
fmt.Printf("\t%#04x, %#04x,\n", range16[i], range16[i+1])
}
fmt.Printf("}\n\n")
fmt.Printf("var isNotPrint16 = []uint16{\n")
for _, r := range except16 {
fmt.Printf("\t%#04x,\n", r)
}
fmt.Printf("}\n\n")
fmt.Printf("var isPrint32 = []uint32{\n")
for i := 0; i < len(range32); i += 2 {
fmt.Printf("\t%#06x, %#06x,\n", range32[i], range32[i+1])
}
fmt.Printf("}\n\n")
fmt.Printf("var isNotPrint32 = []uint16{ // add 0x10000 to each entry\n")
for _, r := range except32 {
if r >= 0x20000 {
fmt.Fprintf(os.Stderr, "%U too big for isNotPrint32\n", r)
return
}
fmt.Printf("\t%#04x,\n", r-0x10000)
}
fmt.Printf("}\n")
}
示例3: quoteDouble
func quoteDouble(s string) string {
var buf bytes.Buffer
buf.WriteByte('"')
for _, r := range s {
if r == '\\' || r == '"' {
buf.WriteByte('\\')
buf.WriteRune(r)
} else if !unicode.IsPrint(r) {
buf.WriteByte('\\')
if r <= 0xff {
buf.WriteByte('x')
buf.Write(rtohex(r, 2))
} else if r <= 0xffff {
buf.WriteByte('u')
buf.Write(rtohex(r, 4))
} else {
buf.WriteByte('U')
buf.Write(rtohex(r, 8))
}
} else {
buf.WriteRune(r)
}
}
buf.WriteByte('"')
return buf.String()
}
示例4: incrementCount
func incrementCount(r rune, counts map[int]int) {
switch {
case unicode.IsControl(r):
counts[isControl]++
case unicode.IsNumber(r):
counts[isNumber]++
case unicode.IsDigit(r):
counts[isDigit]++
case unicode.IsLetter(r):
counts[isLetter]++
case unicode.IsMark(r):
counts[isMark]++
case unicode.IsPunct(r):
counts[isPunct]++
case unicode.IsSpace(r):
counts[isSpace]++
case unicode.IsSymbol(r):
counts[isSymbol]++
case unicode.IsPrint(r):
counts[isPrint]++
case unicode.IsGraphic(r):
counts[isGraphic]++
}
}
示例5: valid
func valid(id string) error {
if utf8.RuneCountInString(id) == 0 {
return ErrBadID{"Empty ID is not allowed"}
}
if !utf8.ValidString(id) {
return ErrBadID{fmt.Sprintf("Invalid utf-8: %v", id)}
}
for idx, rn := range id {
if unicode.IsSpace(rn) {
return ErrBadID{
fmt.Sprintf("Space not allowed: %s (at %d)", id, idx),
}
}
if !unicode.IsPrint(rn) {
return ErrBadID{
fmt.Sprintf("Only printable runes allowed: %s (at %d)", id, idx),
}
}
}
return nil
}
示例6: CharType
// CharType returns a string representing the unicode type of a rune
func CharType(r rune) string {
switch {
case unicode.IsLetter(r):
return "letter"
case unicode.IsSpace(r):
return "space"
case unicode.IsPunct(r):
return "punct"
case unicode.IsNumber(r):
return "number"
case unicode.IsSymbol(r):
return "symbol"
case unicode.IsMark(r):
return "mark"
case unicode.IsDigit(r):
return "digit"
case unicode.IsPrint(r):
return "print"
case unicode.IsControl(r):
return "control"
case unicode.IsGraphic(r):
return "graphic"
default:
return "invalid"
}
}
示例7: allowedInVariableName
// The following are allowed in variable names:
// * Anything beyond ASCII that is printable
// * Letters and numbers
// * The symbols "-_:"
func allowedInVariableName(r rune) bool {
return (r >= 0x80 && unicode.IsPrint(r)) ||
('0' <= r && r <= '9') ||
('a' <= r && r <= 'z') ||
('A' <= r && r <= 'Z') ||
r == '-' || r == '_' || r == ':'
}
示例8: QuoteAs
// QuoteAs returns a representation of s in elvish syntax, using the syntax
// specified by q, which must be one of Bareword, SingleQuoted, or
// DoubleQuoted. It returns the quoted string and the actual quoting.
func QuoteAs(s string, q PrimaryType) (string, PrimaryType) {
if q == DoubleQuoted {
// Everything can be quoted using double quotes, return directly.
return quoteDouble(s), DoubleQuoted
}
if s == "" {
return "''", SingleQuoted
}
// Keep track of whether it is a valid bareword.
bare := s[0] != '~'
for _, r := range s {
if !unicode.IsPrint(r) {
// Contains unprintable character; force double quote.
return quoteDouble(s), DoubleQuoted
}
if !allowedInBareword(r, false) {
bare = false
}
}
if q == Bareword && bare {
return s, Bareword
}
return quoteSingle(s), SingleQuoted
}
示例9: quoteDouble
func quoteDouble(s string) string {
var buf bytes.Buffer
buf.WriteByte('"')
for _, r := range s {
if e, ok := doubleUnescape[r]; ok {
// Takes care of " and \ as well.
buf.WriteByte('\\')
buf.WriteRune(e)
} else if !unicode.IsPrint(r) {
buf.WriteByte('\\')
if r <= 0xff {
buf.WriteByte('x')
buf.Write(rtohex(r, 2))
} else if r <= 0xffff {
buf.WriteByte('u')
buf.Write(rtohex(r, 4))
} else {
buf.WriteByte('U')
buf.Write(rtohex(r, 8))
}
} else {
buf.WriteRune(r)
}
}
buf.WriteByte('"')
return buf.String()
}
示例10: writeQuotedString
func writeQuotedString(s string, b *bufio.Writer, f *Format) {
b.WriteRune('"')
for i := range s {
c := s[i] // don't decode as runes
switch c {
case '\r':
b.WriteString(`\r`)
case '\n':
b.WriteString(`\n`)
case '\t':
b.WriteString(`\t`)
case '"':
b.WriteString(`\"`)
case '\\':
b.WriteString(`\\`)
default:
if c < 0x80 && unicode.IsPrint(rune(c)) {
b.WriteRune(rune(c))
} else {
b.WriteString(`\x`)
b.WriteRune(enchex((c >> 4) & 0x0F))
b.WriteRune(enchex(c & 0x0F))
}
}
}
b.WriteRune('"')
}
示例11: Stat
// Stat calculates statistics for all runes read from r.
func (m *Main) Stat(r io.RuneReader) (Stats, error) {
var stats Stats
for {
// Read next character.
ch, sz, err := r.ReadRune()
if err == io.EOF {
break
} else if err != nil {
return stats, err
}
// Calculate stats.
stats.TotalN++
if unicode.IsControl(ch) {
stats.ControlN++
}
if unicode.IsDigit(ch) {
stats.DigitN++
}
if unicode.IsGraphic(ch) {
stats.GraphicN++
}
if unicode.IsLetter(ch) {
stats.LetterN++
}
if unicode.IsLower(ch) {
stats.LowerN++
}
if unicode.IsMark(ch) {
stats.MarkN++
}
if unicode.IsNumber(ch) {
stats.NumberN++
}
if unicode.IsPrint(ch) {
stats.PrintN++
}
if unicode.IsPunct(ch) {
stats.PunctN++
}
if unicode.IsSpace(ch) {
stats.SpaceN++
}
if unicode.IsSymbol(ch) {
stats.SymbolN++
}
if unicode.IsTitle(ch) {
stats.TitleN++
}
if unicode.IsUpper(ch) {
stats.UpperN++
}
if sz > 1 {
stats.MultiByteN++
}
}
return stats, nil
}
示例12: Write
func (q *quotedwriter) Write(data []byte) (n int, err error) {
b := q.b
if !q.add {
b = append(b, '"')
q.add = true
}
for _, c := range data {
switch {
case q.esc, c > unicode.MaxASCII:
fallthrough
default:
x := []byte{'\\', 'x', 0, c}
hex.Encode(x[2:], x[3:])
b = append(b, x...)
case c == '"':
b = append(b, '\\', '"')
case c == '\\':
b = append(b, '\\', '\\')
case unicode.IsPrint(rune(c)):
b = append(b, c)
}
}
n, err = q.w.Write(b)
q.b = b[:0]
if err == nil {
if n != len(b) {
err = io.ErrShortWrite
} else {
n = len(data)
}
}
return
}
示例13: handleKeyEvent
func (field_editor *FieldEditor) handleKeyEvent(event termbox.Event) (string, bool) {
is_done := false
if event.Key == termbox.KeyEnter {
is_done = true
} else if event.Key == termbox.KeyEsc {
is_done = true
field_editor.value = nil
} else if event.Key == termbox.KeyArrowLeft {
if field_editor.cursor_pos > 0 {
field_editor.cursor_pos--
}
} else if event.Key == termbox.KeyArrowUp || event.Key == termbox.KeyCtrlA {
field_editor.cursor_pos = 0
} else if event.Key == termbox.KeyArrowRight {
if field_editor.cursor_pos < utf8.RuneCount(field_editor.value) {
field_editor.cursor_pos++
}
} else if event.Key == termbox.KeyArrowDown || event.Key == termbox.KeyCtrlE {
field_editor.cursor_pos = utf8.RuneCount(field_editor.value)
} else if event.Key == termbox.KeyCtrlH || event.Key == termbox.KeyBackspace {
if field_editor.cursor_pos > 0 {
field_editor.value = removeRuneAtIndex(field_editor.value, field_editor.cursor_pos-1)
field_editor.cursor_pos--
}
} else if unicode.IsPrint(event.Ch) {
field_editor.value = insertRuneAtIndex(field_editor.value, field_editor.cursor_pos, event.Ch)
field_editor.cursor_pos++
} else if event.Key == termbox.KeySpace {
field_editor.value = insertRuneAtIndex(field_editor.value, field_editor.cursor_pos, ' ')
field_editor.cursor_pos++
}
return string(field_editor.value), is_done
}
示例14: isPrintableASCII
func isPrintableASCII(s string) bool {
for _, x := range s {
if unicode.IsPrint(x) == false {
return false
}
}
return true
}
示例15: IsAsciiPrintable
// checks if s is ascii and printable, aka doesn't include tab, backspace, etc.
func IsAsciiPrintable(s string) bool {
for _, r := range s {
if r > unicode.MaxASCII || !unicode.IsPrint(r) {
return false
}
}
return true
}