Loading...
Searching...
No Matches
Converter.hpp
/*
* Open Chinese Convert
*
* Copyright 2010-2014 Carbo Kuo <byvoid@byvoid.com>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#pragma once
#include <cstddef>
#include <string>
#include <string_view>
#include "Common.hpp"
#include "ConversionInspection.hpp"
#include "Segmentation.hpp"
namespace opencc {
class OPENCC_EXPORT Converter {
public:
virtual ~Converter() = default;
virtual std::string Convert(std::string_view text) const = 0;
virtual ConversionInspectionResult Inspect(std::string_view text) const = 0;
virtual SegmentationPtr GetSegmentation() const = 0;
virtual ConversionChainPtr GetConversionChain() const = 0;
};
class OPENCC_EXPORT ConverterStream {
public:
explicit ConverterStream(ConverterPtr converter, size_t maxKeepChars = 16)
: converter(converter), maxKeepChars(maxKeepChars) {}
std::string ConvertChunk(std::string_view input);
std::string Finish(std::string_view input);
std::string Finish();
private:
ConverterPtr converter;
size_t maxKeepChars;
std::string pending;
};
} // namespace opencc
opencc::Converter
Abstract base for full-text converters.
Definition Converter.hpp:48
opencc::Converter::Inspect
virtual ConversionInspectionResult Inspect(std::string_view text) const =0
Converts text and returns a detailed inspection result that includes the initial segmentation,...
opencc::Converter::Convert
virtual std::string Convert(std::string_view text) const =0
Converts text and returns the result.
opencc::Converter::GetSegmentation
virtual SegmentationPtr GetSegmentation() const =0
Returns the segmentation used by this converter, or nullptr if the converter has no single segmentati...
opencc::Converter::GetConversionChain
virtual ConversionChainPtr GetConversionChain() const =0
Returns the conversion chain used by this converter, or nullptr if the converter has no single chain ...
opencc::ConverterStream::ConverterStream
ConverterStream(ConverterPtr converter, size_t maxKeepChars=16)
Definition Converter.hpp:88
opencc::ConversionInspectionResult
Full inspection result returned by Converter::Inspect().
Definition ConversionInspection.hpp:52