`vendor/MetasequoiaImeEngine` submodule 改为 `engine/` 目录,导入的是 product-lock.json 原本钉住的提交 c810d201,逐文件核对过 blob,因此这是一次 搬迁而不是引擎升级。引擎自己的嵌套 submodule(googlepinyinime-rev、utfcpp、 miniaudio)按各自 gitlink 一并展开,来源与提交见 engine/UPSTREAM.md。 Windows 专门化裁掉了不属于本产品的部分:whisper.cpp 与本地推理 provider、 macOS 示例宿主、整个 dictionary/ 建库流水线、上游 CI 与 release-please 配置。 词库仍按 product-lock.json 在构建时取发布产物。 引擎不再进 product-lock.json:没有 gitlink 就没有可比对的东西,锁里写一个上游 commit 等于宣称这棵树仍等于上游,而第一个 Windows 专门化改动落地时这句话就假了。 verify-contracts / verify-checkout 随之移除,verify-published 保留。 CI 与工具链:引擎源码并入根 scripts/format.sh(删掉引擎自己的那份,避免两套排除 列表分叉);引擎 voice.yml 里的 silero_vad.onnx 摘要校验移到本仓 lock job; engine-bump-triage 工作流与其测试删除;gitsubmodule 的 dependabot 频率由 daily 改为 monthly。 README、README.en、AGENTS.md、CONTRIBUTING、docs/product-release.md 及各子目录 文档同步说明新的位置与边界。
89 lines
2.1 KiB
C++
89 lines
2.1 KiB
C++
#include "unicode_query.h"
|
|
|
|
#include <algorithm>
|
|
#include <cctype>
|
|
#include <cstdint>
|
|
#include <cstdio>
|
|
#include <iterator>
|
|
#include <utf8.h>
|
|
|
|
namespace metasequoia::local_modes
|
|
{
|
|
namespace
|
|
{
|
|
bool is_hex_character(unsigned char character)
|
|
{
|
|
return std::isxdigit(character) != 0;
|
|
}
|
|
|
|
bool is_unicode_scalar(std::uint32_t codepoint)
|
|
{
|
|
return codepoint <= 0x10ffffU && (codepoint < 0xd800U || codepoint > 0xdfffU);
|
|
}
|
|
|
|
std::string codepoint_to_utf8(std::uint32_t codepoint)
|
|
{
|
|
std::string result;
|
|
utf8::append(static_cast<utf8::utfchar32_t>(codepoint), std::back_inserter(result));
|
|
return result;
|
|
}
|
|
|
|
std::string codepoint_label(std::uint32_t codepoint)
|
|
{
|
|
char buffer[16] = {};
|
|
std::snprintf(buffer, sizeof(buffer), "U+%04X", codepoint);
|
|
return buffer;
|
|
}
|
|
} // namespace
|
|
|
|
std::vector<WordItem> query_unicode(const std::string &hex_part, int limit)
|
|
{
|
|
if (limit <= 0)
|
|
{
|
|
return {};
|
|
}
|
|
|
|
std::size_t offset = 0;
|
|
if (!hex_part.empty() && hex_part.front() == '+')
|
|
{
|
|
offset = 1;
|
|
}
|
|
if (offset >= hex_part.size())
|
|
{
|
|
return {};
|
|
}
|
|
|
|
const std::string hex = hex_part.substr(offset);
|
|
if (hex.empty() || hex.size() > 6 ||
|
|
!std::all_of(hex.begin(), hex.end(), [](unsigned char character) { return is_hex_character(character); }))
|
|
{
|
|
return {};
|
|
}
|
|
|
|
std::uint32_t codepoint = 0;
|
|
for (const unsigned char character : hex)
|
|
{
|
|
codepoint <<= 4;
|
|
if (character >= '0' && character <= '9')
|
|
{
|
|
codepoint |= static_cast<std::uint32_t>(character - '0');
|
|
}
|
|
else if (character >= 'a' && character <= 'f')
|
|
{
|
|
codepoint |= static_cast<std::uint32_t>(character - 'a' + 10);
|
|
}
|
|
else
|
|
{
|
|
codepoint |= static_cast<std::uint32_t>(character - 'A' + 10);
|
|
}
|
|
}
|
|
if (!is_unicode_scalar(codepoint))
|
|
{
|
|
return {};
|
|
}
|
|
|
|
return {WordItem(codepoint_label(codepoint), codepoint_to_utf8(codepoint), static_cast<std::int64_t>(hex.size()),
|
|
CandidateSource::Generated)};
|
|
}
|
|
} // namespace metasequoia::local_modes
|