github.com/pbberlin/tools@v0.0.0-20160910141205-7aa5421c2169/os/fsi/dsfs/string_inc.go (about) 1 package dsfs 2 3 import ( 4 "fmt" 5 "unicode/utf8" 6 ) 7 8 func IncrementString(s string) string { 9 10 if s == "" { 11 panic("Increment String is undefined for an empty string") 12 } 13 14 uTFCodePointLastChar, itsSize := utf8.DecodeLastRuneInString(s) 15 if uTFCodePointLastChar == utf8.RuneError { 16 panic(fmt.Sprint("Following string is invalid utf8: %q", s)) 17 } 18 sReduced := s[:len(s)-itsSize] 19 20 uTFCodePointLastChar++ 21 oneHigherChar := fmt.Sprintf("%c", uTFCodePointLastChar) 22 23 return sReduced + oneHigherChar 24 25 }