process method

StubbleResult? process(
  1. ProcessMessage msg,
  2. StubbleContext context
)

Implementation

StubbleResult? process(ProcessMessage msg, StubbleContext context) {
  final charCode = msg.charCode;

  if (charCode == eos) {
    return StubbleResult(
        pop: true, message: ProcessMessage(charCode: charCode));
  }

  if (_search) {
    _tmp += String.fromCharCode(charCode);

    var l = _look;
    var t = _tmp;
    var o = _openTag;

    final op = context.opt('ignoreTagCaseSensetive');

    if (op == true) {
      l = l.toLowerCase();
      t = t.toLowerCase();
      o = o.toLowerCase();
    }

    if ((t[_count] != l[_count] && t[_count] != o[_count]) ||
        _count >= l.length) {
      _search = false;
      _body += _tmp;
    } else {
      _count++;
    }

    if (t == o) {
      _search = false;
      _body += _tmp;
      _innerOpened++;
    } else if (t.length == l.length) {
      if (_innerOpened > 0) {
        _search = false;
        _body += _tmp;
        _innerOpened--;
      } else {
        return StubbleResult(
            pop: true,
            message: NotifyMessage(
              charCode: null,
              type: notifyBlockEndResult,
              value: _body,
            ));
      }
    }
  } else {
    if (charCode == openBracket && !_esc) {
      _search = true;
      _tmp = '' + String.fromCharCode(openBracket);
      _count = 0;
    } else if (charCode == backSlash && !_esc) {
      _esc = true;
    } else {
      _esc = false;
      _body += String.fromCharCode(charCode);
    }
  }

  return null;
}