本文整理汇总了Golang中unicode.IsNumber函数的典型用法代码示例。如果您正苦于以下问题:Golang IsNumber函数的具体用法?Golang IsNumber怎么用?Golang IsNumber使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了IsNumber函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: parseDateFormat
func parseDateFormat(format string) []string {
format = strings.TrimSpace(format)
start := 0
seps := []string{}
for i := 0; i < len(format); i++ {
// Date format must start and end with number.
if i == 0 || i == len(format)-1 {
if !unicode.IsNumber(rune(format[i])) {
return nil
}
continue
}
// Separator is a single none-number char.
if !unicode.IsNumber(rune(format[i])) {
if !unicode.IsNumber(rune(format[i-1])) {
return nil
}
seps = append(seps, format[start:i])
start = i + 1
}
}
seps = append(seps, format[start:])
return seps
}
示例2: isFloatNumber
func isFloatNumber(s string) bool {
if len(s) == 0 {
return false
}
if !unicode.IsNumber(rune(s[0])) {
return false
}
already_encountered := false
if s[0] == '0' {
return s[1] == '.'
} else {
for _, r := range s {
if !unicode.IsNumber(r) && r != '.' {
return false
}
if r == '.' {
if already_encountered {
return false
} else {
already_encountered = true
}
}
}
}
return true
}
示例3: CheckRuneType
func CheckRuneType(last, current rune) index.RuneType {
if isTermSep(current) {
return index.TokenSep
}
if current > 128 {
return index.TokenStart
}
if unicode.IsLetter(current) {
if unicode.IsLetter(last) {
return index.TokenBody
}
return index.TokenStart
}
if unicode.IsNumber(current) {
if unicode.IsNumber(last) {
return index.TokenBody
}
return index.TokenStart
}
return index.TokenStart
}
示例4: get_identifier
func get_identifier(s string, sk *Stack) (rs string, ri int) {
i := 0
if s == "" {
ri = 1
return
}
iLen := len(s)
// fmt.Printf("@@@%[email protected]@@\n", s)
con := true
for i < iLen && con {
switch {
case unicode.IsLetter(rune(s[i])), unicode.IsNumber(rune(s[i])), s[i] == '_':
i++
for i < iLen {
if unicode.IsLetter(rune(s[i])) || unicode.IsNumber(rune(s[i])) || s[i] == '_' {
i++
} else {
break
}
}
con = false
case s[i] == ' ', s[i] == '\t':
i++
default:
con = false
i++
}
}
// time.Sleep(time.Second)
ts := s[:i]
s1 := strings.Trim(ts, " ")
s = s[i:]
sk.Push(s1)
rs = s
switch s1 {
case "":
ri = -1
case "char", "short", "int", "long", "float", "double", "auto", "signed", "unsigned", "const", "volatile", "static", "enum", "struct", "union", "void":
ri = -1
default:
if !unicode.IsLetter(rune(s1[0])) && s1[0] != '_' {
ri = -1
} else {
ri = 0
}
}
return
// fmt.Printf("<<<%d|%s|%s|%d>>>\n", iLen, ts[:i], ts[i:], i)
}
示例5: 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
}
示例6: readBlkioValues
// readDeviceValues reads values from a single blkio file.
// It expects to read values like "245:1 read 18880" or "254:1 1909". It returns
// an array containing an entry for each valid line read.
func readBlkioValues(path ...string) ([]blkioValue, error) {
f, err := os.Open(filepath.Join(path...))
if err != nil {
if os.IsNotExist(err) {
return nil, nil
}
return nil, err
}
defer f.Close()
var values []blkioValue
sc := bufio.NewScanner(f)
for sc.Scan() {
line := strings.TrimSpace(sc.Text())
if len(line) == 0 {
continue
}
// Valid lines start with a device ID.
if !unicode.IsNumber(rune(line[0])) {
continue
}
v, err := parseBlkioValue(sc.Text())
if err != nil {
return nil, err
}
values = append(values, v)
}
return values, nil
}
示例7: 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"
}
}
示例8: Escape
// Escape escapes the given data to make sure it is safe to use it as a
// filename. It also replaces spaces and other seperation characters
// with the '-' character. It returns an error if the escaped string is
// empty.
func Escape(name string) (escaped string, err error) {
mfunc := func(r rune) rune {
switch {
case unicode.IsLetter(r):
return r
case unicode.IsNumber(r):
return r
case unicode.IsSpace(r):
return '-'
case unicode.IsPunct(r):
return '-'
}
return -1
}
escaped = strings.Map(mfunc, html.UnescapeString(name))
for strings.Contains(escaped, "--") {
escaped = strings.Replace(escaped, "--", "-", -1)
}
escaped = strings.TrimPrefix(escaped, "-")
escaped = strings.TrimSuffix(escaped, "-")
if len(escaped) <= 0 {
err = errors.New("couldn't escape title")
}
return
}
示例9: validateId
func validateId(id string, allowEmpty bool, idName string, errors map[string][]error) (newId string, err error) {
if idName == "" {
idName = "id"
}
newId = strings.TrimSpace(id)
if newId == "" {
if !allowEmpty {
err = ERR_MUST_SPECIFY_ID
}
}
if err == nil {
for _, rune := range newId {
switch {
case unicode.IsLetter(rune), unicode.IsNumber(rune):
default:
switch rune {
case '/', '-', '_', '@', '.':
default:
err = ERR_INVALID_ID
}
}
if err != nil {
break
}
}
}
if err != nil && errors != nil {
errors[idName] = []error{err}
}
return
}
示例10: Atbash
//Atbash implements atbash cypher
func Atbash(s string) (cypher string) {
s = strings.ToLower(s)
// s = strings.Replace(s, " ", "", -1)
var code []string
var block int
for _, v := range s {
if unicode.IsLetter(v) || unicode.IsNumber(v) {
if block == 5 {
code = append(code, DELIMITER)
block = 0
}
if unicode.IsLetter(v) {
index := v - 'a'
cypherIndex := (('z' - 'a') - index)
code = append(code, string(cypherIndex+'a'))
} else {
code = append(code, string(v))
}
block++
}
}
cypher = strings.Join(code, "")
return
}
示例11: parse12HourClock
// parse12HourClock convers 12-hour clock time to 24-hour one.
func parse12HourClock(word string) (time.Time, error) {
lower := strings.ToLower(word)
now := time.Now().In(time.Local)
start := 0
hour := 0
var err error
for width := 0; start < len(lower); start += width {
var r rune
r, width = utf8.DecodeRuneInString(lower[start:])
if !unicode.IsNumber(r) {
hour, err = strconv.Atoi(lower[:start])
if err != nil || hour > 12 || hour < 0 {
return time.Now(), fmt.Errorf("Wrong hour: %v", word)
}
if string(lower[start:]) == "am" {
break
}
if string(lower[start:]) == "pm" {
hour += 12
break
}
return time.Now(), fmt.Errorf("Unsupported 12 hour clock notation: %v", word)
}
}
return time.Date(now.Year(), now.Month(), now.Day(), hour, 0, 0, 0, time.Local), nil
}
示例12: scanWord
func (this *Scanner) scanWord(token *TokenType, lexeme *string, tabIndex *int) {
var char = this.lookahead
for char != endOfFile && (unicode.IsLetter(char) || unicode.IsNumber(char)) {
*lexeme += string(char)
char = this.getc()
}
//Put back last invalid character
this.ungetc(char)
//Set lookahead for next lexeme
this.lookahead = this.firstChar()
//Finally check the symbol table for correctness
/*
* If the lexeme is already in the symbol table,
* return its tokenclass. If it isn't, it must
* be an identifier whose type we do not know yet.
*/
if this.St.Installname(*lexeme, tabIndex) {
*token = this.St.gettok_class(*tabIndex)
} else {
this.St.Setattrib(*tabIndex, Stunknown, Tokidentifier)
*token = Tokidentifier
}
}
示例13: lexId
func (x *exprLex) lexId(yylval *exprSymType) int {
var b bytes.Buffer
for {
c := x.next()
if c == lexEOF {
break
}
// If this isn't a character we want in an ID, return out.
// One day we should make this a regexp.
if c != '_' &&
c != '-' &&
c != '.' &&
c != '*' &&
!unicode.IsLetter(c) &&
!unicode.IsNumber(c) {
x.backup()
break
}
if _, err := b.WriteRune(c); err != nil {
log.Printf("ERR: %s", err)
return lexEOF
}
}
yylval.str = b.String()
return IDENTIFIER
}
示例14: valid_identifier_rune
func valid_identifier_rune(r rune) bool {
if unicode.IsLetter(r) || unicode.IsNumber(r) || r == rune('-') || r == rune('_') {
return true
} else {
return false
}
}
示例15: readNumber
func (self *Tokenizer) readNumber() (token int, lit string) {
buffer := make([]rune, 0, 1)
isFloat := false
sawDecimal := false
firstChar := true
for !self.isEof() {
ch := rune(self.CurrentCh)
if ch == '.' && !sawDecimal {
isFloat = true
sawDecimal = true
buffer = append(buffer, self.CurrentCh)
self.Advance()
} else if firstChar && ch == '-' {
buffer = append(buffer, self.CurrentCh)
self.Advance()
} else if unicode.IsNumber(ch) {
buffer = append(buffer, self.CurrentCh)
self.Advance()
} else {
break
}
firstChar = false
}
lit = string(buffer)
if isFloat {
token = FLOAT
} else {
token = NUMBER
}
return
}