breakUpTexStrings static method

List<String> breakUpTexStrings(
  1. String texString,
  2. List<String> subStringToIsolate,
  3. Map<String, Color> texToColorMap
)

Implementation

static List<String> breakUpTexStrings(String texString,
    List<String> subStringToIsolate, Map<String, Color> texToColorMap) {
  var texStrings = texString.splitWithContent(RegExp('{{(.*?)}}'));
  var patterns = [
    for (var ss in [...texToColorMap.keys, ...subStringToIsolate])
      '(${RegExp.escape(ss)})'
  ];
  var pattern = patterns.join('|');
  var pieces = <String>[];

  if (pattern.isNotEmpty) {
    var regex = RegExp(pattern);

    for (var s in texStrings) {
      pieces.addAll(s.splitWithContent(regex));
    }
  } else {
    pieces = texStrings;
  }

  return [
    for (var p in pieces)
      if (p.isNotEmpty) p
  ];
}