From 0cb3acf426c35da2fcd63d9c74f0a3806c815b9e Mon Sep 17 00:00:00 2001 From: Simon Rozman Date: Tue, 9 Feb 2016 15:07:54 +0100 Subject: [PATCH] Decomposition rearranged --- lib/libZRCola/include/zrcola/decompose.h | 2 +- lib/libZRCola/src/decompose.cpp | 18 ++++++++++++++++-- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/lib/libZRCola/include/zrcola/decompose.h b/lib/libZRCola/include/zrcola/decompose.h index a8966b2..4407930 100644 --- a/lib/libZRCola/include/zrcola/decompose.h +++ b/lib/libZRCola/include/zrcola/decompose.h @@ -34,5 +34,5 @@ namespace ZRCola { /// \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* map = NULL); + void ZRCOLA_API Decompose(_In_z_count_(inputMax) const wchar_t* input, _In_ size_t inputMax, _Out_ std::wstring &output, _Out_opt_ std::vector* map = NULL); }; diff --git a/lib/libZRCola/src/decompose.cpp b/lib/libZRCola/src/decompose.cpp index a05679a..f4b0ba3 100644 --- a/lib/libZRCola/src/decompose.cpp +++ b/lib/libZRCola/src/decompose.cpp @@ -20,8 +20,15 @@ #include "stdafx.h" -void ZRCOLA_API ZRCola::Decompose(_In_z_count_(inputMax) const wchar_t *input, _In_ size_t inputMax, _Out_ std::wstring &output, _Out_opt_ std::vector* map) +static inline void Decompose( + _In_count_(decompositionsCount) const ZRCola::decomposition* decompositions, + _In_ const size_t decompositionsCount, + _In_z_count_(inputMax) const wchar_t* input, + _In_ size_t inputMax, + _Out_ std::wstring &output, + _Out_opt_ std::vector* map) { + assert(decompositions || decompositionsCount == 0); assert(input || inputMax == 0); // Trim inputMax to actual length. @@ -37,6 +44,7 @@ void ZRCOLA_API ZRCola::Decompose(_In_z_count_(inputMax) const wchar_t *input, _ for (size_t i = 0; i < inputMax;) { // Find whether the character can be decomposed. wchar_t c = input[i]; + for (size_t l = 0, r = decompositionsCount;; ) { if (l < r) { size_t m = (l + r) / 2; @@ -48,7 +56,7 @@ void ZRCOLA_API ZRCola::Decompose(_In_z_count_(inputMax) const wchar_t *input, _ i++; if (map) { // Mapping changed. - map->push_back(mapping(i, output.length())); + map->push_back(ZRCola::mapping(i, output.length())); } break; } @@ -61,3 +69,9 @@ void ZRCOLA_API ZRCola::Decompose(_In_z_count_(inputMax) const wchar_t *input, _ } } } + + +void ZRCOLA_API ZRCola::Decompose(_In_z_count_(inputMax) const wchar_t* input, _In_ size_t inputMax, _Out_ std::wstring &output, _Out_opt_ std::vector* map) +{ + ::Decompose(decompositions, decompositionsCount, input, inputMax, output, map); +}