"Golang, Go : what is rune by the way?" erwähnt:
Mit der jüngsten Unicode 6.3 gibt es mehr als 110.000 Symbole definiert. Dies erfordert mindestens 21-Bit-Darstellung jedes Codepunkts, so dass eine Rune wie Int32 ist und viele Bits hat.
Aber in Bezug auf die Überlauf oder einen negativen Wert Probleme, beachten Sie, dass die Umsetzung einiger der Unicode-Funktionen wie unicode.IsGraphic verstehen:
Wir konvertieren uint32
den zusätzlichen Test für negative
zu vermeiden
Code:
const MaxLatin1 = '\u00FF' // maximum Latin-1 value.
// IsGraphic reports whether the rune is defined as a Graphic by Unicode.
// Such characters include letters, marks, numbers, punctuation, symbols, and
// spaces, from categories L, M, N, P, S, Zs.
func IsGraphic(r rune) bool {
// We convert to uint32 to avoid the extra test for negative,
// and in the index we convert to uint8 to avoid the range check.
if uint32(r) <= MaxLatin1 {
return properties[uint8(r)]&pg != 0
}
return In(r, GraphicRanges...)
}
Das vielleicht weil eine Rune soll constant sein (wie in „Go rune type explanation“ erwähnt, wo eine Rune in einem sein könnte int32
oder uint32
oder sogar float32
oder ...: sein konstant Wert autorisiert es in einen der gespeichert werden diese numeric types).
Hinweis: 'byte' ist ein Alias für' uint8', nicht 'uint'. –