2016-10-14 10:37:30 +03:00
|
|
|
package internal
|
|
|
|
|
2017-02-01 11:36:33 +03:00
|
|
|
import "reflect"
|
|
|
|
|
2016-10-14 10:37:30 +03:00
|
|
|
func ToLower(s string) string {
|
|
|
|
if isLower(s) {
|
|
|
|
return s
|
|
|
|
}
|
|
|
|
|
|
|
|
b := make([]byte, len(s))
|
|
|
|
for i := range b {
|
|
|
|
c := s[i]
|
|
|
|
if c >= 'A' && c <= 'Z' {
|
|
|
|
c += 'a' - 'A'
|
|
|
|
}
|
|
|
|
b[i] = c
|
|
|
|
}
|
2017-01-13 14:39:59 +03:00
|
|
|
return BytesToString(b)
|
2016-10-14 10:37:30 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
func isLower(s string) bool {
|
|
|
|
for i := 0; i < len(s); i++ {
|
|
|
|
c := s[i]
|
|
|
|
if c >= 'A' && c <= 'Z' {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true
|
|
|
|
}
|
2017-02-01 11:36:33 +03:00
|
|
|
|
|
|
|
func SliceNextElem(v reflect.Value) reflect.Value {
|
|
|
|
if v.Len() < v.Cap() {
|
|
|
|
v.Set(v.Slice(0, v.Len()+1))
|
|
|
|
return v.Index(v.Len() - 1)
|
|
|
|
}
|
|
|
|
|
|
|
|
elemType := v.Type().Elem()
|
|
|
|
|
|
|
|
if elemType.Kind() == reflect.Ptr {
|
|
|
|
elem := reflect.New(elemType.Elem())
|
|
|
|
v.Set(reflect.Append(v, elem))
|
|
|
|
return elem.Elem()
|
|
|
|
}
|
|
|
|
|
|
|
|
v.Set(reflect.Append(v, reflect.Zero(elemType)))
|
|
|
|
return v.Index(v.Len() - 1)
|
|
|
|
}
|