llparse peek() characters with multiple code points

Viewed 21

I'm trying to modify llhttp, an HTTP client based on llparse, to support NTRIP (an HTTP-based protocol). To do so, I need to peek '\u{D3}' (match but not consume) and perform a test, otherwise start a span.

The problem is peek() only works with a single character and '\u{D3}' counts as 2 ('\u{C3}\u{93}'). How would I peek multiple characters or re-prepend the first character?

Here is what I had:

n('header_field_start') // Match node
  .match('\r', n('headers_almost_done'))
  .peek('\n', n('headers_almost_done'))
  .peek(
    '\u{D3}', // 2 characters
    this.testLenientFlags(
      LENIENT_FLAGS.NTRIP, 
      {
        1: this.invokePausable('on_chunk_complete', ERROR.CB_CHUNK_COMPLETE, 'message_done') // If NTRIP is set
      },
      p.error(ERROR.INVALID_VERSION, 'Invalid major version') // Otherwise
    )
  )
  .otherwise(span.headerField.start(n('header_field')));

// Defined earlier...
private testLenientFlags(flag: LENIENT_FLAGS, map: { [key: number]: Node }, next?: string | Node): Node {
  const p = this.llparse;
  const res = p.invoke(p.code.test('lenient_flags', flag), map);
  if (next !== undefined) {
    res.otherwise(this.node(next));
  }
  return res;
}
0 Answers
Related