@@ -219,18 +219,69 @@ func FSize(f *os.File) int64 {
219219}
220220
221221// IsWordChar returns whether or not a rune is a 'word character'
222- // Word characters are defined as numbers, letters or '_'
222+ // Word characters are defined as numbers, letters or sub-word delimiters
223223func IsWordChar (r rune ) bool {
224- return unicode . IsLetter (r ) || unicode . IsNumber (r ) || r == '_'
224+ return IsAlphanumeric (r ) || IsSubwordDelimiter (r )
225225}
226226
227227// IsNonWordChar returns whether or not a rune is not a 'word character'
228- // Non word characters are defined as all characters not being numbers, letters or '_'
228+ // Non word characters are defined as all characters not being numbers, letters or sub-word delimiters
229229// See IsWordChar()
230230func IsNonWordChar (r rune ) bool {
231231 return ! IsWordChar (r )
232232}
233233
234+ // IsUpperWordChar returns whether or not a rune is an 'upper word character'
235+ // Upper word characters are defined as numbers, upper-case letters or sub-word delimiters
236+ func IsUpperWordChar (r rune ) bool {
237+ return IsUpperAlphanumeric (r ) || IsSubwordDelimiter (r )
238+ }
239+
240+ // IsLowerWordChar returns whether or not a rune is a 'lower word character'
241+ // Lower word characters are defined as numbers, lower-case letters or sub-word delimiters
242+ func IsLowerWordChar (r rune ) bool {
243+ return IsLowerAlphanumeric (r ) || IsSubwordDelimiter (r )
244+ }
245+
246+ // IsSubwordDelimiter returns whether or not a rune is a 'sub-word delimiter character'
247+ // i.e. is considered a part of the word and is used as a delimiter between sub-words of the word.
248+ // For now the only sub-word delimiter character is '_'.
249+ func IsSubwordDelimiter (r rune ) bool {
250+ return r == '_'
251+ }
252+
253+ // IsAlphanumeric returns whether or not a rune is an 'alphanumeric character'
254+ // Alphanumeric characters are defined as numbers or letters
255+ func IsAlphanumeric (r rune ) bool {
256+ return unicode .IsLetter (r ) || unicode .IsNumber (r )
257+ }
258+
259+ // IsUpperAlphanumeric returns whether or not a rune is an 'upper alphanumeric character'
260+ // Upper alphanumeric characters are defined as numbers or upper-case letters
261+ func IsUpperAlphanumeric (r rune ) bool {
262+ return IsUpperLetter (r ) || unicode .IsNumber (r )
263+ }
264+
265+ // IsLowerAlphanumeric returns whether or not a rune is a 'lower alphanumeric character'
266+ // Lower alphanumeric characters are defined as numbers or lower-case letters
267+ func IsLowerAlphanumeric (r rune ) bool {
268+ return IsLowerLetter (r ) || unicode .IsNumber (r )
269+ }
270+
271+ // IsUpperLetter returns whether or not a rune is an 'upper letter character'
272+ // Upper letter characters are defined as upper-case letters
273+ func IsUpperLetter (r rune ) bool {
274+ // unicode.IsUpper() returns true for letters only
275+ return unicode .IsUpper (r )
276+ }
277+
278+ // IsLowerLetter returns whether or not a rune is a 'lower letter character'
279+ // Lower letter characters are defined as lower-case letters
280+ func IsLowerLetter (r rune ) bool {
281+ // unicode.IsLower() returns true for letters only
282+ return unicode .IsLower (r )
283+ }
284+
234285// Spaces returns a string with n spaces
235286func Spaces (n int ) string {
236287 return strings .Repeat (" " , n )
0 commit comments