(De)composition is not static any more
This commit is contained in:
@@ -19,8 +19,6 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <stdex/idrec.h>
|
||||
#include <istream>
|
||||
#include <vector>
|
||||
|
||||
|
||||
@@ -54,31 +52,6 @@ namespace ZRCola {
|
||||
typedef unsigned __int32 recordsize_t;
|
||||
|
||||
|
||||
///
|
||||
/// Translation database
|
||||
///
|
||||
class translation_db {
|
||||
public:
|
||||
#pragma pack(push)
|
||||
#pragma pack(4)
|
||||
///
|
||||
/// Translation index
|
||||
///
|
||||
struct index {
|
||||
unsigned __int32 start; ///< Composed character offset
|
||||
unsigned __int32 end; ///< Decomposed string end offset
|
||||
};
|
||||
#pragma pack(pop)
|
||||
|
||||
std::vector<index> comp_index; ///< Composition index
|
||||
std::vector<index> decomp_index; ///< Decomposition index
|
||||
std::vector<wchar_t> data; ///< Transformation data
|
||||
};
|
||||
|
||||
|
||||
typedef ZRCOLA_API stdex::idrec::record<translation_db, recordid_t, recordsize_t, ZRCOLA_RECORD_ALIGN> translation_rec;
|
||||
|
||||
|
||||
///
|
||||
/// Composed-decomposed index transformation mapping
|
||||
///
|
||||
@@ -118,44 +91,3 @@ namespace ZRCola {
|
||||
};
|
||||
|
||||
#pragma warning(pop)
|
||||
|
||||
|
||||
const ZRCola::recordid_t stdex::idrec::record<ZRCola::translation_db, ZRCola::recordid_t, ZRCola::recordsize_t, ZRCOLA_RECORD_ALIGN>::id = ZRCOLA_DB_TRANSLATIONS_ID;
|
||||
|
||||
|
||||
///
|
||||
/// Reads translation database from a stream
|
||||
///
|
||||
/// \param[in] stream Input stream
|
||||
/// \param[out] t_db Translation database
|
||||
///
|
||||
/// \returns The stream \p stream
|
||||
///
|
||||
inline std::istream& operator >>(std::istream& stream, ZRCola::translation_db &t_db)
|
||||
{
|
||||
unsigned __int32 count;
|
||||
|
||||
// Read index count.
|
||||
stream.read((char*)&count, sizeof(count));
|
||||
if (!stream.good()) return stream;
|
||||
|
||||
// Read composition index.
|
||||
t_db.comp_index.resize(count);
|
||||
stream.read((char*)t_db.comp_index.data(), sizeof(ZRCola::translation_db::index)*count);
|
||||
if (!stream.good()) return stream;
|
||||
|
||||
// Read decomposition index.
|
||||
t_db.decomp_index.resize(count);
|
||||
stream.read((char*)t_db.decomp_index.data(), sizeof(ZRCola::translation_db::index)*count);
|
||||
if (!stream.good()) return stream;
|
||||
|
||||
// Read data count.
|
||||
stream.read((char*)&count, sizeof(count));
|
||||
if (!stream.good()) return stream;
|
||||
|
||||
// Read data.
|
||||
t_db.data.resize(count);
|
||||
stream.read((char*)t_db.data.data(), sizeof(wchar_t)*count);
|
||||
|
||||
return stream;
|
||||
}
|
||||
|
@@ -1,47 +0,0 @@
|
||||
/*
|
||||
Copyright 2015-2016 Amebis
|
||||
|
||||
This file is part of ZRCola.
|
||||
|
||||
ZRCola is free software: you can redistribute it and/or modify it
|
||||
under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
ZRCola is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with ZRCola. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "common.h"
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
|
||||
namespace ZRCola {
|
||||
///
|
||||
/// Composition
|
||||
///
|
||||
struct composition {
|
||||
const wchar_t *src; ///< Decomposed string
|
||||
wchar_t dst; ///< Composed character
|
||||
};
|
||||
|
||||
|
||||
///
|
||||
/// Composes string
|
||||
///
|
||||
/// \param[in] input Input string (UTF-16)
|
||||
/// \param[in] inputMax Length of the input string in characters. Can be (size_t)-1 if \p input is zero terminated.
|
||||
/// \param[out] output Output string (UTF-16)
|
||||
/// \param[out] map The vector of source to destination index mappings (optional)
|
||||
///
|
||||
void ZRCOLA_API Compose(_In_z_count_(inputMax) const wchar_t* input, _In_ size_t inputMax, _Out_ std::wstring &output, _Out_opt_ std::vector<mapping>* map = NULL);
|
||||
};
|
@@ -1,47 +0,0 @@
|
||||
/*
|
||||
Copyright 2015-2016 Amebis
|
||||
|
||||
This file is part of ZRCola.
|
||||
|
||||
ZRCola is free software: you can redistribute it and/or modify it
|
||||
under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
ZRCola is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with ZRCola. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "common.h"
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
|
||||
namespace ZRCola {
|
||||
///
|
||||
/// Decomposition
|
||||
///
|
||||
struct decomposition {
|
||||
wchar_t src; ///< composed character
|
||||
const wchar_t *dst; ///< decomposed string
|
||||
};
|
||||
|
||||
|
||||
///
|
||||
/// Decomposes string
|
||||
///
|
||||
/// \param[in] input Input string (UTF-16)
|
||||
/// \param[in] inputMax Length of the input string in characters. Can be (size_t)-1 if \p input is zero terminated.
|
||||
/// \param[out] output Output string (UTF-16)
|
||||
/// \param[out] map The vector of source to destination index mappings (optional)
|
||||
///
|
||||
void ZRCOLA_API Decompose(_In_z_count_(inputMax) const wchar_t* input, _In_ size_t inputMax, _Out_ std::wstring &output, _Out_opt_ std::vector<mapping>* map = NULL);
|
||||
};
|
136
lib/libZRCola/include/zrcola/translate.h
Normal file
136
lib/libZRCola/include/zrcola/translate.h
Normal file
@@ -0,0 +1,136 @@
|
||||
/*
|
||||
Copyright 2015-2016 Amebis
|
||||
|
||||
This file is part of ZRCola.
|
||||
|
||||
ZRCola is free software: you can redistribute it and/or modify it
|
||||
under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
ZRCola is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with ZRCola. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "common.h"
|
||||
|
||||
#include <stdex/idrec.h>
|
||||
#include <istream>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
#pragma warning(push)
|
||||
#pragma warning(disable: 4251)
|
||||
|
||||
|
||||
namespace ZRCola {
|
||||
///
|
||||
/// Translation database
|
||||
///
|
||||
class ZRCOLA_API translation_db {
|
||||
public:
|
||||
#pragma pack(push)
|
||||
#pragma pack(4)
|
||||
///
|
||||
/// Translation index
|
||||
///
|
||||
struct index {
|
||||
unsigned __int32 start; ///< Composed character offset
|
||||
unsigned __int32 end; ///< Decomposed string end offset
|
||||
|
||||
///
|
||||
/// Returns translation string start offset
|
||||
///
|
||||
inline unsigned __int32 GetChrStart() const { return start; }
|
||||
|
||||
///
|
||||
/// Returns translation string start offset
|
||||
///
|
||||
inline unsigned __int32 GetStrStart() const { return start + 1; }
|
||||
|
||||
///
|
||||
/// Returns translation string length
|
||||
///
|
||||
inline unsigned __int32 GetStrLength() const { return end - (start + 1); }
|
||||
};
|
||||
#pragma pack(pop)
|
||||
|
||||
std::vector<index> idxComp; ///< Composition index
|
||||
std::vector<index> idxDecomp; ///< Decomposition index
|
||||
std::vector<wchar_t> data; ///< Transformation data
|
||||
|
||||
public:
|
||||
///
|
||||
/// Composes string
|
||||
///
|
||||
/// \param[in] input Input string (UTF-16)
|
||||
/// \param[in] inputMax Length of the input string in characters. Can be (size_t)-1 if \p input is zero terminated.
|
||||
/// \param[out] output Output string (UTF-16)
|
||||
/// \param[out] map The vector of source to destination index mappings (optional)
|
||||
///
|
||||
void Compose(_In_z_count_(inputMax) const wchar_t* input, _In_ size_t inputMax, _Out_ std::wstring &output, _Out_opt_ std::vector<mapping>* map = NULL) const;
|
||||
|
||||
///
|
||||
/// Decomposes string
|
||||
///
|
||||
/// \param[in] input Input string (UTF-16)
|
||||
/// \param[in] inputMax Length of the input string in characters. Can be (size_t)-1 if \p input is zero terminated.
|
||||
/// \param[out] output Output string (UTF-16)
|
||||
/// \param[out] map The vector of source to destination index mappings (optional)
|
||||
///
|
||||
void Decompose(_In_z_count_(inputMax) const wchar_t* input, _In_ size_t inputMax, _Out_ std::wstring &output, _Out_opt_ std::vector<mapping>* map = NULL) const;
|
||||
};
|
||||
|
||||
|
||||
typedef ZRCOLA_API stdex::idrec::record<translation_db, recordid_t, recordsize_t, ZRCOLA_RECORD_ALIGN> translation_rec;
|
||||
};
|
||||
|
||||
|
||||
const ZRCola::recordid_t stdex::idrec::record<ZRCola::translation_db, ZRCola::recordid_t, ZRCola::recordsize_t, ZRCOLA_RECORD_ALIGN>::id = ZRCOLA_DB_TRANSLATIONS_ID;
|
||||
|
||||
|
||||
///
|
||||
/// Reads translation database from a stream
|
||||
///
|
||||
/// \param[in] stream Input stream
|
||||
/// \param[out] t_db Translation database
|
||||
///
|
||||
/// \returns The stream \p stream
|
||||
///
|
||||
inline std::istream& operator >>(_In_ std::istream& stream, _Out_ ZRCola::translation_db &t_db)
|
||||
{
|
||||
unsigned __int32 count;
|
||||
|
||||
// Read index count.
|
||||
stream.read((char*)&count, sizeof(count));
|
||||
if (!stream.good()) return stream;
|
||||
|
||||
// Read composition index.
|
||||
t_db.idxComp.resize(count);
|
||||
stream.read((char*)t_db.idxComp.data(), sizeof(ZRCola::translation_db::index)*count);
|
||||
if (!stream.good()) return stream;
|
||||
|
||||
// Read decomposition index.
|
||||
t_db.idxDecomp.resize(count);
|
||||
stream.read((char*)t_db.idxDecomp.data(), sizeof(ZRCola::translation_db::index)*count);
|
||||
if (!stream.good()) return stream;
|
||||
|
||||
// Read data count.
|
||||
stream.read((char*)&count, sizeof(count));
|
||||
if (!stream.good()) return stream;
|
||||
|
||||
// Read data.
|
||||
t_db.data.resize(count);
|
||||
stream.read((char*)t_db.data.data(), sizeof(wchar_t)*count);
|
||||
|
||||
return stream;
|
||||
}
|
||||
|
||||
#pragma warning(pop)
|
Reference in New Issue
Block a user