From 3aba6080015219351c026e9c0e9829b5a556734d Mon Sep 17 00:00:00 2001 From: Simon Rozman Date: Fri, 16 Sep 2022 13:54:57 +0200 Subject: [PATCH] ZRColaWS: Return source->destination index mapping Signed-off-by: Simon Rozman --- ZRColaWS/controller.hpp | 10 ++++++++++ ZRColaWS/dto.hpp | 1 + 2 files changed, 11 insertions(+) diff --git a/ZRColaWS/controller.hpp b/ZRColaWS/controller.hpp index 293b99d..63fee63 100644 --- a/ZRColaWS/controller.hpp +++ b/ZRColaWS/controller.hpp @@ -65,6 +65,7 @@ public: std::u16string dst, dst2; if (input->text) dst = cIn.convert(*input->text); + size_t src_len = dst.length(); std::vector mapping; if (input->transet) { ZRCola::mapping_vector map; @@ -92,6 +93,15 @@ public: utf16toutf8 cOut; auto dto = translateOutDto::createShared(); dto->text = cOut.convert(dst); + auto map = oatpp::Vector::createShared(); + auto m_end = mapping.cend(); + for (size_t i = 0; i < src_len; ++i) { + auto j = i; + for (auto m = mapping.cbegin(); m != m_end; ++m) + j = m->to_dst(j); + map->push_back(j); + } + dto->map = map; return createDtoResponse(Status::CODE_200, dto); } catch (std::exception &ex) { OATPP_LOGE("ZRColaWS", "%s: %s", typeid(ex).name(), ex.what()); diff --git a/ZRColaWS/dto.hpp b/ZRColaWS/dto.hpp index 655b6fa..3116406 100644 --- a/ZRColaWS/dto.hpp +++ b/ZRColaWS/dto.hpp @@ -39,6 +39,7 @@ class translateOutDto : public oatpp::DTO { DTO_INIT(translateOutDto, DTO) DTO_FIELD(String, text); + DTO_FIELD(Vector, map); }; #include OATPP_CODEGEN_END(DTO)