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

Code before:
	}
	return a
}

// Max takes the max of two ints
func Max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

// FSize gets the size of a file
func FSize(f *os.File) int64 {
	fi, _ := f.Stat()
	return fi.Size()
}

// IsWordChar returns whether or not the string is a 'word character'
// Word characters are defined as numbers, letters, or '_'
func IsWordChar(r rune) bool {
	return IsAlphanumeric(r) || IsWordDelimiter(r)
}

// IsUpperWordChar returns whether or not the string is a 'upper word character'
// Upper word characters are defined as numbers, upper-case letters, or delimiters ([A-Z0-9_])
func IsUpperWordChar(r rune) bool {
	return IsUpperAlphanumeric(r) || IsWordDelimiter(r)
}

// IsLowerWordChar returns whether or not the string is a 'lower word character'
// Lower word characters are defined as numbers, upper-case letters, or delimiters ([a-z0-9_])
func IsLowerWordChar(r rune) bool {
	return IsLowerAlphanumeric(r) || IsWordDelimiter(r)
}

// IsWordDelimiter returns whether or not the string is a 'delimiter character'
// Delimiter characters are defined as '_'
func IsWordDelimiter(r rune) bool {
	return r == '_'
}

// IsNoneWordChar returns whether or not the string is not a 'word character'
// None word characters are defined as all characters not being alphanumerics, whitespaces or delimiters ([!A-Za-z0-9\s_])
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 {

Review comment (suggestion):
There references to regex patterns are not quite accurate, since `unicode.IsLetter()` returns true not only for Latin (ascii) letters.

Code after:
	if a > b {
		return b
	}
	return a
}

// Max takes the max of two ints
func Max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

// FSize gets the size of a file
func FSize(f *os.File) int64 {
	fi, _ := f.Stat()
	return fi.Size()
}

// IsWordChar returns whether or not a rune is a 'word character'
// Word characters are defined as numbers, letters or sub-word delimiters
func IsWordChar(r rune) bool {
	return IsAlphanumeric(r) || IsSubwordDelimiter(r)
}

// IsNonWordChar returns whether or not a rune is not a 'word character'
// Non word characters are defined as all characters not being numbers, letters or sub-word delimiters
// See IsWordChar()
func IsNonWordChar(r rune) bool {
	return !IsWordChar(r)
}

// IsUpperWordChar returns whether or not a rune is an 'upper word character'
// Upper word characters are defined as numbers, upper-case letters or sub-word delimiters
func IsUpperWordChar(r rune) bool {
	return IsUpperAlphanumeric(r) || IsSubwordDelimiter(r)
}

// IsLowerWordChar returns whether or not a rune is a 'lower word character'
// Lower word characters are defined as numbers, lower-case letters or sub-word delimiters
func IsLowerWordChar(r rune) bool {
	return IsLowerAlphanumeric(r) || IsSubwordDelimiter(r)
}

// 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 == '_'
}