MCPcopy Create free account
hub / github.com/BYVoid/OpenCC / SerializeSegmentationResultJson

Function SerializeSegmentationResultJson

src/tools/CommandLineMain.cpp:301–316  ·  view source on GitHub ↗

Serializes the segmentation-only view of an inspection result as a JSON object with "input" and "segments" fields. Used with --segmentation mode.

Source from the content-addressed store, hash-verified

299// Serializes the segmentation-only view of an inspection result as a JSON
300// object with "input" and "segments" fields. Used with --segmentation mode.
301std::string SerializeSegmentationResultJson(
302 const ConversionInspectionResult& result) {
303 rapidjson::StringBuffer buffer;
304 rapidjson::Writer<rapidjson::StringBuffer> writer(buffer);
305 writer.StartObject();
306 writer.Key("input");
307 writer.String(result.input.c_str(), result.input.size());
308 writer.Key("segments");
309 writer.StartArray();
310 for (const auto& seg : result.segments) {
311 writer.String(seg.c_str(), seg.size());
312 }
313 writer.EndArray();
314 writer.EndObject();
315 return buffer.GetString();
316}
317
318// Writes a ConversionInspectionResult as a JSON object into writer.
319// Handles both SingleStageConverter results (segments + stages) and

Callers 1

ConvertLineByModeFunction · 0.85

Calls 8

GetStringMethod · 0.80
StartObjectMethod · 0.45
KeyMethod · 0.45
StringMethod · 0.45
sizeMethod · 0.45
StartArrayMethod · 0.45
EndArrayMethod · 0.45
EndObjectMethod · 0.45

Tested by

no test coverage detected