Open Chinese Convert 1.3.2
A project for conversion between Traditional and Simplified Chinese
Loading...
Searching...
No Matches
opencc::Conversion Class Reference

Single-dictionary phrase conversion. More...

#include <Conversion.hpp>

Public Member Functions

 Conversion (DictPtr _dict)
 Constructs a Conversion backed by dict.
std::string Convert (std::string_view phrase) const
 Converts phrase using prefix-match replacement and returns the result.
std::string Convert (const char *phrase) const
 Converts phrase using prefix-match replacement and returns the result.
void AppendConverted (std::string_view phrase, std::string *output) const
 Converts phrase and appends the result to output.
void AppendConverted (const char *phrase, std::string *output) const
 Converts phrase and appends the result to output.
SegmentsPtr Convert (const SegmentsPtr &input) const
 Converts every segment in input and returns a new Segments object.
const DictPtr GetDict () const
 Returns the backing dictionary.

Detailed Description

Single-dictionary phrase conversion.

Applies prefix-match replacement using one dictionary (DictPtr) to an already-segmented piece of text. This is the lowest-level conversion primitive: it knows nothing about segmentation and operates on a single segment or a pre-built Segments object.

Multiple Conversion objects are composed in a ConversionChain to apply several dictionaries in order (e.g. phrase dictionary first, then character dictionary).

Member Function Documentation

◆ AppendConverted() [1/2]

void Conversion::AppendConverted ( const char * phrase,
std::string * output ) const

Converts phrase and appends the result to output.

Parameters
phraseNull-terminated UTF-8 text.
outputDestination buffer; content is appended, not replaced.

◆ AppendConverted() [2/2]

void Conversion::AppendConverted ( std::string_view phrase,
std::string * output ) const

Converts phrase and appends the result to output.

Preferred in hot paths (e.g. ConversionChain) to avoid extra allocations.

Parameters
phraseUTF-8 text; need not be null-terminated.
outputDestination buffer; content is appended, not replaced.

◆ Convert() [1/3]

std::string Conversion::Convert ( const char * phrase) const

Converts phrase using prefix-match replacement and returns the result.

Parameters
phraseNull-terminated UTF-8 text.

◆ Convert() [2/3]

SegmentsPtr Conversion::Convert ( const SegmentsPtr & input) const

Converts every segment in input and returns a new Segments object.

Each segment is converted independently via Convert(const char*).

◆ Convert() [3/3]

std::string Conversion::Convert ( std::string_view phrase) const

Converts phrase using prefix-match replacement and returns the result.

Parameters
phraseUTF-8 text; need not be null-terminated.

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