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


Golang unicode.IsPrint函數代碼示例

本文整理匯總了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")
}
開發者ID:h8liu,項目名稱:golang,代碼行數:54,代碼來源:makeisprint.go

示例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")
}
開發者ID:ZeusbasePython,項目名稱:appscale,代碼行數:51,代碼來源:makeisprint.go

示例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()
}
開發者ID:rathinaganesh,項目名稱:elvish,代碼行數:26,代碼來源:parse.go

示例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]++
	}

}
開發者ID:alexchowle,項目名稱:tgpl,代碼行數:34,代碼來源:charcount.go

示例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
}
開發者ID:disorganizer,項目名稱:brig,代碼行數:25,代碼來源:id.go

示例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"
	}
}
開發者ID:aliwatters,項目名稱:go-course-02,代碼行數:27,代碼來源:ex4.8.go

示例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 == ':'
}
開發者ID:rathinaganesh,項目名稱:elvish,代碼行數:11,代碼來源:parse.go

示例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
}
開發者ID:yonglehou,項目名稱:elvish,代碼行數:29,代碼來源:quote.go

示例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()
}
開發者ID:yonglehou,項目名稱:elvish,代碼行數:27,代碼來源:quote.go

示例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('"')
}
開發者ID:hlandau,項目名稱:sx,代碼行數:27,代碼來源:sx.go

示例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
}
開發者ID:boutros,項目名稱:unistat,代碼行數:61,代碼來源:main.go

示例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
}
開發者ID:extemporalgenome,項目名稱:randat,代碼行數:33,代碼來源:string.go

示例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
}
開發者ID:jmptrader,項目名稱:hecate,代碼行數:33,代碼來源:field_editor.go

示例14: isPrintableASCII

func isPrintableASCII(s string) bool {
	for _, x := range s {
		if unicode.IsPrint(x) == false {
			return false
		}
	}
	return true
}
開發者ID:Safe3,項目名稱:oz,代碼行數:8,代碼來源:util.go

示例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
}
開發者ID:sheeeng,項目名稱:sandbox,代碼行數:9,代碼來源:getproductkey.go


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