findFrom method

MustacheTag? findFrom(
  1. String? value, {
  2. bool onlyFormat = false,
})

loops through looking for a matched value, return null if not found

Implementation

MustacheTag? findFrom(String? value, {bool onlyFormat = false}) {
  if (value == null) {
    return null;
  }

  final valueLower = value.toLowerCase();

  for (final e in this) {
    final name = e.name.toLowerCase().replaceAll('_', '');
    if (!onlyFormat) {
      if (valueLower.startsWith(name)) {
        return e;
      }
    }

    if (!e.isFormat) {
      continue;
    }

    if (valueLower.startsWith(e.name.replaceAll('Case', ''))) {
      return e;
    }
  }

  return null;
}