From 399430bb41a62d7c9953dc174cab1ce55c238c8f Mon Sep 17 00:00:00 2001 From: Ivailo Monev Date: Tue, 13 Feb 2018 04:06:43 +0000 Subject: [PATCH] almost complete QChar, QList, QRegExp, QSet, QString, QStringList and QVector bindings Signed-off-by: Ivailo Monev --- bindings/KtCore.i | 64 ++--- bindings/core/qchar.i | 258 ++++++++++++++++++++ bindings/core/qlist.i | 104 ++++++++ bindings/core/qregexp.i | 67 ++++++ bindings/core/qset.i | 68 ++++++ bindings/core/qstring.i | 571 ++++++++++++++++++++++++++++++++++++++++++++ bindings/core/qstringlist.i | 57 +++++ bindings/core/qvector.i | 101 ++++++++ src/core/tools/qstring.h | 2 +- 9 files changed, 1250 insertions(+), 42 deletions(-) create mode 100644 bindings/core/qchar.i create mode 100644 bindings/core/qlist.i create mode 100644 bindings/core/qregexp.i create mode 100644 bindings/core/qset.i create mode 100644 bindings/core/qstring.i create mode 100644 bindings/core/qstringlist.i create mode 100644 bindings/core/qvector.i diff --git a/bindings/KtCore.i b/bindings/KtCore.i index 9beba11a5..72bceff80 100644 --- a/bindings/KtCore.i +++ b/bindings/KtCore.i @@ -1,12 +1,33 @@ %module KtCore +%include "core/qchar.i" +%include "core/qlist.i" +%include "core/qregexp.i" +%include "core/qset.i" +%include "core/qstring.i" +%include "core/qstringlist.i" +%include "core/qvector.i" + +%template(QListInt) QList; +%template(QListQChar) QList; +%template(QListQString) QList; + +%template(QSetInt) QSet; +%template(QSetQChar) QSet; +%template(QSetQString) QSet; + +%template(QVectorInt) QVector; +%template(QVectorQChar) QVector; +%template(QVectorQString) QVector; + %{ -#include "QtCore/QtCore" +#include "QtCore/QObject" +#include "QtCore/QCoreApplication" +#include "QtCore/QFile" QT_USE_NAMESPACE %} - class QObject { public: QObject(QObject *parent = Q_NULLPTR); @@ -22,45 +43,6 @@ public: static int exec(); }; -class QChar { -public: - QChar(const char c); - QChar(const uchar c); - QChar(const uchar c, uchar r); - QChar(const ushort rc); - QChar(const short rc); - QChar(const uint rc); - QChar(const int rc); - - char toAscii() const; - char toLatin1() const; - ushort unicode() const; - - bool isNull() const; - bool isPrint() const; - bool isPunct() const; - bool isSpace() const; - bool isMark() const; - bool isLetter() const; - bool isNumber() const; - bool isLetterOrNumber() const; - bool isDigit() const; - bool isSymbol() const; - bool isLower() const; - bool isUpper() const; - bool isTitleCase() const; -}; - -class QString { -public: - QString(const char *ch); - QString(const QChar *unicode, int size = -1); - QString(const QChar c); - QString(const int size, const QChar c); - QString(const QString &); - ~QString(); -}; - class QFile { public: QFile(QString filename); diff --git a/bindings/core/qchar.i b/bindings/core/qchar.i new file mode 100644 index 000000000..326157157 --- /dev/null +++ b/bindings/core/qchar.i @@ -0,0 +1,258 @@ +%{ +#include "QtCore/qchar.h" +QT_USE_NAMESPACE +%} + +#undef QT_FASTCALL +#define QT_FASTCALL + +class QLatin1Char +{ +public: + QLatin1Char(const char c); + char toLatin1() const; + ushort unicode() const; +}; + + +class QChar { +public: + QChar(); +#ifndef QT_NO_CAST_FROM_ASCII + QChar(const char c); + QChar(const uchar c); +#endif + QChar(const QLatin1Char ch); + QChar(const uchar c, uchar r); + QChar(const ushort rc); + QChar(const short rc); + QChar(const uint rc); + QChar(const int rc); + enum SpecialCharacter { + Null = 0x0000, + Nbsp = 0x00a0, + ReplacementCharacter = 0xfffd, + ObjectReplacementCharacter = 0xfffc, + ByteOrderMark = 0xfeff, + ByteOrderSwapped = 0xfffe, + ParagraphSeparator = 0x2029, + LineSeparator = 0x2028 + }; + QChar(const SpecialCharacter sc); + + // Unicode information + + enum Category + { + NoCategory, // ### Qt 5: replace with Other_NotAssigned + + Mark_NonSpacing, // Mn + Mark_SpacingCombining, // Mc + Mark_Enclosing, // Me + + Number_DecimalDigit, // Nd + Number_Letter, // Nl + Number_Other, // No + + Separator_Space, // Zs + Separator_Line, // Zl + Separator_Paragraph, // Zp + + Other_Control, // Cc + Other_Format, // Cf + Other_Surrogate, // Cs + Other_PrivateUse, // Co + Other_NotAssigned, // Cn + + Letter_Uppercase, // Lu + Letter_Lowercase, // Ll + Letter_Titlecase, // Lt + Letter_Modifier, // Lm + Letter_Other, // Lo + + Punctuation_Connector, // Pc + Punctuation_Dash, // Pd + Punctuation_Open, // Ps + Punctuation_Close, // Pe + Punctuation_InitialQuote, // Pi + Punctuation_FinalQuote, // Pf + Punctuation_Other, // Po + + Symbol_Math, // Sm + Symbol_Currency, // Sc + Symbol_Modifier, // Sk + Symbol_Other // So + }; + + enum Direction + { + DirL, DirR, DirEN, DirES, DirET, DirAN, DirCS, DirB, DirS, DirWS, DirON, + DirLRE, DirLRO, DirAL, DirRLE, DirRLO, DirPDF, DirNSM, DirBN + }; + + enum Decomposition + { + NoDecomposition, + Canonical, + Font, + NoBreak, + Initial, + Medial, + Final, + Isolated, + Circle, + Super, + Sub, + Vertical, + Wide, + Narrow, + Small, + Square, + Compat, + Fraction + + }; + + enum Joining + { + OtherJoining, Dual, Right, Center + }; + + enum CombiningClass + { + Combining_BelowLeftAttached = 200, + Combining_BelowAttached = 202, + Combining_BelowRightAttached = 204, + Combining_LeftAttached = 208, + Combining_RightAttached = 210, + Combining_AboveLeftAttached = 212, + Combining_AboveAttached = 214, + Combining_AboveRightAttached = 216, + + Combining_BelowLeft = 218, + Combining_Below = 220, + Combining_BelowRight = 222, + Combining_Left = 224, + Combining_Right = 226, + Combining_AboveLeft = 228, + Combining_Above = 230, + Combining_AboveRight = 232, + + Combining_DoubleBelow = 233, + Combining_DoubleAbove = 234, + Combining_IotaSubscript = 240 + }; + + enum UnicodeVersion { + Unicode_Unassigned, // ### Qt 5: assign with some constantly big value + Unicode_1_1, + Unicode_2_0, + Unicode_2_1_2, + Unicode_3_0, + Unicode_3_1, + Unicode_3_2, + Unicode_4_0, + Unicode_4_1, + Unicode_5_0 + }; + // ****** WHEN ADDING FUNCTIONS, CONSIDER ADDING TO QCharRef TOO + + Category category() const; + Direction direction() const; + Joining joining() const; + bool hasMirrored() const; + unsigned char combiningClass() const; + + QChar mirroredChar() const; + QString decomposition() const; + Decomposition decompositionTag() const; + + int digitValue() const; + QChar toLower() const; + QChar toUpper() const; + QChar toTitleCase() const; + QChar toCaseFolded() const; + + UnicodeVersion unicodeVersion() const; + + char toAscii() const; + char toLatin1() const; + ushort unicode() const; + ushort &unicode(); + + static QChar fromAscii(const char c); + static QChar fromLatin1(const char c); + + bool isNull() const; + bool isPrint() const; + bool isPunct() const; + bool isSpace() const; + bool isMark() const; + bool isLetter() const; + bool isNumber() const; + bool isLetterOrNumber() const; + bool isDigit() const; + bool isSymbol() const; + bool isLower() const; + bool isUpper() const; + bool isTitleCase() const; + + bool isHighSurrogate() const; + bool isLowSurrogate() const; + + uchar cell() const; + uchar row() const; + void setCell(uchar cell); + void setRow(uchar row); + + static bool isHighSurrogate(uint ucs4); + static bool isLowSurrogate(uint ucs4); + static bool requiresSurrogates(uint ucs4); + static uint surrogateToUcs4(ushort high, ushort low); + static uint surrogateToUcs4(QChar high, QChar low); + static ushort highSurrogate(uint ucs4); + static ushort lowSurrogate(uint ucs4); + + static Category QT_FASTCALL category(const uint ucs4); + static Category QT_FASTCALL category(const ushort ucs2); + static Direction QT_FASTCALL direction(const uint ucs4); + static Direction QT_FASTCALL direction(const ushort ucs2); + static Joining QT_FASTCALL joining(const uint ucs4); + static Joining QT_FASTCALL joining(const ushort ucs2); + static unsigned char QT_FASTCALL combiningClass(const uint ucs4); + static unsigned char QT_FASTCALL combiningClass(const ushort ucs2); + + static uint QT_FASTCALL mirroredChar(const uint ucs4); + static ushort QT_FASTCALL mirroredChar(const ushort ucs2); + static Decomposition QT_FASTCALL decompositionTag(const uint ucs4); + + static int QT_FASTCALL digitValue(const uint ucs4); + static int QT_FASTCALL digitValue(const ushort ucs2); + static uint QT_FASTCALL toLower(const uint ucs4); + static ushort QT_FASTCALL toLower(const ushort ucs2); + static uint QT_FASTCALL toUpper(const uint ucs4); + static ushort QT_FASTCALL toUpper(const ushort ucs2); + static uint QT_FASTCALL toTitleCase(const uint ucs4); + static ushort QT_FASTCALL toTitleCase(const ushort ucs2); + static uint QT_FASTCALL toCaseFolded(const uint ucs4); + static ushort QT_FASTCALL toCaseFolded(const ushort ucs2); + + static UnicodeVersion QT_FASTCALL unicodeVersion(const uint ucs4); + static UnicodeVersion QT_FASTCALL unicodeVersion(const ushort ucs2); + + static UnicodeVersion QT_FASTCALL currentUnicodeVersion(); + + static QString QT_FASTCALL decomposition(uint ucs4); + + +private: +#ifdef QT_NO_CAST_FROM_ASCII + QChar(const char c); + QChar(const uchar c); +#endif +}; + +#ifndef QT_NO_DATASTREAM +QDataStream &operator<<(QDataStream &, const QChar &); +QDataStream &operator>>(QDataStream &, QChar &); +#endif diff --git a/bindings/core/qlist.i b/bindings/core/qlist.i new file mode 100644 index 000000000..00731f207 --- /dev/null +++ b/bindings/core/qlist.i @@ -0,0 +1,104 @@ +%{ +#include "QtCore/qlist.h" +QT_USE_NAMESPACE +%} + +template +class QList +{ +public: + QList(); + QList(const QList &l); + ~QList(); + QList &operator=(const QList &l); +#ifdef Q_COMPILER_RVALUE_REFS + QList &operator=(QList &&other); +#endif + void swap(QList &other); +#ifdef Q_COMPILER_INITIALIZER_LISTS + QList(std::initializer_list args); +#endif + bool operator==(const QList &l) const; + bool operator!=(const QList &l) const; + + int size() const; + + void detach(); + + void detachShared(); + + bool isDetached() const; + void setSharable(bool sharable); + bool isSharedWith(const QList &other) const; + + bool isEmpty() const; + + void clear(); + + const T &at(int i) const; + const T &operator[](int i) const; + T &operator[](int i); + + void reserve(int size); + void append(const T &t); + void append(const QList &t); + void prepend(const T &t); + void insert(int i, const T &t); + void replace(int i, const T &t); + void removeAt(int i); + int removeAll(const T &t); + bool removeOne(const T &t); + T takeAt(int i); + T takeFirst(); + T takeLast(); + void move(int from, int to); + void swap(int i, int j); + int indexOf(const T &t, int from = 0) const; + int lastIndexOf(const T &t, int from = -1) const; + bool contains(const T &t) const; + int count(const T &t) const; + + // more Qt + int count() const; + int length() const; + T& first(); + const T& first() const; + T& last(); + const T& last() const; + void removeFirst(); + void removeLast(); + bool startsWith(const T &t) const; + bool endsWith(const T &t) const; + QList mid(int pos, int length = -1) const; + + T value(int i) const; + T value(int i, const T &defaultValue) const; + + // stl compatibility + void push_back(const T &t); + void push_front(const T &t); + T& front(); + const T& front() const; + T& back(); + const T& back() const; + void pop_front(); + void pop_back(); + bool empty() const; + + + // comfort + QList &operator+=(const QList &l); + QList operator+(const QList &l) const; + QList &operator+=(const T &t); + QList &operator<< (const T &t); + QList &operator<<(const QList &l); + + QVector toVector() const; + QSet toSet() const; + + static QList fromVector(const QVector &vector); + static QList fromSet(const QSet &set); + + static QList fromStdList(const std::list &list); + std::list toStdList() const; +}; diff --git a/bindings/core/qregexp.i b/bindings/core/qregexp.i new file mode 100644 index 000000000..7dcb6884c --- /dev/null +++ b/bindings/core/qregexp.i @@ -0,0 +1,67 @@ +%{ +#include "QtCore/qregexp.h" +QT_USE_NAMESPACE +%} + +#ifndef QT_NO_REGEXP + +class QRegExp +{ +public: + enum PatternSyntax { + RegExp, + Wildcard, + FixedString, + RegExp2, + WildcardUnix, + W3CXmlSchema11 }; + enum CaretMode { CaretAtZero, CaretAtOffset, CaretWontMatch }; + + QRegExp(); + QRegExp(const QString &pattern, Qt::CaseSensitivity cs = Qt::CaseSensitive, + PatternSyntax syntax = RegExp); + QRegExp(const QRegExp &rx); + ~QRegExp(); + QRegExp &operator=(const QRegExp &rx); +#ifdef Q_COMPILER_RVALUE_REFS + QRegExp &operator=(QRegExp &&other); +#endif + void swap(QRegExp &other); + + bool operator==(const QRegExp &rx) const; + bool operator!=(const QRegExp &rx) const; + + bool isEmpty() const; + bool isValid() const; + QString pattern() const; + void setPattern(const QString &pattern); + Qt::CaseSensitivity caseSensitivity() const; + void setCaseSensitivity(Qt::CaseSensitivity cs); + PatternSyntax patternSyntax() const; + void setPatternSyntax(PatternSyntax syntax); + + bool isMinimal() const; + void setMinimal(bool minimal); + + bool exactMatch(const QString &str) const; + + int indexIn(const QString &str, int offset = 0, CaretMode caretMode = CaretAtZero) const; + int lastIndexIn(const QString &str, int offset = -1, CaretMode caretMode = CaretAtZero) const; + int matchedLength() const; +#ifndef QT_NO_REGEXP_CAPTURE + int captureCount() const; + QStringList capturedTexts() const; + QString cap(int nth = 0) const; + int pos(int nth = 0) const; + QString errorString() const; +#endif + + static QString escape(const QString &str); +}; + +#ifndef QT_NO_DATASTREAM +QDataStream &operator<<(QDataStream &out, const QRegExp ®Exp); +QDataStream &operator>>(QDataStream &in, QRegExp ®Exp); +#endif + +#endif // QT_NO_REGEXP diff --git a/bindings/core/qset.i b/bindings/core/qset.i new file mode 100644 index 000000000..c022afbfa --- /dev/null +++ b/bindings/core/qset.i @@ -0,0 +1,68 @@ +%{ +#include "QtCore/qset.h" +QT_USE_NAMESPACE +%} + +template +class QSet +{ +public: + QSet(); + QSet(const QSet &other); + + QSet &operator=(const QSet &other); +#ifdef Q_COMPILER_RVALUE_REFS + QSet &operator=(QSet &&other); +#endif + void swap(QSet &other); + + bool operator==(const QSet &other) const; + bool operator!=(const QSet &other) const; + + int size() const; + + bool isEmpty() const; + + int capacity() const; + void reserve(int size); + void squeeze(); + + void detach(); + bool isDetached() const; + void setSharable(bool sharable); + + void clear(); + + bool remove(const T &value); + + bool contains(const T &value) const; + + bool contains(const QSet &set) const; + + // more Qt + int count() const; + QSet &unite(const QSet &other); + QSet &intersect(const QSet &other); + QSet &subtract(const QSet &other); + + bool empty() const; + // comfort + QSet &operator<<(const T &value); + QSet &operator|=(const QSet &other); + QSet &operator|=(const T &value); + QSet &operator&=(const QSet &other); + QSet &operator&=(const T &value); + QSet &operator+=(const QSet &other); + QSet &operator+=(const T &value); + QSet &operator-=(const QSet &other); + QSet &operator-=(const T &value); + QSet operator|(const QSet &other) const; + QSet operator&(const QSet &other) const; + QSet operator+(const QSet &other) const; + QSet operator-(const QSet &other) const; + + QList toList() const; + QList values() const; + + static QSet fromList(const QList &list); +}; diff --git a/bindings/core/qstring.i b/bindings/core/qstring.i new file mode 100644 index 000000000..0c42bc54a --- /dev/null +++ b/bindings/core/qstring.i @@ -0,0 +1,571 @@ +%{ +#include "QtCore/qstring.h" +QT_USE_NAMESPACE +%} + +#undef Q_REQUIRED_RESULT +#define Q_REQUIRED_RESULT + +class QString +{ +public: + QString(); + QString(const QChar *unicode, int size = -1); + QString(const QChar c); + QString(const int size, const QChar c); + QString(const QLatin1String &latin1); + QString(const QString &); + ~QString(); + QString &operator=(QChar c); + QString &operator=(const QString &); + QString &operator=(const QLatin1String &); +#ifdef Q_COMPILER_RVALUE_REFS + QString &operator=(QString &&other); +#endif + void swap(QString &other); + int size() const; + int count() const; + int length() const; + bool isEmpty() const; + bool isNull() const; + void resize(int size); + + QString &fill(QChar c, int size = -1); + void truncate(int pos); + void chop(int n); + + int capacity() const; + void reserve(int size); + void squeeze(); + + const QChar *unicode() const; + QChar *data(); + const QChar *data() const; + const QChar *constData() const; + + void detach(); + bool isDetached() const; + bool isSharedWith(const QString &other) const; + void clear(); + + const QChar at(int i) const; + const QChar operator[](int i) const; + QCharRef operator[](int i); + const QChar operator[](uint i) const; + QCharRef operator[](uint i); + + QString arg(qlonglong a, int fieldwidth=0, int base=10, + const QChar &fillChar = QLatin1Char(' ')) const Q_REQUIRED_RESULT; + QString arg(qulonglong a, int fieldwidth=0, int base=10, + const QChar &fillChar = QLatin1Char(' ')) const Q_REQUIRED_RESULT; + QString arg(long a, int fieldwidth=0, int base=10, + const QChar &fillChar = QLatin1Char(' ')) const Q_REQUIRED_RESULT; + QString arg(ulong a, int fieldwidth=0, int base=10, + const QChar &fillChar = QLatin1Char(' ')) const Q_REQUIRED_RESULT; + QString arg(int a, int fieldWidth = 0, int base = 10, + const QChar &fillChar = QLatin1Char(' ')) const Q_REQUIRED_RESULT; + QString arg(uint a, int fieldWidth = 0, int base = 10, + const QChar &fillChar = QLatin1Char(' ')) const Q_REQUIRED_RESULT; + QString arg(short a, int fieldWidth = 0, int base = 10, + const QChar &fillChar = QLatin1Char(' ')) const Q_REQUIRED_RESULT; + QString arg(ushort a, int fieldWidth = 0, int base = 10, + const QChar &fillChar = QLatin1Char(' ')) const Q_REQUIRED_RESULT; + QString arg(double a, int fieldWidth = 0, char fmt = 'g', int prec = -1, + const QChar &fillChar = QLatin1Char(' ')) const Q_REQUIRED_RESULT; + QString arg(char a, int fieldWidth = 0, + const QChar &fillChar = QLatin1Char(' ')) const Q_REQUIRED_RESULT; + QString arg(QChar a, int fieldWidth = 0, + const QChar &fillChar = QLatin1Char(' ')) const Q_REQUIRED_RESULT; + QString arg(const QString &a, int fieldWidth = 0, + const QChar &fillChar = QLatin1Char(' ')) const Q_REQUIRED_RESULT; + QString arg(const QString &a1, const QString &a2) const Q_REQUIRED_RESULT; + QString arg(const QString &a1, const QString &a2, const QString &a3) const Q_REQUIRED_RESULT; + QString arg(const QString &a1, const QString &a2, const QString &a3, + const QString &a4) const Q_REQUIRED_RESULT; + QString arg(const QString &a1, const QString &a2, const QString &a3, + const QString &a4, const QString &a5) const Q_REQUIRED_RESULT; + QString arg(const QString &a1, const QString &a2, const QString &a3, + const QString &a4, const QString &a5, const QString &a6) const Q_REQUIRED_RESULT; + QString arg(const QString &a1, const QString &a2, const QString &a3, + const QString &a4, const QString &a5, const QString &a6, + const QString &a7) const Q_REQUIRED_RESULT; + QString arg(const QString &a1, const QString &a2, const QString &a3, + const QString &a4, const QString &a5, const QString &a6, + const QString &a7, const QString &a8) const Q_REQUIRED_RESULT; + QString arg(const QString &a1, const QString &a2, const QString &a3, + const QString &a4, const QString &a5, const QString &a6, + const QString &a7, const QString &a8, const QString &a9) const Q_REQUIRED_RESULT; + + QString &vsprintf(const char *format, va_list ap) +#if defined(Q_CC_GNU) && !defined(__INSURE__) + __attribute__ ((format (printf, 2, 0))) +#endif + ; + QString &sprintf(const char *format, ...) +#if defined(Q_CC_GNU) && !defined(__INSURE__) + __attribute__ ((format (printf, 2, 3))) +#endif + ; + + int indexOf(QChar c, int from = 0, Qt::CaseSensitivity cs = Qt::CaseSensitive) const; + int indexOf(const QString &s, int from = 0, Qt::CaseSensitivity cs = Qt::CaseSensitive) const; + int indexOf(const QLatin1String &s, int from = 0, Qt::CaseSensitivity cs = Qt::CaseSensitive) const; + int indexOf(const QStringRef &s, int from = 0, Qt::CaseSensitivity cs = Qt::CaseSensitive) const; + int lastIndexOf(QChar c, int from = -1, Qt::CaseSensitivity cs = Qt::CaseSensitive) const; + int lastIndexOf(const QString &s, int from = -1, Qt::CaseSensitivity cs = Qt::CaseSensitive) const; + int lastIndexOf(const QLatin1String &s, int from = -1, Qt::CaseSensitivity cs = Qt::CaseSensitive) const; + int lastIndexOf(const QStringRef &s, int from = -1, Qt::CaseSensitivity cs = Qt::CaseSensitive) const; + + bool contains(QChar c, Qt::CaseSensitivity cs = Qt::CaseSensitive) const; + bool contains(const QString &s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const; + bool contains(const QStringRef &s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const; + int count(QChar c, Qt::CaseSensitivity cs = Qt::CaseSensitive) const; + int count(const QString &s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const; + int count(const QStringRef &s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const; + +#ifndef QT_NO_REGEXP + int indexOf(const QRegExp &, int from = 0) const; + int lastIndexOf(const QRegExp &, int from = -1) const; + bool contains(const QRegExp &rx) const; + int count(const QRegExp &) const; + + int indexOf(QRegExp &, int from = 0) const; + int lastIndexOf(QRegExp &, int from = -1) const; + bool contains(QRegExp &rx) const; +#endif + + enum SectionFlags { + SectionDefault = 0x00, + SectionSkipEmpty = 0x01, + SectionIncludeLeadingSep = 0x02, + SectionIncludeTrailingSep = 0x04, + SectionCaseInsensitiveSeps = 0x08 + }; + + QString section(QChar sep, int start, int end = -1, SectionFlags flags = SectionDefault) const; + QString section(const QString &in_sep, int start, int end = -1, SectionFlags flags = SectionDefault) const; +#ifndef QT_NO_REGEXP + QString section(const QRegExp ®, int start, int end = -1, SectionFlags flags = SectionDefault) const; +#endif + + QString left(int n) const Q_REQUIRED_RESULT; + QString right(int n) const Q_REQUIRED_RESULT; + QString mid(int position, int n = -1) const Q_REQUIRED_RESULT; + QStringRef leftRef(int n) const Q_REQUIRED_RESULT; + QStringRef rightRef(int n) const Q_REQUIRED_RESULT; + QStringRef midRef(int position, int n = -1) const Q_REQUIRED_RESULT; + + bool startsWith(const QString &s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const; + bool startsWith(const QStringRef &s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const; + bool startsWith(const QLatin1String &s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const; + bool startsWith(const QChar &c, Qt::CaseSensitivity cs = Qt::CaseSensitive) const; + bool endsWith(const QString &s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const; + bool endsWith(const QStringRef &s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const; + bool endsWith(const QLatin1String &s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const; + bool endsWith(const QChar &c, Qt::CaseSensitivity cs = Qt::CaseSensitive) const; + + QString leftJustified(int width, QChar fill = QLatin1Char(' '), bool trunc = false) const Q_REQUIRED_RESULT; + QString rightJustified(int width, QChar fill = QLatin1Char(' '), bool trunc = false) const Q_REQUIRED_RESULT; + + QString toLower() const Q_REQUIRED_RESULT; + QString toUpper() const Q_REQUIRED_RESULT; + QString toCaseFolded() const Q_REQUIRED_RESULT; + + QString trimmed() const Q_REQUIRED_RESULT; + QString simplified() const Q_REQUIRED_RESULT; + + QString &insert(int i, QChar c); + QString &insert(int i, const QChar *uc, int len); + QString &insert(int i, const QString &s); + QString &insert(int i, const QLatin1String &s); + QString &append(QChar c); + QString &append(const QString &s); + QString &append(const QStringRef &s); + QString &append(const QLatin1String &s); + QString &prepend(QChar c); + QString &prepend(const QString &s); + QString &prepend(const QLatin1String &s); + + QString &operator+=(QChar c); + QString &operator+=(QChar::SpecialCharacter c); + QString &operator+=(const QString &s); + QString &operator+=(const QStringRef &s); + QString &operator+=(const QLatin1String &s); + + QString &remove(int i, int len); + QString &remove(QChar c, Qt::CaseSensitivity cs = Qt::CaseSensitive); + QString &remove(const QString &s, Qt::CaseSensitivity cs = Qt::CaseSensitive); + QString &replace(int i, int len, QChar after); + QString &replace(int i, int len, const QChar *s, int slen); + QString &replace(int i, int len, const QString &after); + QString &replace(QChar before, QChar after, Qt::CaseSensitivity cs = Qt::CaseSensitive); + QString &replace(const QChar *before, int blen, const QChar *after, int alen, Qt::CaseSensitivity cs = Qt::CaseSensitive); + QString &replace(const QLatin1String &before, const QLatin1String &after, Qt::CaseSensitivity cs = Qt::CaseSensitive); + QString &replace(const QLatin1String &before, const QString &after, Qt::CaseSensitivity cs = Qt::CaseSensitive); + QString &replace(const QString &before, const QLatin1String &after, Qt::CaseSensitivity cs = Qt::CaseSensitive); + QString &replace(const QString &before, const QString &after, + Qt::CaseSensitivity cs = Qt::CaseSensitive); + QString &replace(QChar c, const QString &after, Qt::CaseSensitivity cs = Qt::CaseSensitive); + QString &replace(QChar c, const QLatin1String &after, Qt::CaseSensitivity cs = Qt::CaseSensitive); +#ifndef QT_NO_REGEXP + QString &replace(const QRegExp &rx, const QString &after); + QString &remove(const QRegExp &rx); +#endif + + enum SplitBehavior { KeepEmptyParts, SkipEmptyParts }; + + QStringList split(const QString &sep, SplitBehavior behavior = KeepEmptyParts, + Qt::CaseSensitivity cs = Qt::CaseSensitive) const Q_REQUIRED_RESULT; + QStringList split(const QChar &sep, SplitBehavior behavior = KeepEmptyParts, + Qt::CaseSensitivity cs = Qt::CaseSensitive) const Q_REQUIRED_RESULT; +#ifndef QT_NO_REGEXP + QStringList split(const QRegExp &sep, SplitBehavior behavior = KeepEmptyParts) const Q_REQUIRED_RESULT; +#endif + + enum NormalizationForm { + NormalizationForm_D, + NormalizationForm_C, + NormalizationForm_KD, + NormalizationForm_KC + }; + QString normalized(NormalizationForm mode) const Q_REQUIRED_RESULT; + QString normalized(NormalizationForm mode, QChar::UnicodeVersion version) const Q_REQUIRED_RESULT; + + QString repeated(int times) const; + + const ushort *utf16() const; + + QByteArray toAscii() const Q_REQUIRED_RESULT; + QByteArray toLatin1() const Q_REQUIRED_RESULT; + QByteArray toUtf8() const Q_REQUIRED_RESULT; + QByteArray toLocal8Bit() const Q_REQUIRED_RESULT; + QVector toUcs4() const Q_REQUIRED_RESULT; + + static QString fromAscii(const char *, int size = -1); + static QString fromLatin1(const char *, int size = -1); + static QString fromUtf8(const char *, int size = -1); + static QString fromLocal8Bit(const char *, int size = -1); + static QString fromUtf16(const ushort *, int size = -1); + static QString fromUcs4(const uint *, int size = -1); + static QString fromRawData(const QChar *, int size); + + int toWCharArray(wchar_t *array) const; + static QString fromWCharArray(const wchar_t *, int size = -1); + + QString &setRawData(const QChar *unicode, int size); + QString &setUnicode(const QChar *unicode, int size); + QString &setUtf16(const ushort *utf16, int size); + + int compare(const QString &s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const; + + int compare(const QLatin1String &other, Qt::CaseSensitivity cs = Qt::CaseSensitive) const; + + static int compare(const QString &s1, const QString &s2, Qt::CaseSensitivity cs = Qt::CaseSensitive); + + static int compare(const QString& s1, const QLatin1String &s2, + Qt::CaseSensitivity cs = Qt::CaseSensitive); + static int compare(const QLatin1String& s1, const QString &s2, + Qt::CaseSensitivity cs = Qt::CaseSensitive); + + int compare(const QStringRef &s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const; + static int compare(const QString &s1, const QStringRef &s2, + Qt::CaseSensitivity = Qt::CaseSensitive); + + int localeAwareCompare(const QString& s) const; + static int localeAwareCompare(const QString& s1, const QString& s2); + + int localeAwareCompare(const QStringRef &s) const; + static int localeAwareCompare(const QString& s1, const QStringRef& s2); + + short toShort(bool *ok=Q_NULLPTR, int base=10) const; + ushort toUShort(bool *ok=Q_NULLPTR, int base=10) const; + int toInt(bool *ok=Q_NULLPTR, int base=10) const; + uint toUInt(bool *ok=Q_NULLPTR, int base=10) const; + long toLong(bool *ok=Q_NULLPTR, int base=10) const; + ulong toULong(bool *ok=Q_NULLPTR, int base=10) const; + qlonglong toLongLong(bool *ok=Q_NULLPTR, int base=10) const; + qulonglong toULongLong(bool *ok=Q_NULLPTR, int base=10) const; + float toFloat(bool *ok=Q_NULLPTR) const; + double toDouble(bool *ok=Q_NULLPTR) const; + + QString &setNum(short, int base=10); + QString &setNum(ushort, int base=10); + QString &setNum(int, int base=10); + QString &setNum(uint, int base=10); + QString &setNum(long, int base=10); + QString &setNum(ulong, int base=10); + QString &setNum(qlonglong, int base=10); + QString &setNum(qulonglong, int base=10); + QString &setNum(float, char f='g', int prec=6); + QString &setNum(double, char f='g', int prec=6); + + static QString number(int, int base=10); + static QString number(uint, int base=10); + static QString number(long, int base=10); + static QString number(ulong, int base=10); + static QString number(qlonglong, int base=10); + static QString number(qulonglong, int base=10); + static QString number(double, char f='g', int prec=6); + + bool operator==(const QString &s) const; + bool operator<(const QString &s) const; + bool operator>(const QString &s) const; + bool operator!=(const QString &s) const; + bool operator<=(const QString &s) const; + bool operator>=(const QString &s) const; + + bool operator==(const QLatin1String &s) const; + bool operator<(const QLatin1String &s) const; + bool operator>(const QLatin1String &s) const; + bool operator!=(const QLatin1String &s) const; + bool operator<=(const QLatin1String &s) const; + bool operator>=(const QLatin1String &s) const; + + // ASCII compatibility +#ifndef QT_NO_CAST_FROM_ASCII + QString(const char *ch); + QString(const QByteArray &a); + QString &operator=(const char *ch); + QString &operator=(const QByteArray &a); + QString &operator=(char c); + + // these are needed, so it compiles with STL support enabled + QString &prepend(const char *s); + QString &prepend(const QByteArray &s); + QString &append(const char *s); + QString &append(const QByteArray &s); + QString &operator+=(const char *s); + QString &operator+=(const QByteArray &s); + QString &operator+=(char c); + + bool operator==(const char *s) const; + bool operator!=(const char *s) const; + bool operator<(const char *s) const; + bool operator<=(const char *s2) const; + bool operator>(const char *s2) const; + bool operator>=(const char *s2) const; + + bool operator==(const QByteArray &s) const; + bool operator!=(const QByteArray &s) const; + bool operator<(const QByteArray &s) const; + bool operator>(const QByteArray &s) const; + bool operator<=(const QByteArray &s) const; + bool operator>=(const QByteArray &s) const; +#endif + + typedef QChar *iterator; + typedef const QChar *const_iterator; + typedef iterator Iterator; + typedef const_iterator ConstIterator; + iterator begin(); + const_iterator begin() const; + const_iterator constBegin() const; + iterator end(); + const_iterator end() const; + const_iterator constEnd() const; + + // STL compatibility + typedef const QChar & const_reference; + typedef QChar & reference; + typedef QChar value_type; + void push_back(QChar c); + void push_back(const QString &s); + void push_front(QChar c); + void push_front(const QString &s); + + static QString fromStdString(const std::string &s); + std::string toStdString() const; +#ifndef QT_NO_STL_WCHAR + static QString fromStdWString(const QStdWString &s); + QStdWString toStdWString() const; +#endif // QT_NO_STL_WCHAR + + bool isSimpleText() const; + bool isRightToLeft() const; + + QString(int size, Qt::Initialization); + + typedef Data * DataPtr; + DataPtr &data_ptr(); +}; + + +class QLatin1String +{ +public: + QLatin1String(const char *s); + QLatin1String &operator=(const QLatin1String &other); + + const char *latin1() const; + + bool operator==(const QString &s) const; + bool operator!=(const QString &s) const; + bool operator>(const QString &s) const; + bool operator<(const QString &s) const; + bool operator>=(const QString &s) const; + bool operator<=(const QString &s) const; + + // QT_ASCII_CAST_WARN + bool operator==(const char *s) const; + bool operator!=(const char *s) const; + bool operator<(const char *s) const; + bool operator>(const char *s) const; + bool operator<=(const char *s) const; + bool operator>=(const char *s) const; +}; + + +class QCharRef { + QCharRef(QString &str, int idx); +public: + + // most QChar operations repeated here + + // all this is not documented: We just say "like QChar" and let it be. + operator QChar() const; + QCharRef &operator=(const QChar &c); + + // An operator= for each QChar cast constructors +#ifndef QT_NO_CAST_FROM_ASCII + QCharRef &operator=(char c); + QCharRef &operator=(uchar c); +#endif + QCharRef &operator=(const QCharRef &c); + QCharRef &operator=(ushort rc); + QCharRef &operator=(short rc); + QCharRef &operator=(uint rc); + QCharRef &operator=(int rc); + + // each function... + bool isNull() const; + bool isPrint() const; + bool isPunct() const; + bool isSpace() const; + bool isMark() const; + bool isLetter() const; + bool isNumber() const; + bool isLetterOrNumber() const; + bool isDigit() const; + bool isLower() const; + bool isUpper() const; + bool isTitleCase() const; + + int digitValue() const; + QChar toLower() const; + QChar toUpper() const; + QChar toTitleCase () const; + + QChar::Category category() const; + QChar::Direction direction() const; + QChar::Joining joining() const; + bool hasMirrored() const; + QChar mirroredChar() const; + QString decomposition() const; + QChar::Decomposition decompositionTag() const; + uchar combiningClass() const; + + QChar::UnicodeVersion unicodeVersion() const; + + uchar cell() const; + uchar row() const; + void setCell(uchar cell); + void setRow(uchar row); + + char toAscii() const; + char toLatin1() const; + ushort unicode() const; + ushort& unicode(); +}; + +#if !defined(QT_NO_DATASTREAM) +QDataStream &operator<<(QDataStream &, const QString &); +QDataStream &operator>>(QDataStream &, QString &); +#endif + +class QStringRef { +public: + QStringRef(); + QStringRef(const QString *string, int position, int size); + QStringRef(const QString *string); + QStringRef(const QStringRef &other); + + ~QStringRef(); + const QString *string() const; + int position() const; + int size() const; + int count() const; + int length() const; + + QStringRef &operator=(const QStringRef &other); + + int indexOf(const QString &str, int from = 0, Qt::CaseSensitivity cs = Qt::CaseSensitive) const; + int indexOf(QChar ch, int from = 0, Qt::CaseSensitivity cs = Qt::CaseSensitive) const; + int indexOf(QLatin1String str, int from = 0, Qt::CaseSensitivity cs = Qt::CaseSensitive) const; + int indexOf(const QStringRef &str, int from = 0, Qt::CaseSensitivity cs = Qt::CaseSensitive) const; + int lastIndexOf(const QString &str, int from = -1, Qt::CaseSensitivity cs = Qt::CaseSensitive) const; + int lastIndexOf(QChar ch, int from = -1, Qt::CaseSensitivity cs = Qt::CaseSensitive) const; + int lastIndexOf(QLatin1String str, int from = -1, Qt::CaseSensitivity cs = Qt::CaseSensitive) const; + int lastIndexOf(const QStringRef &str, int from = -1, Qt::CaseSensitivity cs = Qt::CaseSensitive) const; + + bool contains(const QString &str, Qt::CaseSensitivity cs = Qt::CaseSensitive) const; + bool contains(QChar ch, Qt::CaseSensitivity cs = Qt::CaseSensitive) const; + bool contains(QLatin1String str, Qt::CaseSensitivity cs = Qt::CaseSensitive) const; + bool contains(const QStringRef &str, Qt::CaseSensitivity cs = Qt::CaseSensitive) const; + + int count(const QString &s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const; + int count(QChar c, Qt::CaseSensitivity cs = Qt::CaseSensitive) const; + int count(const QStringRef &s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const; + + bool startsWith(const QString &s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const; + bool startsWith(QLatin1String s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const; + bool startsWith(QChar c, Qt::CaseSensitivity cs = Qt::CaseSensitive) const; + bool startsWith(const QStringRef &c, Qt::CaseSensitivity cs = Qt::CaseSensitive) const; + + bool endsWith(const QString &s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const; + bool endsWith(QLatin1String s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const; + bool endsWith(QChar c, Qt::CaseSensitivity cs = Qt::CaseSensitive) const; + bool endsWith(const QStringRef &c, Qt::CaseSensitivity cs = Qt::CaseSensitive) const; + + QStringRef &operator=(const QString *string); + + const QChar *unicode() const; + const QChar *data() const; + const QChar *constData() const; + + QByteArray toAscii() const Q_REQUIRED_RESULT; + QByteArray toLatin1() const Q_REQUIRED_RESULT; + QByteArray toUtf8() const Q_REQUIRED_RESULT; + QByteArray toLocal8Bit() const Q_REQUIRED_RESULT; + QVector toUcs4() const Q_REQUIRED_RESULT; + + void clear(); + QString toString() const; + bool isEmpty() const; + bool isNull() const; + + QStringRef appendTo(QString *string) const; + + const QChar at(int i) const; + + int compare(const QString &s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const; + int compare(const QStringRef &s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const; + int compare(QLatin1String s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const; + static int compare(const QStringRef &s1, const QString &s2, + Qt::CaseSensitivity = Qt::CaseSensitive); + static int compare(const QStringRef &s1, const QStringRef &s2, + Qt::CaseSensitivity = Qt::CaseSensitive); + static int compare(const QStringRef &s1, QLatin1String s2, + Qt::CaseSensitivity cs = Qt::CaseSensitive); + + int localeAwareCompare(const QString &s) const; + int localeAwareCompare(const QStringRef &s) const; + static int localeAwareCompare(const QStringRef &s1, const QString &s2); + static int localeAwareCompare(const QStringRef &s1, const QStringRef &s2); +}; + +// Those are Q_CORE_EXPORT'ed not inline'ed +bool operator==(const QStringRef &s1,const QStringRef &s2); +bool operator==(const QString &s1,const QStringRef &s2); +bool operator==(const QLatin1String &s1, const QStringRef &s2); + +bool operator<(const QStringRef &s1,const QStringRef &s2); diff --git a/bindings/core/qstringlist.i b/bindings/core/qstringlist.i new file mode 100644 index 000000000..f7b6fe1bb --- /dev/null +++ b/bindings/core/qstringlist.i @@ -0,0 +1,57 @@ +%{ +#include "QtCore/qstringlist.h" +QT_USE_NAMESPACE +%} + +#define Q_NO_USING_KEYWORD + +typedef QListIterator QStringListIterator; +typedef QMutableListIterator QMutableStringListIterator; + +class QStringList : public QList +{ +public: + QStringList(); + QStringList(const QString &i); + QStringList(const QStringList &l); + QStringList(const QList &l); +#ifdef Q_COMPILER_INITIALIZER_LISTS + QStringList(std::initializer_list args); +#endif + + void sort(); + int removeDuplicates(); + + QString join(const QString &sep) const; + + QStringList filter(const QString &str, Qt::CaseSensitivity cs = Qt::CaseSensitive) const; + bool contains(const QString &str, Qt::CaseSensitivity cs = Qt::CaseSensitive) const; + + QStringList &replaceInStrings(const QString &before, const QString &after, Qt::CaseSensitivity cs = Qt::CaseSensitive); + + QStringList operator+(const QStringList &other) const; + QStringList &operator<<(const QString &str); + QStringList &operator<<(const QStringList &l); + +#ifndef QT_NO_REGEXP + QStringList filter(const QRegExp &rx) const; + QStringList &replaceInStrings(const QRegExp &rx, const QString &after); + int indexOf(const QRegExp &rx, int from = 0) const; + int lastIndexOf(const QRegExp &rx, int from = -1) const; + int indexOf(QRegExp &rx, int from = 0) const; + int lastIndexOf(QRegExp &rx, int from = -1) const; +#endif +#if !defined(Q_NO_USING_KEYWORD) + using QList::indexOf; + using QList::lastIndexOf; +#else + int indexOf(const QString &str, int from = 0) const; + int lastIndexOf(const QString &str, int from = -1) const; +#endif +}; + + +#ifndef QT_NO_DATASTREAM +QDataStream &operator>>(QDataStream &in, QStringList &list); +QDataStream &operator<<(QDataStream &out, const QStringList &list); +#endif // QT_NO_DATASTREAM diff --git a/bindings/core/qvector.i b/bindings/core/qvector.i new file mode 100644 index 000000000..89595cfd8 --- /dev/null +++ b/bindings/core/qvector.i @@ -0,0 +1,101 @@ +%{ +#include "QtCore/qvector.h" +QT_USE_NAMESPACE +%} + +template +class QVector +{ +public: + QVector(); + QVector(int size); + QVector(int size, const T &t); + QVector(const QVector &v); + ~QVector(); + QVector &operator=(const QVector &v); +#ifdef Q_COMPILER_RVALUE_REFS + QVector operator=(QVector &&other); +#endif + void swap(QVector &other); +#ifdef Q_COMPILER_INITIALIZER_LISTS + QVector(std::initializer_list args); +#endif + bool operator==(const QVector &v) const; + bool operator!=(const QVector &v) const; + + int size() const; + + bool isEmpty() const; + + void resize(int size); + + int capacity() const; + void reserve(int size); + void squeeze(); + + void detach(); + bool isDetached() const; + void setSharable(bool sharable); + bool isSharedWith(const QVector &other) const; + + T *data(); + const T *data() const; + const T *constData() const; + void clear(); + + const T &at(int i) const; + T &operator[](int i); + const T &operator[](int i) const; + void append(const T &t); + void prepend(const T &t); + void insert(int i, const T &t); + void insert(int i, int n, const T &t); + void replace(int i, const T &t); + void remove(int i); + void remove(int i, int n); + + QVector &fill(const T &t, int size = -1); + + int indexOf(const T &t, int from = 0) const; + int lastIndexOf(const T &t, int from = -1) const; + bool contains(const T &t) const; + int count(const T &t) const; + + // more Qt + int count() const; + T& first(); + const T &first() const; + T& last(); + const T &last() const; + bool startsWith(const T &t) const; + bool endsWith(const T &t) const; + QVector mid(int pos, int length = -1) const; + + T value(int i) const; + T value(int i, const T &defaultValue) const; + + // STL compatibility + void push_back(const T &t); + void push_front(const T &t); + void pop_back(); + void pop_front(); + bool empty() const; + T& front(); + const T &front() const; + T &back(); + const T &back(); + + // comfort + QVector &operator+=(const QVector &l); + QVector operator+(const QVector &l) const; + QVector &operator+=(const T &t); + QVector &operator<< (const T &t); + QVector &operator<<(const QVector &l); + + QList toList() const; + + static QVector fromList(const QList &list); + + static QVector fromStdVector(const std::vector &vector); + std::vector toStdVector() const; +}; diff --git a/src/core/tools/qstring.h b/src/core/tools/qstring.h index bf7c181ca..a15a7e883 100644 --- a/src/core/tools/qstring.h +++ b/src/core/tools/qstring.h @@ -706,7 +706,7 @@ public: inline bool isMark() const { return QChar(*this).isMark(); } inline bool isLetter() const { return QChar(*this).isLetter(); } inline bool isNumber() const { return QChar(*this).isNumber(); } - inline bool isLetterOrNumber() { return QChar(*this).isLetterOrNumber(); } + inline bool isLetterOrNumber() const { return QChar(*this).isLetterOrNumber(); } inline bool isDigit() const { return QChar(*this).isDigit(); } inline bool isLower() const { return QChar(*this).isLower(); } inline bool isUpper() const { return QChar(*this).isUpper(); } -- 2.11.0