ORE Studio 0.0.4
Loading...
Searching...
No Matches
TextUtils.hpp
1/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2 *
3 * Copyright (C) 2026 Marco Craveiro <marco.craveiro@gmail.com>
4 *
5 * This program is free software; you can redistribute it and/or modify it under
6 * the terms of the GNU General Public License as published by the Free Software
7 * Foundation; either version 3 of the License, or (at your option) any later
8 * version.
9 *
10 * This program is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
13 * details.
14 *
15 * You should have received a copy of the GNU General Public License along with
16 * this program; if not, write to the Free Software Foundation, Inc., 51
17 * Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 *
19 */
20#ifndef ORES_QT_TEXT_UTILS_HPP
21#define ORES_QT_TEXT_UTILS_HPP
22
23#include <algorithm>
24#include <optional>
25#include <string>
26#include <QString>
27#include "ores.qt/export.hpp"
28
29namespace ores::qt {
30
31struct TextUtils {
32 static constexpr int max_transliterated_length = 30;
33
40 static bool contains_non_latin(const QString& text) {
41 return std::any_of(text.begin(), text.end(), [](const QChar& ch) {
42 auto s = ch.script();
43 return s != QChar::Script_Common && s != QChar::Script_Latin &&
44 s != QChar::Script_Inherited;
45 });
46 }
47
55 static QString display_name_with_transliteration(
56 const std::string& name,
57 const std::optional<std::string>& transliterated_name) {
58 auto qname = QString::fromStdString(name);
59 if (transliterated_name.has_value() &&
60 !transliterated_name->empty() &&
61 contains_non_latin(qname)) {
62 auto tl = QString::fromStdString(*transliterated_name);
63 if (tl.size() > max_transliterated_length)
64 tl = tl.left(max_transliterated_length) + QChar(0x2026);
65 return qname + QStringLiteral(" (") + tl + QStringLiteral(")");
66 }
67 return qname;
68 }
69};
70
71}
72
73#endif
Qt-based graphical user interface for ORE Studio.
Definition AccountController.hpp:32