4#include "qplatformdefs.h"
8#ifndef QT_NO_TRANSLATION
25#if defined(Q_OS_UNIX) && !defined(Q_OS_INTEGRITY)
27# include "private/qcore_unix_p.h"
56 0x3c, 0xb8, 0x64, 0x18, 0xca, 0xef, 0x9c, 0x95,
57 0xcd, 0x21, 0x1c, 0xbf, 0x60, 0xa1, 0xbd, 0xdd
66 if (foundLen > 0 && found[foundLen-1] ==
'\0')
68 return ((targetLen == foundLen) && memcmp(found,
target, foundLen) == 0);
79 if ((
g = (
h & 0xf0000000)) != 0)
121 if (++
offset == rulesSize)
135 if (
offset != rulesSize) {
153 && ++
offset != rulesSize);
182 bool orExprTruthValue =
false;
185 bool andExprTruthValue =
true;
188 bool truthValue =
true;
197 while (leftOperand >= 1000)
202 int rightOperand = rules[
i++];
206 truthValue = (leftOperand == rightOperand);
209 truthValue = (leftOperand < rightOperand);
212 truthValue = (leftOperand <= rightOperand);
215 int bottom = rightOperand;
216 int top = rules[
i++];
217 truthValue = (leftOperand >=
bottom && leftOperand <=
top);
221 truthValue = !truthValue;
223 andExprTruthValue = andExprTruthValue && truthValue;
225 if (
i == rulesSize || rules[
i] !=
Q_AND)
230 orExprTruthValue = orExprTruthValue || andExprTruthValue;
232 if (
i == rulesSize || rules[
i] !=
Q_OR)
237 if (orExprTruthValue)
259#
if defined(QT_USE_MMAP)
266#if defined(QT_USE_MMAP)
446 const QString & search_delimiters,
467 realname = prefix + fname + suffixOrDotQM;
468 fi.setFile(realname);
469 if (fi.isReadable() && fi.isFile())
472 realname = prefix + fname;
473 fi.setFile(realname);
474 if (fi.isReadable() && fi.isFile())
478 for (
int i = 0;
i < (int)delims.size();
i++) {
488 fname.truncate(rightmost);
500 if (realname.startsWith(u
':')) {
504 d->resource = std::make_unique<QResource>(realname);
509 d->unmapPointer =
reinterpret_cast<char *
>(
const_cast<uchar *
>(
resource->data()));
510#if defined(QT_USE_MMAP)
511 d->used_mmap =
false;
525 if (fileSize < MagicLength || fileSize > std::numeric_limits<qsizetype>::max())
543#define MAP_FAILED reinterpret_cast<void *>(-1)
548 int protection = PROT_READ;
550 void *
ptr = QT_MMAP(
nullptr,
d->unmapLength,
556 d->unmapPointer =
static_cast<char *
>(
ptr);
563 d->unmapPointer =
new (std::nothrow)
char[
d->unmapLength];
564 if (
d->unmapPointer) {
576 if (
d->do_load(
reinterpret_cast<const uchar *
>(
d->unmapPointer),
d->unmapLength,
578 d->filePath = realname;
583#if defined(QT_USE_MMAP)
592 d->resource =
nullptr;
593 d->unmapPointer =
nullptr;
603 return fi.isReadable() && fi.isFile();
615 if (!
path.isEmpty() && !
path.endsWith(u
'/'))
621 realname +=
path + filename + prefix;
622 const int realNameBaseSize = realname.
size();
634 for (
int i = languages.size()-1;
i >= 0; --
i) {
637 if (lang != lowerLang)
638 languages.insert(
i + 1, lowerLang);
641 for (
QString localeName : std::as_const(languages)) {
645 realname += localeName + suffixOrDotQM;
649 realname.truncate(realNameBaseSize + localeName.size());
653 realname.truncate(realNameBaseSize);
655 int rightmost = localeName.lastIndexOf(u
'_');
658 localeName.truncate(rightmost);
662 const int realNameBaseSizeFallbacks =
path.size() + filename.
size();
666 realname.replace(realNameBaseSizeFallbacks, prefix.
size(), suffix);
670 realname.replace(realNameBaseSizeFallbacks, suffix.
size(), prefix);
677 realname.truncate(realNameBaseSizeFallbacks);
682 realname.truncate(0);
738 return !fname.isEmpty() &&
d->do_load(fname,
directory);
771 return qFromBigEndian<quint16>(
data);
776 return qFromBigEndian<quint32>(
data);
791 if (!
tag || !blockLen)
817 dependencies.append(dep);
828 for (
const QString &dependency : std::as_const(dependencies)) {
829 auto translator = std::make_unique<QTranslator>();
856 const char *sourceText,
const char *comment,
uint numerus)
858 const uchar *tn =
nullptr;
860 const uint sourceTextLen =
uint(strlen(sourceText));
862 const uint commentLen =
uint(strlen(comment));
871 case Tag_Translation: {
886 case Tag_SourceText: {
889 if (!
match(
m,
len, sourceText, sourceTextLen))
905 if (*
m && !
match(
m,
len, comment, commentLen))
923 const char *comment,
int n)
const
927 if (sourceText ==
nullptr)
929 if (comment ==
nullptr)
936 goto searchDependencies;
965 goto searchDependencies;
984 }
else if (
hash <
h) {
1004 sourceText, comment, numerus);
1033#if defined(QT_USE_MMAP)
1087 return d->do_translate(
context, sourceText, disambiguation,
n);
1097 return !
d->messageArray && !
d->offsetArray && !
d->contextArray
1098 &&
d->subTranslators.empty();
1129#include "moc_qtranslator.cpp"
static QByteArray fromRawData(const char *data, qsizetype size)
Constructs a QByteArray that uses the first size bytes of the data array.
static bool isTranslatorInstalled(QTranslator *translator)
static QCoreApplication * instance() noexcept
Returns a pointer to the application's QCoreApplication (or QGuiApplication/QApplication) instance.
static void postEvent(QObject *receiver, QEvent *event, int priority=Qt::NormalEventPriority)
static bool removeTranslator(QTranslator *messageFile)
Removes the translation file translationFile from the list of translation files used by this applicat...
\inmodule QtCore\reentrant
bool seek(qint64 offset) override
For random-access devices, this function sets the current position to pos, returning true on success,...
int handle() const
Returns the file handle of the file.
void close() override
Calls QFileDevice::flush() and closes the file.
QString absolutePath() const
Returns the absolute path of the file system entry this QFileInfo refers to, excluding the entry's na...
QFILE_MAYBE_NODISCARD bool open(OpenMode flags) override
Opens the file using OpenMode mode, returning true if successful; otherwise false.
qint64 size() const override
\reimp
qint64 read(char *data, qint64 maxlen)
Reads at most maxSize bytes from the device into data, and returns the number of bytes read.
\macro QT_RESTRICTED_CAST_FROM_ASCII
qsizetype lastIndexOf(QChar c, Qt::CaseSensitivity cs=Qt::CaseSensitive) const noexcept
bool isEmpty() const noexcept
Returns true if the string has no characters; otherwise returns false.
void clear()
Clears the contents of the string and makes it null.
bool isNull() const
Returns true if this string is null; otherwise returns false.
qsizetype size() const noexcept
Returns the number of characters in this string.
static QString fromUtf8(QByteArrayView utf8)
This is an overloaded member function, provided for convenience. It differs from the above function o...
bool endsWith(const QString &s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Returns true if the string ends with s; otherwise returns false.
QString toLower() const &
QChar * data()
Returns a pointer to the data stored in the QString.
bool do_load(const QString &filename, const QString &directory)
std::unique_ptr< QResource > resource
QString do_translate(const char *context, const char *sourceText, const char *comment, int n) const
const uchar * messageArray
std::vector< std::unique_ptr< QTranslator > > subTranslators
const uchar * numerusRulesArray
const uchar * contextArray
const uchar * offsetArray
QTranslator(QObject *parent=nullptr)
Constructs an empty message file object with parent parent that is not connected to any file.
~QTranslator()
Destroys the object and frees any allocated resources.
virtual bool isEmpty() const
Returns true if this translator is empty, otherwise returns false.
bool load(const QString &filename, const QString &directory=QString(), const QString &search_delimiters=QString(), const QString &suffix=QString())
Loads filename + suffix (".qm" if the suffix is not specified), which may be an absolute file name or...
virtual QString translate(const char *context, const char *sourceText, const char *disambiguation=nullptr, int n=-1) const
Returns the translation for the key (context, sourceText, disambiguation).
QHash< int, QWidget * > hash
[35multi]
Combined button and popup list for selecting options.
constexpr Initialization Uninitialized
AudioChannelLayoutTag tag
quint8 qFromBigEndian< quint8 >(const void *src)
static ControlElement< T > * ptr(QWidget *widget)
GLdouble GLdouble GLdouble GLdouble top
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
GLenum GLuint GLintptr offset
GLfloat GLfloat GLfloat GLfloat h
GLdouble GLdouble GLdouble GLdouble q
GLsizei const GLchar *const * path
static QT_BEGIN_NAMESPACE bool isRelative(const QString &path)
#define QStringLiteral(str)
static QString getMessage(const uchar *m, const uchar *end, const char *context, const char *sourceText, const char *comment, uint numerus)
static quint32 read32(const uchar *data)
static void elfHash_continue(const char *name, uint &h)
static bool isValidNumerusRules(const uchar *rules, uint rulesSize)
static Q_NEVER_INLINE bool is_readable_file(const QString &name)
static const int MagicLength
static QString dotQmLiteral()
static uint elfHash(const char *name)
static bool match(const uchar *found, uint foundLen, const char *target, uint targetLen)
static const uchar magic[MagicLength]
static uint numerusHelper(int n, const uchar *rules, uint rulesSize)
static QString find_translation(const QLocale &locale, const QString &filename, const QString &prefix, const QString &directory, const QString &suffix)
static quint8 read8(const uchar *data)
static quint16 read16(const uchar *data)
static void elfHash_finish(uint &h)
if(qFloatDistance(a, b)<(1<< 7))
[0]