rmlInspect function
Problems rml's inspect finds in a single RML document: the compiler
accepts these but they are wired wrong. Treats rml as one document --
no fragments, default InspectOptions.
A document that fails to parse comes back with one problem of kind 'syntax' per parse error rather than throwing -- inspect folds parse failures into the same problems list.
Throws when markupAvailable is false.
Implementation
List<RmlProblem> rmlInspect(String rml) {
_requireMarkup();
if (rml.isEmpty) {
// Mirrors rmlToRev's empty guard: avoids a zero-byte calloc, and an
// empty document is not well-formed XML either way.
return const [
RmlProblem(
severity: 'error',
kind: 'syntax',
message: 'no markup to inspect',
line: 0,
),
];
}
final rmlBytes = utf8.encode(rml);
final source = calloc<Uint8>(rmlBytes.length);
final response = calloc<_RmlInspectResponseStruct>();
try {
source.asTypedList(rmlBytes.length).setAll(0, rmlBytes);
_rmlInspect(source, rmlBytes.length, response);
final json = response.ref.data == nullptr || response.ref.size <= 0
? '[]'
: utf8.decode(
response.ref.data.asTypedList(response.ref.size),
allowMalformed: true,
);
return RmlProblem.listFromJson(json);
} finally {
_freeRmlInspect(response);
calloc.free(response);
calloc.free(source);
}
}