normalizeArray static method

List<String> normalizeArray(
  1. List<String> arr
)

Trim whitespace, strip empty and duplicate elements elements If the result is an empty array, add a single element "\u2421" (Unicode Del character)

Implementation

static List<String> normalizeArray(List<String> arr) {
  var out = <String>[];

  if (arr is List) {
    // Trim, throw away very short and empty tags.
    for (var i = 0, l = arr.length; i < l; i++) {
      var t = arr[i];
      if (t != null && t != '') {
        t = t.trim().toLowerCase();
        if (t.length > 1) {
          out.add(t);
        }
      }
    }
    out.sort();
    out = out.toSet().toList();
  }
  if (out.isEmpty) {
    // Add single tag with a Unicode Del character, otherwise an empty array
    // is ambiguous. The Del tag will be stripped by the server.
    out.add(DEL_CHAR);
  }
  return out;
}