clean static method

String clean(
  1. String value, {
  2. bool allowLatin = true,
})

Returns a cleaned string (that is ready for encoding) by performing the following steps on value :

  • trimming any whitespace and converting to uppercase
  • removing any generational suffixes (jr, sr, roman)
  • removing any non-word characters including latin vowels if allowLatin is false

Note that this does not try to clean special characters (such as - and .) that appear in the wrong location because that would affect performance negatively for an edge case that is not common. You may need to do additional cleaning if you're working with strings that are particularly dirty.

Implementation

static String clean(final String value, {bool allowLatin = true}) {
  if (value.isEmpty) {
    return value;
  }

  final cleaned = value
      .trim()
      .toUpperCase()
      .replaceFirst(_cleanGenerational, '')
      .replaceAll(
          (allowLatin) ? _cleanLatinAllowed : _cleanLatinNotAllowed, '');

  return cleaned;
}