Improve Ui::Text::String features.

This commit is contained in:
John Preston
2023-10-03 17:50:33 +04:00
parent 2b3f17e982
commit 396c229a4d
31 changed files with 85 additions and 82 deletions

View File

@@ -133,8 +133,8 @@ bool ValueParser::readTag() {
_tagsUsed.insert(_currentTagIndex);
if (_currentTagReplacer.isEmpty()) {
_currentTagReplacer = QString(4, TextCommand);
_currentTagReplacer[1] = kTextCommandLangTag;
_currentTagReplacer = QString(4, QChar(kTextCommand));
_currentTagReplacer[1] = QChar(kTextCommandLangTag);
}
_currentTagReplacer[2] = QChar(0x0020 + _currentTagIndex);
@@ -168,8 +168,10 @@ QString PrepareTestValue(const QString &current, QChar filler) {
auto result = QString(size + 1, filler);
auto inCommand = false;
for (auto i = 0; i != size; ++i) {
auto ch = current[i];
auto newInCommand = (ch.unicode() == TextCommand) ? (!inCommand) : inCommand;
const auto ch = current[i];
const auto newInCommand = (ch.unicode() == kTextCommand)
? (!inCommand)
: inCommand;
if (inCommand || newInCommand || ch.isSpace()) {
result[i + 1] = ch;
}

View File

@@ -868,8 +868,10 @@ auto ChoosePlural = ChoosePluralDefault;
int FindTagReplacementPosition(const QString &original, ushort tag) {
for (auto s = original.constData(), ch = s, e = ch + original.size(); ch != e;) {
if (*ch == TextCommand) {
if (ch + kTagReplacementSize <= e && (ch + 1)->unicode() == kTextCommandLangTag && *(ch + 3) == TextCommand) {
if (ch->unicode() == kTextCommand) {
if (ch + kTagReplacementSize <= e
&& (ch + 1)->unicode() == kTextCommandLangTag
&& (ch + 3)->unicode() == kTextCommand) {
if ((ch + 2)->unicode() == 0x0020 + tag) {
return ch - s;
} else {

View File

@@ -11,11 +11,12 @@ enum lngtag_count : int;
namespace Lang {
inline constexpr auto kTextCommand = 0x10;
inline constexpr auto kTextCommandLangTag = 0x20;
constexpr auto kTagReplacementSize = 4;
[[nodiscard]] int FindTagReplacementPosition(
const QString &original,
const QString &original,
ushort tag);
struct ShortenedCount {