代码拉取完成,页面将自动刷新
package misspell
import (
"strings"
"unicode"
)
// WordCase is an enum of various word casing styles
type WordCase int
// Various WordCase types.. likely to be not correct
const (
AllLower WordCase = iota
AllUpper
Title
Mixed
Camel
)
// CaseStyle returns what case style a word is in
func CaseStyle(word string) WordCase {
hasTitle := false
upperCount := 0
lowerCount := 0
runeCount := 0
// this iterates over RUNES not BYTES
for _, r := range word {
// ASCII apostrophe doesn't count
// want words like "don't" to have
// upper case forms when adding to dictionary
if r == 0x0027 {
continue
}
runeCount++
if unicode.IsLower(r) {
lowerCount++
continue
}
if unicode.IsUpper(r) {
if runeCount == 1 {
hasTitle = true
}
upperCount++
continue
}
//???
}
switch {
case runeCount == lowerCount:
return AllLower
case runeCount == upperCount:
return AllUpper
case hasTitle && runeCount-1 == lowerCount:
return Title
default:
return Mixed
}
}
// CaseVariations returns
// If AllUpper or First-Letter-Only is upcased: add the all upper case version
// If AllLower, add the original, the title and upcase forms
// If Mixed, return the original, and the all upcase form
//
func CaseVariations(word string, style WordCase) []string {
switch style {
case AllLower:
return []string{word, strings.ToUpper(word[0:1]) + word[1:], strings.ToUpper(word)}
case AllUpper:
return []string{strings.ToUpper(word)}
default:
return []string{word, strings.ToUpper(word)}
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。