本文整理汇总了Golang中unicode.IsLower函数的典型用法代码示例。如果您正苦于以下问题:Golang IsLower函数的具体用法?Golang IsLower怎么用?Golang IsLower使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了IsLower函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: LookupString
// LookupString attempts to convert a (modifiers, keycode) to an english string.
// It essentially implements the rules described at http://goo.gl/qum9q
// Namely, the bulleted list that describes how key syms should be interpreted
// when various modifiers are pressed.
// Note that we ignore the logic that asks us to check if particular key codes
// are mapped to particular modifiers (i.e., "XK_Caps_Lock" to "Lock" modifier).
// We just check if the modifiers are activated. That's good enough for me.
// XXX: We ignore num lock stuff.
// XXX: We ignore MODE SWITCH stuff. (i.e., we don't use group 2 key syms.)
func LookupString(xu *xgbutil.XUtil, mods uint16,
keycode xproto.Keycode) string {
k1, k2, _, _ := interpretSymList(xu, keycode)
shift := mods&xproto.ModMaskShift > 0
lock := mods&xproto.ModMaskLock > 0
switch {
case !shift && !lock:
return k1
case !shift && lock:
if len(k1) == 1 && unicode.IsLower(rune(k1[0])) {
return k2
} else {
return k1
}
case shift && lock:
if len(k2) == 1 && unicode.IsLower(rune(k2[0])) {
return string(unicode.ToUpper(rune(k2[0])))
} else {
return k2
}
case shift:
return k2
}
return ""
}
示例2: camelize
func camelize(str string) string {
runes := []rune(str)
w, i := 0, 0
for i+1 <= len(runes) {
eow := false
if i+1 == len(runes) {
eow = true
} else if !validIdentifier(runes[i]) {
runes = append(runes[:i], runes[i+1:]...)
} else if spacer(runes[i+1]) {
eow = true
n := 1
for i+n+1 < len(runes) && spacer(runes[i+n+1]) {
n++
}
copy(runes[i+1:], runes[i+n+1:])
runes = runes[:len(runes)-n]
} else if unicode.IsLower(runes[i]) && !unicode.IsLower(runes[i+1]) {
eow = true
}
i++
if !eow {
continue
}
runes[w] = unicode.ToUpper(runes[w])
w = i
}
return string(runes)
}
示例3: lintName
// lintName returns a different name if it should be different.
func lintName(name string) (should string) {
// Fast path for simple cases: "_" and all lowercase.
if name == "_" {
return name
}
allLower := true
for _, r := range name {
if !unicode.IsLower(r) {
allLower = false
break
}
}
if allLower {
return name
}
// Split camelCase at any lower->upper transition, and split on underscores.
// Check each word for common initialisms.
runes := []rune(name)
w, i := 0, 0 // index of start of word, scan
for i+1 <= len(runes) {
eow := false // whether we hit the end of a word
if i+1 == len(runes) {
eow = true
} else if runes[i+1] == '_' {
// underscore; shift the remainder forward over any run of underscores
eow = true
n := 1
for i+n+1 < len(runes) && runes[i+n+1] == '_' {
n++
}
copy(runes[i+1:], runes[i+n+1:])
runes = runes[:len(runes)-n]
} else if unicode.IsLower(runes[i]) && !unicode.IsLower(runes[i+1]) {
// lower->non-lower
eow = true
}
i++
if !eow {
continue
}
// [w,i) is a word.
word := string(runes[w:i])
if u := strings.ToUpper(word); commonInitialisms[u] {
// Keep consistent case, which is lowercase only at the start.
if w == 0 && unicode.IsLower(runes[w]) {
u = strings.ToLower(u)
}
// All the common initialisms are ASCII,
// so we can replace the bytes exactly.
copy(runes[w:], []rune(u))
} else if w > 0 && strings.ToLower(word) == word {
// already all lowercase, and not the first word, so uppercase the first character.
runes[w] = unicode.ToUpper(runes[w])
}
w = i
}
return string(runes)
}
示例4: Goify
// Goify makes a valid Go identifier out of any string.
// It does that by removing any non letter and non digit character and by making sure the first
// character is a letter or "_".
// Goify produces a "CamelCase" version of the string, if firstUpper is true the first character
// of the identifier is uppercase otherwise it's lowercase.
func Goify(str string, firstUpper bool) string {
runes := []rune(str)
w, i := 0, 0 // index of start of word, scan
for i+1 <= len(runes) {
eow := false // whether we hit the end of a word
if i+1 == len(runes) {
eow = true
} else if !validIdentifier(runes[i]) {
// get rid of it
runes = append(runes[:i], runes[i+1:]...)
} else if runes[i+1] == '_' {
// underscore; shift the remainder forward over any run of underscores
eow = true
n := 1
for i+n+1 < len(runes) && runes[i+n+1] == '_' {
n++
}
copy(runes[i+1:], runes[i+n+1:])
runes = runes[:len(runes)-n]
} else if unicode.IsLower(runes[i]) && !unicode.IsLower(runes[i+1]) {
// lower->non-lower
eow = true
}
i++
if !eow {
continue
}
// [w,i] is a word.
word := string(runes[w:i])
// is it one of our initialisms?
if u := strings.ToUpper(word); commonInitialisms[u] {
if firstUpper {
u = strings.ToUpper(u)
}
// All the common initialisms are ASCII,
// so we can replace the bytes exactly.
copy(runes[w:], []rune(u))
} else if w > 0 && strings.ToLower(word) == word {
// already all lowercase, and not the first word, so uppercase the first character.
runes[w] = unicode.ToUpper(runes[w])
} else if w == 0 && strings.ToLower(word) == word && firstUpper {
runes[w] = unicode.ToUpper(runes[w])
}
if w == 0 && !firstUpper {
runes[w] = unicode.ToLower(runes[w])
}
//advance to next word
w = i
}
res := string(runes)
if _, ok := reserved[res]; ok {
res += "_"
}
return res
}
示例5: Rename
func Rename(filename string, line int, column int, newName string) (ok bool, err *errors.GoRefactorError) {
if ok, err = CheckRenameParameters(filename, line, column, newName); !ok {
return
}
programTree := parseProgram(filename)
var sym st.Symbol
if sym, err = programTree.FindSymbolByPosition(filename, line, column); err == nil {
if _, ok := sym.(*st.PointerTypeSymbol); ok {
panic("find by position returned pointer type!!!")
}
if st.IsPredeclaredIdentifier(sym.Name()) {
return false, errors.UnrenamableIdentifierError(sym.Name(), " It's a basic language symbol")
}
if sym.PackageFrom().IsGoPackage {
return false, errors.UnrenamableIdentifierError(sym.Name(), " It's a symbol,imported from go library")
}
if unicode.IsUpper(int(sym.Name()[0])) && !unicode.IsUpper(int(newName[0])) ||
unicode.IsLower(int(sym.Name()[0])) && !unicode.IsLower(int(newName[0])) {
return false, &errors.GoRefactorError{ErrorType: "Can't rename identifier", Message: "can't change access modifier. Changing first letter's case can cause errors."}
}
if _, ok := sym.Scope().LookUp(newName, filename); ok {
return false, errors.IdentifierAlreadyExistsError(newName)
}
if meth, ok := sym.(*st.FunctionSymbol); ok {
if meth.IsInterfaceMethod {
return false, errors.UnrenamableIdentifierError(sym.Name(), " It's an interface method")
}
}
if ps, ok := sym.(*st.PackageSymbol); ok {
pack, file := programTree.FindPackageAndFileByFilename(filename)
impDecl := findImportDecl(pack, file, ps)
if impDecl == nil {
panic("couldn't find import decl")
}
if impDecl.Name == nil || impDecl.Name.Name == "" {
impDecl.Name = ast.NewIdent(newName)
}
}
fnames, fsets, files, err := renameSymbol(sym, newName, programTree)
if err == nil {
for i, f := range fnames {
programTree.SaveFileExplicit(f, fsets[i], files[i])
}
}
return err == nil, err
} else {
return false, err
}
panic("unreachable code")
}
示例6: toSnake
func toSnake(s string) string {
in := []rune(s)
out := make([]rune, 0, len(in))
for i, c := range in {
if i > 0 && unicode.IsUpper(c) && ((i+1 < len(in) && unicode.IsLower(in[i+1])) || unicode.IsLower(in[i-1])) {
out = append(out, '_')
}
out = append(out, unicode.ToLower(c))
}
return string(out)
}
示例7: TestName
func (f *Function) TestName() string {
if f.Receiver != nil {
receiverType := f.Receiver.Type.Value
if unicode.IsLower([]rune(receiverType)[0]) {
receiverType = "_" + receiverType
}
return "Test" + receiverType + "_" + f.Name
}
if unicode.IsLower([]rune(f.Name)[0]) {
return "Test_" + f.Name
}
return "Test" + f.Name
}
示例8: test_password
func test_password(pass string) bool {
// Windows AD password needs at leat 7 characters password, and must contain characters from three of the following five categories:
// uppercase character
// lowercase character
// digit character
// nonalphanumeric characters
// any Unicode character that is categorized as an alphabetic character but is not uppercase or lowercase
if len(pass) < 7 {
return false
}
d := 0
l := 0
u := 0
p := 0
o := 0
for _, c := range pass {
if unicode.IsDigit(c) { // check digit character
d = 1
} else if unicode.IsLower(c) { // check lowercase character
l = 1
} else if unicode.IsUpper(c) { // check uppercase character
u = 1
} else if unicode.IsPunct(c) { // check nonalphanumeric character
p = 1
} else { // other unicode character
o = 1
}
}
if d+l+u+p+o < 3 {
return false
}
return true
}
示例9: 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
}
示例10: SnakeCase
// SnakeCase produces the snake_case version of the given CamelCase string.
func SnakeCase(name string) string {
for u, l := range toLower {
name = strings.Replace(name, u, l, -1)
}
var b bytes.Buffer
var lastUnderscore bool
ln := len(name)
if ln == 0 {
return ""
}
b.WriteRune(unicode.ToLower(rune(name[0])))
for i := 1; i < ln; i++ {
r := rune(name[i])
nextIsLower := false
if i < ln-1 {
n := rune(name[i+1])
nextIsLower = unicode.IsLower(n) && unicode.IsLetter(n)
}
if unicode.IsUpper(r) {
if !lastUnderscore && nextIsLower {
b.WriteRune('_')
lastUnderscore = true
}
b.WriteRune(unicode.ToLower(r))
} else {
b.WriteRune(r)
lastUnderscore = false
}
}
return b.String()
}
示例11: lexTopLevel
func lexTopLevel(l *lexer) stateFn {
for l.pos < len(l.input) {
r, rlen := l.runeAt(l.start)
l.pos += rlen
simpleType, isSimple := simpleTokens[r]
switch {
case isSimple:
l.emit(simpleType)
case unicode.IsSpace(r):
l.start += rlen
case unicode.IsUpper(r):
return lexVariable
case unicode.IsLower(r):
return lexSimpleAtom
case r == ':':
next, _ := l.runeAt(l.pos)
if next == '-' {
l.pos += 1
l.emit(TknColonDash)
continue
}
fallthrough
}
}
return nil
}
示例12: encodeStruct
func encodeStruct(t reflect.Type) interface{} {
var fields []eField
for i := 0; i < t.NumField(); i++ {
f := t.Field(i)
if len(f.Name) > 0 {
r, _ := utf8.DecodeRuneInString(f.Name)
if unicode.IsLower(r) {
continue
}
}
if f.Tag.Get("msgpack") == "ignore" {
continue
}
if f.Anonymous {
f.Name = f.Type.Name()
}
e := eField{
offset: f.Offset,
name: f.Name,
encode: getTypeEncoder(f.Type),
index: f.Index,
}
_, e.needsReflect = e.encode.(encodeReflectFunc)
fields = append(fields, e)
}
var b []byte
l := uint64(len(fields))
switch {
case l <= 15:
b = make([]byte, 1)
b[0] = 0x80 | byte(l)
case l <= 0xFFFF:
b = make([]byte, 3)
b[0] = 0xDE
binary.BigEndian.PutUint16(b[1:], uint16(l))
case l <= 0xFFFFFFFF:
b = make([]byte, 5)
b[0] = 0xDF
binary.BigEndian.PutUint32(b[1:], uint32(l))
}
return encodeReflectFunc(func(enc *Encoder, v reflect.Value) error {
p := v.UnsafeAddr()
enc.w.Write(b)
for _, e := range fields {
_encodeString(enc, unsafe.Pointer(&e.name))
if !e.needsReflect {
encode := e.encode.(encodeFunc)
if err := encode(enc, unsafe.Pointer(p+e.offset)); err != nil {
return err
}
} else {
encode := e.encode.(encodeReflectFunc)
if err := encode(enc, v.FieldByIndex(e.index)); err != nil {
return err
}
}
}
return nil
})
}
示例13: processPackageTestFiles
// processPackageTestFiles runs through ast of each test
// file pack and looks for godog suite contexts to register
// on run
func processPackageTestFiles(packs ...[]string) ([]string, error) {
var ctxs []string
fset := token.NewFileSet()
for _, pack := range packs {
for _, testFile := range pack {
node, err := parser.ParseFile(fset, testFile, nil, 0)
if err != nil {
return ctxs, err
}
ctxs = append(ctxs, astContexts(node)...)
}
}
var failed []string
for _, ctx := range ctxs {
runes := []rune(ctx)
if unicode.IsLower(runes[0]) {
expected := append([]rune{unicode.ToUpper(runes[0])}, runes[1:]...)
failed = append(failed, fmt.Sprintf("%s - should be: %s", ctx, string(expected)))
}
}
if len(failed) > 0 {
return ctxs, fmt.Errorf("godog contexts must be exported:\n\t%s", strings.Join(failed, "\n\t"))
}
return ctxs, nil
}
示例14: camelCaseToSnakeCase
func camelCaseToSnakeCase(name string) string {
buf := new(bytes.Buffer)
runes := []rune(name)
for i := 0; i < len(runes); i++ {
buf.WriteRune(unicode.ToLower(runes[i]))
if i != len(runes)-1 && unicode.IsUpper(runes[i+1]) &&
(unicode.IsLower(runes[i]) || unicode.IsDigit(runes[i]) ||
(i != len(runes)-2 && unicode.IsLower(runes[i+2]))) {
buf.WriteRune('_')
}
}
return buf.String()
}
示例15: UnderscoreMapper
// UnderscoreMapper converts CamelCase strings to their camel_case
// counterpart
func UnderscoreMapper(str string) string {
var (
parts = []string{}
cur = []rune{}
last2 = [2]rune{}
)
for _, c := range str {
if unicode.IsUpper(c) {
if last2[1] != 0 && unicode.IsLower(last2[1]) {
parts = append(parts, string(cur))
cur = nil
}
cur = append(cur, unicode.ToLower(c))
} else {
if last2[0] != 0 && last2[1] != 0 && unicode.IsUpper(last2[0]) && unicode.IsUpper(last2[1]) {
parts = append(parts, string(cur[:len(cur)-1]))
cur = []rune{cur[len(cur)-1]}
}
cur = append(cur, c)
}
last2[0] = last2[1]
last2[1] = c
}
if len(cur) > 0 {
parts = append(parts, string(cur))
}
return strings.Join(parts, "_")
}