mirror of
https://github.com/wneessen/apg-go.git
synced 2024-09-19 03:12:47 +02:00
Winni Neessen
0bb1b6c09b
Implemented a new function 'GroupCharsForMobile' in the 'apg' package, which groups characters in a mobile-friendly manner based on their Unicode category. Accompanying tests for this function have also been created in 'grouping_test.go'. This update enhances password readability on mobile devices.
23 lines
735 B
Go
23 lines
735 B
Go
package apg
|
|
|
|
import "unicode"
|
|
|
|
// GroupCharsForMobile takes a given string of characters and groups them in a mobile-friendly
|
|
// manner. The grouping is based on the following precedense: uppercase, lowercase, numbers
|
|
// and special characters. The grouped string is then returned.
|
|
func GroupCharsForMobile(chars string) string {
|
|
var uppers, lowers, numbers, others []rune
|
|
for _, char := range chars {
|
|
switch {
|
|
case unicode.IsUpper(char):
|
|
uppers = append(uppers, char)
|
|
case unicode.IsLower(char):
|
|
lowers = append(lowers, char)
|
|
case unicode.IsNumber(char):
|
|
numbers = append(numbers, char)
|
|
default:
|
|
others = append(others, char)
|
|
}
|
|
}
|
|
return string(uppers) + string(lowers) + string(numbers) + string(others)
|
|
}
|