replaceGreek property

String replaceGreek

Replaces all greek characters with latin. Comes handy when you want to normalize text for search.

Example

String foo = 'Αριστοτέλης';
String fooReplaced = foo.replaceGreek; // returns 'aristotelis'

Implementation

String get replaceGreek {
  if (this.isBlank) return this;
  var normalizedWord = '';
  for (var i = 0; i < this.length; i++) {
    var character = this[i];
    if (StringHelpers.greekToLatin.containsKey(character)) {
      normalizedWord += StringHelpers.greekToLatin[character]!;
    } else {
      normalizedWord += character;
    }
  }
  return normalizedWord;
}