recognizeCharacterIcon function

String recognizeCharacterIcon(
  1. String url
)

Implementation

String recognizeCharacterIcon(String url) {
  // Recognizes a character's icon url and returns its name.
  var exp = RegExp('game_record/genshin/character_.*_(\\w+)(?:@\\dx)?.png',
      caseSensitive: false, multiLine: true);
  var match = exp.allMatches(url);
  print("allmatches ${match.toList()}");
  if (match.isEmpty) {
    print("$url is not a character icon or image url");
    throw Error();
  }
  var character = match.first.group(1)!;
  print("character name $character");
  return characterIcons[character] ?? character;
}