本文整理汇总了Golang中unicode.IsSymbol函数的典型用法代码示例。如果您正苦于以下问题:Golang IsSymbol函数的具体用法?Golang IsSymbol怎么用?Golang IsSymbol使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了IsSymbol函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: main
func main() {
counts := make(map[rune]int) // counts of Unicode characters
var utflen [utf8.UTFMax + 1]int // count of lengths of UTF-8 encodings
invalid := 0 // count of invalid UTF-8 characters
catCounts := make(map[string]int) // counts per Unicode category
unknown := 0 // count of characters of unknown category
in := bufio.NewReader(os.Stdin)
for {
r, n, err := in.ReadRune() // returns rune, nbytes, error
if err == io.EOF {
break
}
if err != nil {
fmt.Fprintf(os.Stderr, "charcount: %v\n", err)
os.Exit(1)
}
if r == unicode.ReplacementChar && n == 1 {
invalid++
continue
}
counts[r]++
utflen[n]++
switch {
case unicode.IsLetter(r):
catCounts["Letter"]++
case unicode.IsDigit(r):
catCounts["Digit"]++
case unicode.IsSymbol(r):
catCounts["Symbol"]++
case unicode.IsPunct(r):
catCounts["Punct"]++
case unicode.IsSpace(r):
catCounts["Space"]++
default:
unknown++
}
}
fmt.Printf("rune\tcount\n")
for c, n := range counts {
fmt.Printf("%q\t%d\n", c, n)
}
fmt.Print("\nlen\tcount\n")
for i, n := range utflen {
if i > 0 {
fmt.Printf("%d\t%d\n", i, n)
}
}
if invalid > 0 {
fmt.Printf("\n%d invalid UTF-8 characters\n", invalid)
}
fmt.Print("\ncat\tcount\n")
for cat, n := range catCounts {
fmt.Printf("%s\t%d\n", cat, n)
}
if unknown > 0 {
fmt.Printf("\n%d characters of unknown category\n", unknown)
}
}
示例2: synopsis
// synopsis extracts the first sentence from s. All runs of whitespace are
// replaced by a single space.
func synopsis(s string) string {
parts := strings.SplitN(s, "\n\n", 2)
s = parts[0]
var buf []byte
const (
other = iota
period
space
)
last := space
Loop:
for i := 0; i < len(s); i++ {
b := s[i]
switch b {
case ' ', '\t', '\r', '\n':
switch last {
case period:
break Loop
case other:
buf = append(buf, ' ')
last = space
}
case '.':
last = period
buf = append(buf, b)
default:
last = other
buf = append(buf, b)
}
}
// Ensure that synopsis fits an App Engine datastore text property.
const m = 400
if len(buf) > m {
buf = buf[:m]
if i := bytes.LastIndex(buf, []byte{' '}); i >= 0 {
buf = buf[:i]
}
buf = append(buf, " ..."...)
}
s = string(buf)
r, n := utf8.DecodeRuneInString(s)
if n < 0 || unicode.IsPunct(r) || unicode.IsSymbol(r) {
// ignore Markdown headings, editor settings, Go build constraints, and * in poorly formatted block comments.
s = ""
} else {
for _, prefix := range badSynopsisPrefixes {
if strings.HasPrefix(s, prefix) {
s = ""
break
}
}
}
return s
}
示例3: CharCount
// CharCount scans a *bufio.Reader and returns a map of the counts of its
// Unicode character types.
func CharCount(in *bufio.Reader) map[string]int {
counts := make(map[string]int) // counts of Unicode character types
for {
r, n, err := in.ReadRune() // returns rune, nbytes, error
if err == io.EOF {
break
}
if err != nil {
fmt.Fprintf(os.Stderr, "charcount: %v\n", err)
os.Exit(1)
}
switch {
case r == unicode.ReplacementChar && n == 1:
counts["invalid"]++
case unicode.IsControl(r):
counts["control"]++
case unicode.IsLetter(r):
counts["letter"]++
case unicode.IsMark(r):
counts["mark"]++
case unicode.IsNumber(r):
counts["number"]++
case unicode.IsPunct(r):
counts["punct"]++
case unicode.IsSpace(r):
counts["space"]++
case unicode.IsSymbol(r):
counts["symbol"]++
}
}
return counts
}
示例4: isLetter
func isLetter(ch rune) bool {
if ch == '(' || ch == ')' || ch == '\'' || ch == '"' {
return false
}
return unicode.IsLetter(ch) || unicode.IsPunct(ch) || unicode.IsSymbol(ch)
}
示例5: TestRune_IsIndependent
func TestRune_IsIndependent(t *testing.T) {
numbers := make([]rune, 0)
letters := make([]rune, 0)
marks := make([]rune, 0)
symbols := make([]rune, 0)
puncts := make([]rune, 0)
others := make([]rune, 0)
for _, r := range unicode.Myanmar.R16 {
for c := r.Lo; c <= r.Hi; c++ {
switch mr := rune(c); true {
case unicode.IsLetter(mr):
letters = append(letters, mr)
case unicode.IsNumber(mr):
numbers = append(numbers, mr)
case unicode.IsMark(mr):
marks = append(marks, mr)
case unicode.IsPunct(mr):
puncts = append(puncts, mr)
case unicode.IsSymbol(mr):
symbols = append(symbols, mr)
default:
others = append(others, mr)
}
}
}
independents := string(letters) + string(numbers) + string(puncts) + " \t\r\n"
for _, consonant := range independents {
if ok, _ := Rune(consonant).IsIndependent(); !ok {
t.Errorf("[%U] expected result is true, but it returns false", consonant)
}
}
}
示例6: DeEscapeProse
func DeEscapeProse(p md.Prose) md.Prose {
result := make(md.Prose, 0, len(p))
var buf []byte
runs:
for i := 0; i < len(p); i++ {
if buf == nil {
buf = p[i].Bytes
}
for j := 0; ; {
k := bytes.IndexByte(buf[j:], '\\')
if k == -1 {
result = append(result, md.Run{
Line: p[i].Line,
Bytes: buf,
})
buf = nil
continue runs
}
j += k
r, _ := utf8.DecodeRune(buf[j+1:])
if unicode.IsPunct(r) || unicode.IsSymbol(r) {
result = append(result, md.Run{
Line: p[i].Line,
Bytes: buf[:j],
})
buf = buf[j+1:]
i--
continue runs
}
j++
}
}
return result
}
示例7: 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
}
示例8: 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]++
}
}
示例9: 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"
}
}
示例10: ValidatePassword
/*
* Password rules:
* at least 7 letters
* at least 1 number
* at least 1 upper case
* at least 1 special character
*/
func ValidatePassword(value, local string) error {
fmt.Println("Validate password", value)
if len(value) < 7 {
return errors.New(i18n.Translate(local, i18nSec, "text03"))
}
var num, lower, upper, spec bool
for _, r := range value {
switch {
case unicode.IsDigit(r):
num = true
case unicode.IsUpper(r):
upper = true
case unicode.IsLower(r):
lower = true
case unicode.IsSymbol(r), unicode.IsPunct(r):
spec = true
}
}
if num && lower && upper && spec {
return nil
}
return errors.New(i18n.Translate(local, i18nSec, "text03"))
}
示例11: emitIfKeywordMatches
func (l *GutsLex) emitIfKeywordMatches() bool {
l.remember()
for keyword, typ := range LexKeywords {
var match bool = true
next_keyword:
for _, sc := range keyword {
c := l.next()
if c == eof {
match = false
break next_keyword
}
if sc != c {
match = false
break next_keyword
}
}
if match {
c := l.next()
if c == '\n' || c == eof || c == ' ' || c == '\t' || unicode.IsSymbol(c) {
l.backup()
l.emit(TokenType(typ))
return true
}
}
l.rollback()
}
return false
}
示例12: Sanitize
func Sanitize(r rune) rune {
switch {
case unicode.IsPunct(r):
return ' '
case unicode.IsMark(r):
return ' '
case unicode.IsSymbol(r):
return ' '
}
return r
}
示例13: main
func main() {
counts := make(map[string]int)
var utflen [utf8.UTFMax + 1]int
invalid := 0
in := bufio.NewReader(os.Stdin)
for {
r, n, err := in.ReadRune()
if err == io.EOF {
break
}
if err != nil {
fmt.Fprintf(os.Stderr, "charcount: %v\n", err)
os.Exit(1)
}
if r == unicode.ReplacementChar && n == 1 {
invalid++
continue
}
utflen[n]++
switch {
case unicode.IsLetter(r):
counts["Letter"]++
case unicode.IsMark(r):
counts["Mark"]++
case unicode.IsNumber(r):
counts["Number"]++
case unicode.IsPunct(r):
counts["Punct"]++
case unicode.IsSymbol(r):
counts["Symbol"]++
case unicode.IsSpace(r):
counts["Space"]++
default:
counts["Other"]++
}
}
fmt.Printf("rune\tcount\n")
for c, n := range counts {
fmt.Printf("%s\t%d\n", c, n)
}
fmt.Print("\nlen\tcount\n")
for i, n := range utflen {
if i > 0 {
fmt.Printf("%d\t%d\n", i, n)
}
}
if invalid > 0 {
fmt.Printf("\n%d invalid UTF-8 characters\n", invalid)
}
}
示例14: main
func main() {
in := bufio.NewReader(os.Stdin)
counts := make(map[string]int) // counts of Unicode character types
var utflen [utf8.UTFMax + 1]int // count of lengths of UTF-8 encodings
invalid := 0 // count of invalid UTF-8 characters
for {
r, n, err := in.ReadRune() // returns rune, nbytes, error
if err == io.EOF {
break
}
if err != nil {
fmt.Fprintf(os.Stderr, "charcount: %v\n", err)
os.Exit(1)
}
if r == unicode.ReplacementChar && n == 1 {
invalid++
continue
}
switch {
case unicode.IsControl(r):
counts["control"]++
case unicode.IsLetter(r):
counts["letter"]++
case unicode.IsMark(r):
counts["mark"]++
case unicode.IsNumber(r):
counts["number"]++
case unicode.IsPunct(r):
counts["punct"]++
case unicode.IsSpace(r):
counts["space"]++
case unicode.IsSymbol(r):
counts["symbol"]++
}
utflen[n]++
}
fmt.Printf("rune\tcount\n")
for c, n := range counts {
fmt.Printf("%q\t%d\n", c, n)
}
fmt.Print("\nlen\tcount\n")
for i, n := range utflen {
if i > 0 {
fmt.Printf("%d\t%d\n", i, n)
}
}
if invalid > 0 {
fmt.Printf("\n%d invalid UTF-8 characters\n", invalid)
}
}
示例15: main
func main() {
counts := make(map[rune]int) // counts of Unicode characters
var utflen [utf8.UTFMax]int // count of lengths of UTF-8 encodings
invalid := 0 // count of invalid UTF-8 characters
cats := make(map[string]int) // counts of Unicode categories
// In a terminal, use CTRL+Z at line start to signal EOF with ENTER.
in := bufio.NewReader(os.Stdin)
for {
r, n, err := in.ReadRune() // returns rune, nbytes, error
if err == io.EOF {
break
}
if err != nil {
fmt.Fprintf(os.Stderr, "charcount: %v\n", err)
os.Exit(1)
}
if r == unicode.ReplacementChar && n == 1 {
invalid++
continue
}
switch {
case unicode.IsLetter(r):
cats["letter"]++
case unicode.IsDigit(r):
cats["digit"]++
case unicode.IsControl(r):
cats["control"]++
case unicode.IsMark(r):
cats["mark"]++
case unicode.IsPunct(r):
cats["punct"]++
case unicode.IsSymbol(r):
cats["symbol"]++
}
counts[r]++
utflen[n-1]++
}
fmt.Printf("rune\tcount\n")
for c, n := range counts {
fmt.Printf("%q\t%d\n", c, n)
}
fmt.Print("\nlen\tcount\n")
for i, n := range utflen {
fmt.Printf("%d\t%d\n", i+1, n)
}
fmt.Print("\ncat\tcount\n")
for s, n := range cats {
fmt.Printf("%v\t%d\n", s, n)
}
fmt.Printf("\n%d invalid UTF-8 characters\n", invalid)
}