script.go raw

   1  package lattice
   2  
   3  import "unicode"
   4  
   5  // IsCyrillic returns true if s contains at least one Cyrillic letter
   6  // and no Latin letters. Returns false for empty strings, digit-only
   7  // strings, or strings with mixed scripts.
   8  func IsCyrillic(s string) bool {
   9  	hasCyrillic := false
  10  	for _, r := range s {
  11  		if unicode.Is(unicode.Latin, r) {
  12  			return false
  13  		}
  14  		if unicode.Is(unicode.Cyrillic, r) {
  15  			hasCyrillic = true
  16  		}
  17  	}
  18  	return hasCyrillic
  19  }
  20  
  21  // IsLatin returns true if s contains at least one Latin letter
  22  // and no Cyrillic letters. Returns false for empty strings, digit-only
  23  // strings, or strings with mixed scripts.
  24  func IsLatin(s string) bool {
  25  	hasLatin := false
  26  	for _, r := range s {
  27  		if unicode.Is(unicode.Cyrillic, r) {
  28  			return false
  29  		}
  30  		if unicode.Is(unicode.Latin, r) {
  31  			hasLatin = true
  32  		}
  33  	}
  34  	return hasLatin
  35  }
  36