Repository: zyedidia/micro
File: internal/util/util.go (Go)

Code before:
func IsNoneWordChar(r rune) bool {
	return !IsAlphanumeric(r) && !IsWhitespace(r) && !IsWordDelimiter(r)
}

// IsAlphanumeric returns whether or not the string is an 'alphanumeric character'
// Alphanumeric characters are defined as numbers or letters ([A-Za-z0-9])
func IsAlphanumeric(r rune) bool {
	return unicode.IsLetter(r) || unicode.IsNumber(r)
}

// IsUpperAlphanumeric returns whether or not the string is an 'upper alphanumeric character'
// Upper alphanumeric characters are defined as numbers or upper-case letters ([A-Z0-9])
func IsUpperAlphanumeric(r rune) bool {
	return IsUpperLetter(r) || unicode.IsNumber(r)
}

// IsLowerAlphanumeric returns whether or not the string is an 'lower alphanumeric character'
// Lower alphanumeric characters are defined as numbers or lower-case letters ([a-z0-9])
func IsLowerAlphanumeric(r rune) bool {
	return IsLowerLetter(r) || unicode.IsNumber(r)
}

// IsUpperLetter returns whether or not the string is a 'upper letter character'
// Upper letter characters are defined as upper-case letters ([A-Z])
func IsUpperLetter(r rune) bool {
	return unicode.IsLetter(r) && unicode.IsUpper(r)
}

// IsLowerLetter returns whether or not the string is a 'lower letter character'
// Lower letter characters are defined as lower-case letters ([a-z])
func IsLowerLetter(r rune) bool {
	return unicode.IsLetter(r) && unicode.IsLower(r)
}

// Spaces returns a string with n spaces
func Spaces(n int) string {
	return strings.Repeat(" ", n)
}

// IsSpaces checks if a given string is only spaces
func IsSpaces(str []byte) bool {
	for _, c := range str {
		if c != ' ' {
			return false
		}
	}

	return true
}

// IsSpacesOrTabs checks if a given string contains only spaces and tabs

Review comment (performance):
`unicode.IsLetter(r)` check is redundant: `unicode.IsUpper()` and `unicode.IsLower()` return true for letters only.

Which means that `IsUpperLetter()` and `IsLowerLetter()`, as such, are also redundant?

Code after:

// IsSubwordDelimiter returns whether or not a rune is a 'sub-word delimiter character'
// i.e. is considered a part of the word and is used as a delimiter between sub-words of the word.
// For now the only sub-word delimiter character is '_'.
func IsSubwordDelimiter(r rune) bool {
	return r == '_'
}

// IsAlphanumeric returns whether or not a rune is an 'alphanumeric character'
// Alphanumeric characters are defined as numbers or letters
func IsAlphanumeric(r rune) bool {
	return unicode.IsLetter(r) || unicode.IsNumber(r)
}

// IsUpperAlphanumeric returns whether or not a rune is an 'upper alphanumeric character'
// Upper alphanumeric characters are defined as numbers or upper-case letters
func IsUpperAlphanumeric(r rune) bool {
	return IsUpperLetter(r) || unicode.IsNumber(r)
}

// IsLowerAlphanumeric returns whether or not a rune is a 'lower alphanumeric character'
// Lower alphanumeric characters are defined as numbers or lower-case letters
func IsLowerAlphanumeric(r rune) bool {
	return IsLowerLetter(r) || unicode.IsNumber(r)
}

// IsUpperLetter returns whether or not a rune is an 'upper letter character'
// Upper letter characters are defined as upper-case letters
func IsUpperLetter(r rune) bool {
	// unicode.IsUpper() returns true for letters only
	return unicode.IsUpper(r)
}

// IsLowerLetter returns whether or not a rune is a 'lower letter character'
// Lower letter characters are defined as lower-case letters
func IsLowerLetter(r rune) bool {
	// unicode.IsLower() returns true for letters only
	return unicode.IsLower(r)
}

// Spaces returns a string with n spaces
func Spaces(n int) string {
	return strings.Repeat(" ", n)
}

// IsSpaces checks if a given string is only spaces
func IsSpaces(str []byte) bool {
	for _, c := range str {
		if c != ' ' {
			return false
		}