findTags method

List<Map<String, String>> findTags(
  1. String? str
)

Find tags, locate occurrences of things surrounded in double curly {{brackets}}

Implementation

List<Map<String, String>> findTags(String? str) {
  final tags = <Map<String, String>>[];
  if (str == null) {
    return tags;
  }
  final exp = RegExp('({{[^{}]+}})');
  final Iterable<Match> matches = exp.allMatches(str);
  // Iterate through each one
  for (final match in matches) {
    final s = match.group(0)!;
    // remove leading {{
    // removing trailing }}
    // split into words
    // remove whitespace
    final t = s
        .replaceAll(RegExp('^{{'), '')
        .replaceAll(RegExp('}}\$'), '')
        .split(RegExp('(\\s+)'))
        .map((String e) => e.trim())
        .where(((String e) => e.isNotEmpty))
        .toList();
    final params = t.length == 2 ? t[1] : '';
    tags.add(<String, String>{
      DartamakerConstants.original: s,
      DartamakerConstants.tag: t[0],
      DartamakerConstants.params: params
    });
  }
  return tags;
}