File indexing completed on 2024-04-28 08:44:04

0001 /*
0002 SPDX-FileCopyrightText: 2020 Simon A. Eugster <simon.eu@gmail.com>
0003 SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
0004 */
0005 
0006 #pragma once
0007 
0008 #include <QtCore/QLocale>
0009 #include <QtCore/QString>
0010 
0011 #if defined(Q_OS_UNIX) && !defined(Q_OS_MAC)
0012 #   define MLT_LC_CATEGORY LC_NUMERIC
0013 #   define MLT_LC_NAME     "LC_NUMERIC"
0014 #else
0015 #   define MLT_LC_CATEGORY LC_ALL
0016 #   define MLT_LC_NAME     "LC_ALL"
0017 #endif
0018 
0019 class LocaleHandling
0020 {
0021 public:
0022 
0023     enum class MatchType { Exact = 0, DecimalOnly = 1, NoMatch = 2 };
0024 
0025     /**
0026      * Set LC_ALL to the desired locale.
0027      * The function also tries variants of .utf-8 appendixes if setting the plain locale fails.
0028      * @return The locale which was set, or an empty string if no locale could be set (e.g. not installed on the system).
0029      */
0030     static QString setLocale(const QString &lcName);
0031 
0032     static QPair<QLocale, LocaleHandling::MatchType> getQLocaleForDecimalPoint(const QString &requestedLocale, const QString &decimalPoint);
0033 
0034     /**
0035      * Reset LC_ALL to "C".
0036      * This is used for MLT to ensure that numbers are always serialised the same way
0037      * regardless of the user's locale; many locales use , or another character as decimal point.
0038      */
0039     static void resetLocale();
0040     static void resetAllLocale();
0041 };