src/cpp-common: add `bt2c::StrScanner` class
This patch adds the `bt2c::StrScanner` class, defined in
`str-scanner.hpp` and implemented in `str-scanner.cpp`.
A string scanner is a simple lexical scanner. This one is a
stripped-down version of yactfr's `yactfr::internal::StrScanner`,
stripped-down because yactfr uses this to parse TSDL, therefore it needs
more features.
What's left for the `bt2c::StrScanner` version is:
tryScanLitStr():
Tries to scan a double-quoted literal string, possibly containing
escape sequences.
tryScanConstInt():
Tries to scan a constant unsigned or signed decimal integer string.
tryScanConstReal():
Tries to scan a real number string.
tryScanToken():
Tries to scan an exact string.
skipWhitespaces():
Skips the next whitespaces.
See the specific comments in `str-scanner.hpp` for more details.
I could have used the `GScanner` API [1], as we do to parse the value of
the `--params` CLI option of `babeltrace2`, but:
• `yactfr::internal::StrScanner` is already working, tested,
and documented.
`bt2c::StrScanner` is a much lighter version of it.
• Should we ever make an effort to remove the GLib dependency, this part
will already be done.
• The `GScanner` API doesn't support `\u` escape sequences in literal
strings (needed for JSON strings) out of the box, so we'd need this
part on our side anyway.
`bt2c::StrScanner` could eventually replace `GScanner` elsewhere in the
tree, but it would require a few more features (which already exist
in `yactfr::internal::StrScanner`, that is).
This is part of an effort to implement a JSON parser to
support CTF2‑SPEC‑2.0 [2].
[1]: https://docs.gtk.org/glib/struct.Scanner.html
[2]: https://diamon.org/ctf/CTF2-SPEC-2.0.html
Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: I8317917124218618278611794f32a67be4b9a6dd
Reviewed-on: https://review.lttng.org/c/babeltrace/+/7410
Reviewed-on: https://review.lttng.org/c/babeltrace/+/12681
This page took 0.024622 seconds and 4 git commands to generate.