| 298 | } |
| 299 | |
| 300 | SegmentsPtr Segment(std::string_view text) const override { |
| 301 | const std::string owned(text); |
| 302 | opencc_segment_length_array_t segmentLengths = {}; |
| 303 | segmentLengths.struct_size = sizeof(segmentLengths); |
| 304 | opencc_error_t error = {}; |
| 305 | error.struct_size = sizeof(error); |
| 306 | opencc_segmentation_segment_args_t args = {}; |
| 307 | args.struct_size = sizeof(args); |
| 308 | args.handle = handle_; |
| 309 | args.utf8_text = owned.c_str(); |
| 310 | args.segment_lengths = &segmentLengths; |
| 311 | args.error = &error; |
| 312 | const int status = plugin_->descriptor->segment(&args); |
| 313 | |
| 314 | struct SegmentLengthGuard { |
| 315 | const opencc_segmentation_plugin_v2* desc; |
| 316 | opencc_segment_length_array_t* arr; |
| 317 | ~SegmentLengthGuard() { desc->free_segment_lengths(arr); } |
| 318 | } guard{plugin_->descriptor, &segmentLengths}; |
| 319 | |
| 320 | if (status != 0) { |
| 321 | ThrowPluginError(plugin_->descriptor, &error, |
| 322 | plugin_->descriptor->segmentation_type, |
| 323 | "Segmentation plugin failed", "unknown error"); |
| 324 | } |
| 325 | return BuildSegmentsFromLengths(text, segmentLengths); |
| 326 | } |
| 327 | |
| 328 | private: |
| 329 | std::shared_ptr<PluginLibrary> plugin_; |
nothing calls this directly
no test coverage detected