Open Chinese Convert: opencc::ConversionChain Class Reference

Open Chinese Convert 1.3.2+gad37fd0a6.dirty A project for conversion between Traditional and Simplified Chinese

Loading...
Searching...
No Matches
Public Member Functions | List of all members
opencc::ConversionChain Class Reference
OpenCC C++ Comprehensive API

An ordered sequence of `Conversion` objects applied to pre-segmented text. More...

`#include <ConversionChain.hpp>`

## Public Member Functions
| ConversionChain (const std::list< ConversionPtr > _conversions)
| Constructs a chain from an ordered list of conversions.
SegmentsPtr | Convert (const SegmentsPtr &input) const
| Passes `input` through every conversion in the chain sequentially and returns the final `Segments`.
void | AppendConvertedSegment (const char *segment, std::string *output) const
| Converts the null-terminated `segment` through all conversions and appends the result to `output`.
void | AppendConvertedSegment (std::string_view segment, std::string *output) const
| Like `AppendConvertedSegment(const char*, std::string*)` but accepts the segment as a `string_view`, avoiding a copy when the caller already has a non-null-terminated view (e.g.
std::vector< SegmentsPtr > | ConvertWithTrace (const SegmentsPtr &input) const
| Converts `input` through the chain and records every intermediate `Segments` after each conversion stage.
const std::list< ConversionPtr > | GetConversions () const
| Returns the list of conversions in application order.

## Detailed Description

An ordered sequence of `Conversion` objects applied to pre-segmented text.

Each `Conversion` in the chain wraps one dictionary. The chain applies them in order: the output segments of conversion N become the input of conversion N+1. This enables priority-ordered substitution, such as applying phrase dictionaries before character dictionaries so that multi-character matches take precedence.

A `ConversionChain` operates on `Segments` (output of `Segmentation`) and has no knowledge of how those segments were produced.

## Member Function Documentation

## ◆ AppendConvertedSegment() [1/2]

void ConversionChain::AppendConvertedSegment | ( | const char * | segment,
|  | std::string * | output ) const

Converts the null-terminated `segment` through all conversions and appends the result to `output`.

This is the hot-path entry point used by `SingleStageConverter` to avoid intermediate string allocations.

## ◆ AppendConvertedSegment() [2/2]

void ConversionChain::AppendConvertedSegment | ( | std::string_view | segment,
|  | std::string * | output ) const

Like `AppendConvertedSegment(const char*, std::string*)` but accepts the segment as a `string_view`, avoiding a copy when the caller already has a non-null-terminated view (e.g.

`SingleStageConverter` with no segmentation).

## ◆ ConvertWithTrace()

std::vector< SegmentsPtr > ConversionChain::ConvertWithTrace | ( | const SegmentsPtr & | input | ) | const

Converts `input` through the chain and records every intermediate `Segments` after each conversion stage.

Returns
  One entry per conversion in the chain, in order.

The documentation for this class was generated from the following files:

- ConversionChain.hpp
- ConversionChain.cpp