5#include <private/qqmlcontext_p.h>
6#include <QtCore/qnumeric.h>
7#include <QtCore/qdatetime.h>
8#include <QtCore/qtimezone.h>
10#include <private/qlocale_p.h>
11#include <private/qlocale_data_p.h>
13#include <private/qv4dateobject_p.h>
14#include <private/qv4numberobject_p.h>
15#include <private/qv4stringobject_p.h>
23#define THROW_ERROR(string) \
25 return scope.engine->throwError(QString::fromUtf8(string)); \
29#define GET_LOCALE_DATA_RESOURCE(OBJECT) \
30 QV4::Scoped<QQmlLocaleData> r(scope, OBJECT.as<QQmlLocaleData>()); \
32 THROW_ERROR("Not a valid Locale object")
44 engine->datePrototype()->defineDefaultProperty(
engine->id_toLocaleString(), method_toLocaleString);
45 engine->datePrototype()->defineDefaultProperty(
QStringLiteral(
"toLocaleTimeString"), method_toLocaleTimeString);
46 engine->datePrototype()->defineDefaultProperty(
QStringLiteral(
"toLocaleDateString"), method_toLocaleDateString);
47 engine->dateCtor()->defineDefaultProperty(
QStringLiteral(
"fromLocaleString"), method_fromLocaleString);
48 engine->dateCtor()->defineDefaultProperty(
QStringLiteral(
"fromLocaleTimeString"), method_fromLocaleTimeString);
49 engine->dateCtor()->defineDefaultProperty(
QStringLiteral(
"fromLocaleDateString"), method_fromLocaleDateString);
50 engine->dateCtor()->defineDefaultProperty(
QStringLiteral(
"timeZoneUpdated"), method_timeZoneUpdated);
79 if (
String *
s = argv[1].stringValue()) {
81 formattedDt =
r->d()->locale->toString(dt,
format);
85 formattedDt =
r->d()->locale->toString(dt,
format);
87 THROW_ERROR(
"Locale: Date.toLocaleString(): Invalid datetime format");
90 formattedDt =
r->d()->locale->toString(dt, enumFormat);
123 if (
String *
s = argv[1].stringValue()) {
125 formattedTime =
r->d()->locale->toString(
time,
format);
129 formattedTime =
r->d()->locale->toString(
time,
format);
131 THROW_ERROR(
"Locale: Date.toLocaleTimeString(): Invalid time format");
134 formattedTime =
r->d()->locale->toString(
time, enumFormat);
167 if (
String *
s = argv[1].stringValue()) {
169 formattedDate =
r->d()->locale->toString(
date,
format);
173 formattedDate =
r->d()->locale->toString(
date,
format);
175 THROW_ERROR(
"Locale: Date.loLocaleDateString(): Invalid date format");
178 formattedDate =
r->d()->locale->toString(
date, enumFormat);
189 if (
String *
s = argv[0].stringValue()) {
191 QString dateString =
s->toQString();
198 THROW_ERROR(
"Locale: Date.fromLocaleString(): Invalid arguments");
206 if (
String *
s = argv[2].stringValue()) {
208 dt =
r->d()->locale->toDateTime(dateString,
format);
212 dt =
r->d()->locale->toDateTime(dateString,
format);
214 THROW_ERROR(
"Locale: Date.fromLocaleString(): Invalid datetime format");
217 dt =
r->d()->locale->toDateTime(dateString, enumFormat);
229 if (
String *
s = argv[0].stringValue()) {
231 QString timeString =
s->toQString();
240 THROW_ERROR(
"Locale: Date.fromLocaleTimeString(): Invalid arguments");
248 if (
String *
s = argv[2].stringValue()) {
250 tm =
r->d()->locale->toTime(dateString,
format);
254 tm =
r->d()->locale->toTime(dateString,
format);
256 THROW_ERROR(
"Locale: Date.fromLocaleTimeString(): Invalid datetime format");
259 tm =
r->d()->locale->toTime(dateString, enumFormat);
277 if (
String *
s = argv[0].stringValue()) {
279 QString dateString =
s->toQString();
286 THROW_ERROR(
"Locale: Date.fromLocaleDateString(): Invalid arguments");
294 if (
String *
s = argv[2].stringValue()) {
296 dt =
r->d()->locale->toDate(dateString,
format);
300 dt =
r->d()->locale->toDate(dateString,
format);
302 THROW_ERROR(
"Locale: Date.fromLocaleDateString(): Invalid datetime format");
305 dt =
r->d()->locale->toDate(dateString, enumFormat);
315 THROW_ERROR(
"Locale: Date.timeZoneUpdated(): Invalid arguments");
327 engine->numberPrototype()->defineDefaultProperty(
engine->id_toLocaleString(), method_toLocaleString);
328 engine->numberPrototype()->defineDefaultProperty(
QStringLiteral(
"toLocaleCurrencyString"), method_toLocaleCurrencyString);
329 engine->numberCtor()->defineDefaultProperty(
QStringLiteral(
"fromLocaleString"), method_fromLocaleString);
336 THROW_ERROR(
"Locale: Number.toLocaleString(): Invalid arguments");
353 if (!argv[1].isString())
354 THROW_ERROR(
"Locale: Number.toLocaleString(): Invalid arguments");
362 THROW_ERROR(
"Locale: Number.toLocaleString(): Invalid arguments");
373 THROW_ERROR(
"Locale: Number.toLocaleCurrencyString(): Invalid arguments");
384 THROW_ERROR(
"Locale: Number.toLocaleCurrencyString(): Invalid arguments");
390 if (!argv[1].isString())
391 THROW_ERROR(
"Locale: Number.toLocaleString(): Invalid arguments");
401 if (argc < 1 || argc > 2)
402 THROW_ERROR(
"Locale: Number.fromLocaleString(): Invalid arguments");
409 THROW_ERROR(
"Locale: Number.fromLocaleString(): Invalid arguments");
425 THROW_ERROR(
"Locale: Number.fromLocaleString(): Invalid format");
439 int fdow = int(locale->firstDayOfWeek());
450 int numberOptions = int(locale->numberOptions());
458 locale->setNumberOptions(QLocale::NumberOptions {numberOptions});
469 if (argc < 1 || argc > 3) {
471 "Locale: formattedDataSize(): Expected 1-3 arguments, but received %1").
arg(argc).toLatin1());
481 THROW_ERROR(
"Locale: formattedDataSize(): Invalid argument ('precision' must be an int)");
490 THROW_ERROR(
"Locale: formattedDataSize(): Invalid argument ('format' must be DataSizeFormat)");
493 const auto format = QLocale::DataSizeFormats(intFormat);
526 result->arrayReserve(days.size());
527 for (
int i = 0;
i < days.size(); ++
i) {
528 int day = days.at(
i);
533 result->setArrayLengthUnchecked(days.size());
535 return result.asReturnedValue();
547 result->arrayReserve(langs.size());
549 for (
int i = 0;
i < langs.size(); ++
i)
552 result->setArrayLengthUnchecked(langs.size());
554 return result.asReturnedValue();
565 THROW_ERROR(
"Locale: currencySymbol(): Invalid arguments");
576#define LOCALE_FORMAT(FUNC) \
577ReturnedValue QQmlLocaleData::method_ ##FUNC (const QV4::FunctionObject *b, const QV4::Value *thisObject, const QV4::Value *argv, int argc) { \
578 QV4::Scope scope(b); \
579 const QLocale *locale = getThisLocale(scope, thisObject); \
581 return Encode::undefined(); \
583 THROW_ERROR("Locale: " #FUNC "(): Invalid arguments"); \
584 QLocale::FormatType format = QLocale::LongFormat;\
586 quint32 intFormat = argv[0].toUInt32(); \
587 format = QLocale::FormatType(intFormat); \
589 RETURN_RESULT(scope.engine->newString(locale-> FUNC (format))); \
597#define LOCALE_FORMATTED_MONTHNAME(VARIABLE) \
598ReturnedValue QQmlLocaleData::method_ ## VARIABLE (const QV4::FunctionObject *b, const QV4::Value *thisObject, const QV4::Value *argv, int argc) {\
600 const QLocale *locale = getThisLocale(scope, thisObject); \
602 return Encode::undefined(); \
603 if (argc < 1 || argc > 2) \
604 THROW_ERROR("Locale: " #VARIABLE "(): Invalid arguments"); \
605 QLocale::FormatType enumFormat = QLocale::LongFormat; \
606 int idx = argv[0].toInt32() + 1; \
607 if (idx < 1 || idx > 12) \
608 THROW_ERROR("Locale: Invalid month"); \
611 if (argv[1].isNumber()) { \
612 quint32 intFormat = argv[1].toUInt32(); \
613 QLocale::FormatType format = QLocale::FormatType(intFormat); \
614 name = locale-> VARIABLE(idx, format); \
616 THROW_ERROR("Locale: Invalid datetime format"); \
619 name = locale-> VARIABLE(idx, enumFormat); \
621 RETURN_RESULT(scope.engine->newString(name)); \
625#define LOCALE_FORMATTED_DAYNAME(VARIABLE) \
626ReturnedValue QQmlLocaleData::method_ ## VARIABLE (const QV4::FunctionObject *b, const QV4::Value *thisObject, const QV4::Value *argv, int argc) {\
628 const QLocale *locale = getThisLocale(scope, thisObject); \
630 return Encode::undefined(); \
631 if (argc < 1 || argc > 2) \
632 THROW_ERROR("Locale: " #VARIABLE "(): Invalid arguments"); \
633 QLocale::FormatType enumFormat = QLocale::LongFormat; \
634 int idx = argv[0].toInt32(); \
635 if (idx < 0 || idx > 7) \
636 THROW_ERROR("Locale: Invalid day"); \
637 if (idx == 0) idx = 7; \
640 if (argv[1].isNumber()) { \
641 quint32 intFormat = argv[1].toUInt32(); \
642 QLocale::FormatType format = QLocale::FormatType(intFormat); \
643 name = locale-> VARIABLE(idx, format); \
645 THROW_ERROR("Locale: Invalid datetime format"); \
648 name = locale-> VARIABLE(idx, enumFormat); \
650 RETURN_RESULT(scope.engine->newString(name)); \
661 const QLocale *locale = getThisLocale(scope, thisObject);
674 "Locale: toString(): Expected 1-3 arguments, but received %1").
arg(argc));
678 if (argv[0].isInteger()) {
683 const double number = argv[0].toNumber();
687 if (!argv[1].isString()) {
688 THROW_ERROR(
"Locale: the second argument to the toString overload "
689 "whose first argument is a double should be a char");
691 const char format = argv[1].toQString().at(0).toLatin1();
697 if (!argv[2].isInteger()) {
698 THROW_ERROR(
"Locale: the third argument to the toString overload "
699 "whose first argument is a double should be an int");
706 }
else if (
const DateObject *dateObject = argv[0].as<DateObject>()) {
710 "Locale: the toString() overload that takes a Date as its first "
711 "argument expects 1 or 2 arguments, but received %1").
arg(argc));
714 if (argc == 2 && argv[1].isString()) {
716 dateObject->toQDateTime(), argv[1].toQString())));
719 if (argc == 2 && !argv[1].
isNumber()) {
720 THROW_ERROR(
"Locale: the second argument to the toString overloads whose "
721 "first argument is a Date should be a string or FormatType");
729 THROW_ERROR(
"Locale: toString() expects either an int, double, or Date as its first argument");
732#define LOCALE_STRING_PROPERTY(VARIABLE) \
733ReturnedValue QQmlLocaleData::method_get_ ## VARIABLE (const QV4::FunctionObject *b, const QV4::Value *thisObject, const QV4::Value *, int) \
736 const QLocale *locale = getThisLocale(scope, thisObject); \
738 return Encode::undefined(); \
739 RETURN_RESULT(scope.engine->newString(locale-> VARIABLE()));\
744#if QT_DEPRECATED_SINCE(6, 6)
794#if QT_DEPRECATED_SINCE(6, 6)
795 o->defineAccessorProperty(
QStringLiteral(
"nativeCountryName"), QQmlLocaleData::method_get_nativeCountryName,
nullptr);
921 return wrapper.asReturnedValue();
931 if (argc != 1 || (!argv[0].isString() && !argv[0].as<StringObject>()))
1256#include "moc_qqmllocale_p.cpp"
constexpr char16_t unicode() const noexcept
Returns the numeric Unicode value of the QChar.
\inmodule QtCore\reentrant
static QDateTime currentDateTime()
This is an overloaded member function, provided for convenience. It differs from the above function o...
void setTime(QTime time)
Sets the time part of this datetime to time.
QTime time() const
Returns the time part of the datetime.
QDate date() const
Returns the date part of the datetime.
\inmodule QtCore \reentrant
QDateTime startOfDay(const QTimeZone &zone) const
QJSValue newObject()
Creates a JavaScript object of class Object.
static void registerExtension(QV4::ExecutionEngine *engine)
static void registerExtension(QV4::ExecutionEngine *engine)
\macro QT_RESTRICTED_CAST_FROM_ASCII
static QString fromLatin1(QByteArrayView ba)
This is an overloaded member function, provided for convenience. It differs from the above function o...
qsizetype size() const
Returns the number of characters in this string.
const QChar at(qsizetype i) const
Returns the character at the given index position in the string.
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
int localeAwareCompare(const QString &s) const
\inmodule QtCore \reentrant
bool isValid() const
Returns true if the time is valid; otherwise returns false.
QV4::PersistentValue prototype
~QV4LocaleDataDeletable()
QV4LocaleDataDeletable(QV4::ExecutionEngine *engine)
ObjectType::Data * allocate(Args &&... args)
Q_QML_PRIVATE_EXPORT void registerStringLocaleCompare(QV4::ExecutionEngine *engine)
Q_QML_PRIVATE_EXPORT QV4::ReturnedValue method_localeCompare(const QV4::FunctionObject *, const QV4::Value *thisObject, const QV4::Value *argv, int argc)
Q_QML_PRIVATE_EXPORT QV4::ReturnedValue locale(QV4::ExecutionEngine *engine, const QString &localeName)
Provides locale specific properties and formatted data.
Q_QML_PRIVATE_EXPORT QV4::ReturnedValue wrap(QV4::ExecutionEngine *engine, const QLocale &locale)
Combined button and popup list for selecting options.
\qmltype Particle \inqmlmodule QtQuick.Particles
static const void * symbol()
#define QT_IGNORE_DEPRECATIONS(statement)
static bool isNumber(char s)
GLboolean GLboolean GLboolean b
GLsizei const GLfloat * v
[13]
GLint GLsizei GLsizei GLenum format
GLenum GLint GLint * precision
#define GET_LOCALE_DATA_RESOURCE(OBJECT)
#define LOCALE_FORMATTED_DAYNAME(VARIABLE)
#define LOCALE_FORMATTED_MONTHNAME(VARIABLE)
static bool isLocaleObject(const QV4::Value &val)
#define LOCALE_STRING_PROPERTY(VARIABLE)
#define LOCALE_FORMAT(FUNC)
#define THROW_ERROR(string)
static QT_BEGIN_NAMESPACE QAsn1Element wrap(quint8 type, const QAsn1Element &child)
#define QStringLiteral(str)
#define V4_DEFINE_EXTENSION(dataclass, datafunction)
#define RETURN_UNDEFINED()
#define DEFINE_OBJECT_VTABLE(classname)
Q_QML_PRIVATE_EXPORT QDateTime toQDateTime() const
static ReturnedValue method_toLocaleDateString(const FunctionObject *, const Value *thisObject, const Value *argv, int argc)
static ReturnedValue method_toLocaleTimeString(const FunctionObject *, const Value *thisObject, const Value *argv, int argc)
static void timezoneUpdated(ExecutionEngine *e)
static ReturnedValue method_toLocaleString(const FunctionObject *, const Value *thisObject, const Value *argv, int argc)
static constexpr ReturnedValue undefined()
MemoryManager * memoryManager
Heap::String * newString(const QString &s=QString())
ReturnedValue throwError(const Value &value)
Heap::ArrayObject * newArrayObject(int count=0)
static ReturnedValue method_toLocaleString(const FunctionObject *, const Value *thisObject, const Value *argv, int argc)
static QV4::ReturnedValue method_get_textDirection(const QV4::FunctionObject *, const QV4::Value *thisObject, const QV4::Value *argv, int argc)
static QV4::ReturnedValue method_get_decimalPoint(const QV4::FunctionObject *, const QV4::Value *thisObject, const QV4::Value *argv, int argc)
static QV4::ReturnedValue method_currencySymbol(const QV4::FunctionObject *, const QV4::Value *thisObject, const QV4::Value *argv, int argc)
static QV4::ReturnedValue method_dayName(const QV4::FunctionObject *, const QV4::Value *thisObject, const QV4::Value *argv, int argc)
static QV4::ReturnedValue method_get_zeroDigit(const QV4::FunctionObject *, const QV4::Value *thisObject, const QV4::Value *argv, int argc)
static QV4::ReturnedValue method_get_nativeLanguageName(const QV4::FunctionObject *, const QV4::Value *thisObject, const QV4::Value *argv, int argc)
static QV4::ReturnedValue method_get_amText(const QV4::FunctionObject *, const QV4::Value *thisObject, const QV4::Value *argv, int argc)
static QV4::ReturnedValue method_standaloneMonthName(const QV4::FunctionObject *, const QV4::Value *thisObject, const QV4::Value *argv, int argc)
static QV4::ReturnedValue method_monthName(const QV4::FunctionObject *, const QV4::Value *thisObject, const QV4::Value *argv, int argc)
static QV4::ReturnedValue method_dateFormat(const QV4::FunctionObject *, const QV4::Value *thisObject, const QV4::Value *argv, int argc)
static QV4::ReturnedValue method_get_negativeSign(const QV4::FunctionObject *, const QV4::Value *thisObject, const QV4::Value *argv, int argc)
static QV4::ReturnedValue method_get_measurementSystem(const QV4::FunctionObject *, const QV4::Value *thisObject, const QV4::Value *argv, int argc)
static QV4::ReturnedValue method_standaloneDayName(const QV4::FunctionObject *, const QV4::Value *thisObject, const QV4::Value *argv, int argc)
static QV4::ReturnedValue method_dateTimeFormat(const QV4::FunctionObject *, const QV4::Value *thisObject, const QV4::Value *argv, int argc)
static QV4::ReturnedValue method_get_groupSeparator(const QV4::FunctionObject *, const QV4::Value *thisObject, const QV4::Value *argv, int argc)
static QV4::ReturnedValue method_get_firstDayOfWeek(const QV4::FunctionObject *, const QV4::Value *thisObject, const QV4::Value *argv, int argc)
static QV4::ReturnedValue method_toString(const QV4::FunctionObject *, const QV4::Value *thisObject, const QV4::Value *argv, int argc)
static QV4::ReturnedValue method_get_formattedDataSize(const QV4::FunctionObject *, const QV4::Value *thisObject, const QV4::Value *argv, int argc)
static QV4::ReturnedValue method_get_exponential(const QV4::FunctionObject *, const QV4::Value *thisObject, const QV4::Value *argv, int argc)
static QV4::ReturnedValue method_timeFormat(const QV4::FunctionObject *, const QV4::Value *thisObject, const QV4::Value *argv, int argc)
static QV4::ReturnedValue method_get_uiLanguages(const QV4::FunctionObject *, const QV4::Value *thisObject, const QV4::Value *argv, int argc)
static QV4::ReturnedValue method_get_pmText(const QV4::FunctionObject *, const QV4::Value *thisObject, const QV4::Value *argv, int argc)
static QV4::ReturnedValue method_set_numberOptions(const QV4::FunctionObject *, const QV4::Value *thisObject, const QV4::Value *argv, int argc)
static QV4::ReturnedValue method_get_positiveSign(const QV4::FunctionObject *, const QV4::Value *thisObject, const QV4::Value *argv, int argc)
static QV4::ReturnedValue method_get_weekDays(const QV4::FunctionObject *, const QV4::Value *thisObject, const QV4::Value *argv, int argc)
static QV4::ReturnedValue method_get_numberOptions(const QV4::FunctionObject *, const QV4::Value *thisObject, const QV4::Value *argv, int argc)
static V4_NEEDS_DESTROY QLocale * getThisLocale(QV4::Scope &scope, const QV4::Value *thisObject)
static QV4::ReturnedValue method_get_percent(const QV4::FunctionObject *, const QV4::Value *thisObject, const QV4::Value *argv, int argc)
static QV4::ReturnedValue method_get_nativeTerritoryName(const QV4::FunctionObject *, const QV4::Value *thisObject, const QV4::Value *argv, int argc)
static QV4::ReturnedValue method_get_name(const QV4::FunctionObject *, const QV4::Value *thisObject, const QV4::Value *argv, int argc)
static ReturnedValue method_localeCompare(const FunctionObject *, const Value *thisObject, const Value *argv, int argc)
static constexpr Value fromInt32(int i)
unsigned int toUInt32() const
QString toQString() const
QString toQStringNoThrow() const