findChineseEntriesInFile function

List<String> findChineseEntriesInFile(
  1. String fileContent
)

Implementation

List<String> findChineseEntriesInFile(String fileContent) {
  RegExp singleQuoteRegExp = RegExp(r"'([^']*[\u4e00-\u9fa5]{1,200}[^']*)'");
  RegExp doubleQuoteRegExp = RegExp(r'"([^"]*[\u4e00-\u9fa5]{1,200}[^"]*)"');

  Iterable<Match> singleQuoteMatches =
      singleQuoteRegExp.allMatches(fileContent);
  Iterable<Match> doubleQuoteMatches =
      doubleQuoteRegExp.allMatches(fileContent);

  List<String> entries = [];

  for (Match match in singleQuoteMatches) {
    entries.add(match.group(1)!);
  }

  for (Match match in doubleQuoteMatches) {
    entries.add(match.group(1)!);
  }

  return entries;
}