build method

  1. @override
String build(
  1. Context context,
  2. ParserResult? result
)
override

Implementation

@override
String build(Context context, ParserResult? result) {
  if (this.tag.isEmpty) {
    throw ArgumentError.value(this.tag, 'tag', 'The tag must not be empty');
  }

  context.refersToStateSource = true;
  final fast = result == null;
  final cc = this.tag.codeUnitAt(0).toString();
  final tag = helper.escapeString(this.tag);
  final length = this.tag.length;
  final String test;
  switch (length) {
    case 1:
      test =
          'state.pos < source.length && source.codeUnitAt(state.pos) == $cc';
      break;
    case 2:
      final cc2 = this.tag.codeUnitAt(1).toString();
      test =
          'state.pos + 1 < source.length && source.codeUnitAt(state.pos) == $cc && source.codeUnitAt(state.pos + 1) == $cc2';
      break;
    default:
      test =
          'state.pos < source.length && source.codeUnitAt(state.pos) == $cc && source.startsWith($tag, state.pos)';
  }

  final values = {
    'length': '$length',
    'tag': helper.escapeString(this.tag),
    'test': test,
  };
  return render2(fast, _templateFast, _template, values, [result]);
}