owoify static method

String owoify(
  1. String source, {
  2. OwoifyLevel level = OwoifyLevel.Owo,
})

Convert source string to owoified string using specified OwoifyLevel (owoness). Three levels are available (from lowest to highest): OwoifyLevel.Owo, OwoifyLevel.Uwu, OwoifyLevel.Uvu

Implementation

static String owoify(String source, {OwoifyLevel level = OwoifyLevel.Owo}) {
  var wordMatches = WORD_REGEX.allMatches(source);
  var spaceMatches = SPACE_REGEX.allMatches(source);

  var words = wordMatches.map((e) => Word(e.group(0)));
  var spaces = spaceMatches.map((e) => Word(e.group(0)));

  words = words.map((e) {
    for (var f in SPECIFIC_WORD_MAPPING_LIST) {
      e = f(e);
    }
    switch (level) {
      case OwoifyLevel.Owo:
        for (var f in OWO_MAPPING_LIST) {
          e = f(e);
        }
        break;
      case OwoifyLevel.Uwu:
        for (var f in UWU_MAPPING_LIST) {
          e = f(e);
        }
        for (var f in OWO_MAPPING_LIST) {
          e = f(e);
        }
        break;
      case OwoifyLevel.Uvu:
        for (var f in UVU_MAPPING_LIST) {
          e = f(e);
        }
        for (var f in UWU_MAPPING_LIST) {
          e = f(e);
        }
        for (var f in OWO_MAPPING_LIST) {
          e = f(e);
        }
        break;
    }
    return e;
  });

  var result = interleaveArrays<Word>(words, spaces);
  var resultStrings = result.map((e) => e.toString());
  return resultStrings.join();
}