buildWithRegExp method

void buildWithRegExp({
  1. required String data,
  2. required int start,
  3. required List<RegExpSpecialText> copyRegExps,
  4. required List<InlineSpan> children,
  5. TextStyle? textStyle,
  6. SpecialTextGestureTapCallback? onTap,
})

Implementation

void buildWithRegExp({
  required String data,
  required int start,
  required List<RegExpSpecialText> copyRegExps,
  required List<InlineSpan> children,
  TextStyle? textStyle,
  SpecialTextGestureTapCallback? onTap,
}) {
  if (data.isEmpty) {
    return;
  }

  if (copyRegExps.isEmpty) {
    children.add(TextSpan(text: data, style: textStyle));
    return;
  }

  final RegExpSpecialText regExpSpecialText = copyRegExps.first;

  data.splitMapJoin(regExpSpecialText.regExp, onMatch: (Match match) {
    final String matchString = '${match[0]}';
    children.add(regExpSpecialText.finishText(
      start,
      match,
      textStyle: textStyle,
      onTap: onTap,
    ));
    start += matchString.length;
    return '';
  }, onNonMatch: (String notMatch) {
    if (notMatch.isNotEmpty) {
      buildWithRegExp(
        data: notMatch,
        start: start,
        children: children,
        copyRegExps: copyRegExps.toList()..remove(regExpSpecialText),
        textStyle: textStyle,
        onTap: onTap,
      );
      start += notMatch.length;
    }
    return '';
  });
}