| 1 |
/* |
| 2 |
* SPDX-FileCopyrightText: 2017-2017 CSSlayer <[email protected]> |
| 3 |
* |
| 4 |
* SPDX-License-Identifier: LGPL-2.1-or-later |
| 5 |
* |
| 6 |
*/ |
| 7 |
#ifndef _CHTTRANS_CHTTRANS_NATIVE_H_ |
| 8 |
#define _CHTTRANS_CHTTRANS_NATIVE_H_ |
| 9 |
|
| 10 |
#include "chttrans.h" |
| 11 |
#include <functional> |
| 12 |
#include <string> |
| 13 |
#include <string_view> |
| 14 |
#include <unordered_map> |
| 15 |
|
| 16 |
class NativeBackend : public ChttransBackend { |
| 17 |
struct string_hash { |
| 18 |
using is_transparent = void; |
| 19 |
|
| 20 |
size_t operator()(const std::string_view str) const { |
| 21 |
constexpr std::hash<std::string_view> hasher{}; |
| 22 |
return hasher(str); |
| 23 |
} |
| 24 |
}; |
| 25 |
|
| 26 |
public: |
| 27 |
using MapType = std::unordered_map<std::string, std::string, string_hash, |
| 28 |
std::equal_to<>>; |
| 29 |
std::string convertSimpToTrad(const std::string &) override; |
| 30 |
std::string convertTradToSimp(const std::string &) override; |
| 31 |
|
| 32 |
protected: |
| 33 |
bool loadOnce(const ChttransConfig &) override; |
| 34 |
|
| 35 |
private: |
| 36 |
MapType s2tMap_; |
| 37 |
MapType t2sMap_; |
| 38 |
}; |
| 39 |
|
| 40 |
#endif // _CHTTRANS_CHTTRANS_NATIVE_H_ |