1 /****************************************************************************
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
6 ** This file is part of the QtCore module of the Qt Toolkit.
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** GNU Lesser General Public License Usage
10 ** This file may be used under the terms of the GNU Lesser General Public
11 ** License version 2.1 as published by the Free Software Foundation and
12 ** appearing in the file LICENSE.LGPL included in the packaging of this
13 ** file. Please review the following information to ensure the GNU Lesser
14 ** General Public License version 2.1 requirements will be met:
15 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
17 ** In addition, as a special exception, Nokia gives you certain additional
18 ** rights. These rights are described in the Nokia Qt LGPL Exception
19 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
21 ** GNU General Public License Usage
22 ** Alternatively, this file may be used under the terms of the GNU General
23 ** Public License version 3.0 as published by the Free Software Foundation
24 ** and appearing in the file LICENSE.GPL included in the packaging of this
25 ** file. Please review the following information to ensure the GNU General
26 ** Public License version 3.0 requirements will be met:
27 ** http://www.gnu.org/copyleft/gpl.html.
30 ** Alternatively, this file may be used in accordance with the terms and
31 ** conditions contained in a signed written agreement between you and Nokia.
40 ****************************************************************************/
42 #include <qjsonobject.h>
43 #include <qjsonvalue.h>
44 #include <qjsonarray.h>
45 #include <qjsonvalue.h>
46 #include <qstringlist.h>
50 #include "qjsonwriter_p.h"
61 \brief The QJsonArray class encapsulates a JSON array.
63 A JSON array is a list of values. The list can be manipulated by inserting and
64 removing QJsonValue's from the array.
66 A QJsonArray can be converted to and from a QVariantList. You can query the
67 number of entries with size(), insert(), and remove() entries from it
68 and iterate over its content using the standard C++ iterator pattern.
70 QJsonArray is an implicitly shared class and shares the data with the document
71 it has been created from as long as it is not being modified.
73 You can convert the array to and from text based JSON through QJsonDocument.
77 \typedef QJsonArray::Iterator
79 Qt-style synonym for QJsonArray::iterator.
83 \typedef QJsonArray::ConstIterator
85 Qt-style synonym for QJsonArray::const_iterator.
89 \typedef QJsonArray::size_type
91 Typedef for int. Provided for STL compatibility.
95 \typedef QJsonArray::value_type
97 Typedef for QJsonValue. Provided for STL compatibility.
101 \typedef QJsonArray::difference_type
103 Typedef for int. Provided for STL compatibility.
107 \typedef QJsonArray::pointer
109 Typedef for QJsonValue *. Provided for STL compatibility.
113 \typedef QJsonArray::const_pointer
115 Typedef for const QJsonValue *. Provided for STL compatibility.
119 \typedef QJsonArray::reference
121 Typedef for QJsonValue &. Provided for STL compatibility.
125 \typedef QJsonArray::const_reference
127 Typedef for const QJsonValue &. Provided for STL compatibility.
131 Creates an empty array.
133 QJsonArray::QJsonArray()
141 QJsonArray::QJsonArray(QJsonPrivate::Data *data, QJsonPrivate::Array *array)
152 QJsonArray::~QJsonArray()
154 if (d && !d->ref.deref())
159 Creates a copy of \a other.
161 Since QJsonArray is implicitly shared, the copy is shallow
162 as long as the object doesn't get modified.
164 QJsonArray::QJsonArray(const QJsonArray &other)
173 Assigns \a other to this array.
175 QJsonArray &QJsonArray::operator =(const QJsonArray &other)
178 if (d && !d->ref.deref())
190 Converts the string list \a list to a QJsonArray.
192 The values in \a list will be converted to JSON values.
194 \sa toVariantList(), QJsonValue::fromVariant()
196 QJsonArray QJsonArray::fromStringList(const QStringList &list)
199 for (QStringList::const_iterator it = list.constBegin(); it != list.constEnd(); ++it)
200 array.append(QJsonValue(*it));
205 Converts the variant list \a list to a QJsonArray.
207 The QVariant values in \a list will be converted to JSON values.
209 \sa toVariantList(), QJsonValue::fromVariant()
211 QJsonArray QJsonArray::fromVariantList(const QVariantList &list)
214 for (QVariantList::const_iterator it = list.constBegin(); it != list.constEnd(); ++it)
215 array.append(QJsonValue::fromVariant(*it));
220 Converts this object to a QVariantList.
222 Returns the created map.
224 QVariantList QJsonArray::toVariantList() const
229 for (int i = 0; i < (int)a->length; ++i)
230 list.append(QJsonValue(d, a, a->at(i)).toVariant());
237 Returns the number of values stored in the array.
239 int QJsonArray::size() const
244 return (int)a->length;
248 \fn QJsonArray::count() const
256 Returns \c true if the object is empty. This is the same as size() == 0.
260 bool QJsonArray::isEmpty() const
269 Returns a QJsonValue representing the value for index \a i.
271 The returned QJsonValue is \c Undefined, if \a i is out of bounds.
274 QJsonValue QJsonArray::at(int i) const
276 if (!a || i < 0 || i >= (int)a->length)
277 return QJsonValue(QJsonValue::Undefined);
279 return QJsonValue(d, a, a->at(i));
283 Returns the first value stored in the array.
289 QJsonValue QJsonArray::first() const
295 Returns the last value stored in the array.
297 Same as \c{at(size() - 1)}.
301 QJsonValue QJsonArray::last() const
303 return at(a ? (a->length - 1) : 0);
307 Inserts \a value at the beginning of the array.
309 This is the same as \c{insert(0, \a value)}.
311 \sa append(), insert()
313 void QJsonArray::prepend(const QJsonValue &value)
319 Inserts \a value at the end of the array.
321 \sa prepend(), insert()
323 void QJsonArray::append(const QJsonValue &value)
325 insert(a ? (int)a->length : 0, value);
329 Removes the value at index position \a i. \a i must be a valid
330 index position in the array (i.e., \c{0 <= \a i < size()}).
332 \sa insert(), replace()
334 void QJsonArray::removeAt(int i)
336 if (!a || i < 0 || i >= (int)a->length)
340 a->removeItems(i, 1);
341 ++d->compactionCounter;
342 if (d->compactionCounter > 32u && d->compactionCounter >= unsigned(a->length) / 2u)
346 /*! \fn void QJsonArray::removeFirst()
348 Removes the first item in the array. Calling this function is
349 equivalent to calling \c{removeAt(0)}. The array must not be empty. If
350 the array can be empty, call isEmpty() before calling this
353 \sa removeAt(), removeLast()
356 /*! \fn void QJsonArray::removeLast()
358 Removes the last item in the array. Calling this function is
359 equivalent to calling \c{removeAt(size() - 1)}. The array must not be
360 empty. If the array can be empty, call isEmpty() before calling
363 \sa removeAt(), removeFirst()
367 Removes the item at index position \a i and returns it. \a i must
368 be a valid index position in the array (i.e., \c{0 <= \a i < size()}).
370 If you don't use the return value, removeAt() is more efficient.
374 QJsonValue QJsonArray::takeAt(int i)
376 if (!a || i < 0 || i >= (int)a->length)
377 return QJsonValue(QJsonValue::Undefined);
381 QJsonValue v(d, a, a->at(i));
390 Inserts \a value at index position \a i in the array. If \a i
391 is \c 0, the value is prepended to the array. If \a i is size(), the
392 value is appended to the array.
394 \sa append(), prepend(), replace(), removeAt()
396 void QJsonArray::insert(int i, const QJsonValue &value)
398 Q_ASSERT (i >= 0 && i <= (a ? (int)a->length : 0));
401 int valueSize = QJsonPrivate::Value::requiredStorage(value, &compressed);
403 detach(valueSize + sizeof(QJsonPrivate::Value));
406 a->tableOffset = sizeof(QJsonPrivate::Array);
408 int valueOffset = a->reserveSpace(valueSize, i, 1, false);
409 QJsonPrivate::Value &v = (*a)[i];
410 v.type = (value.t == QJsonValue::Undefined ? QJsonValue::Null : value.t);
411 v.latinOrIntValue = compressed;
413 v.value = QJsonPrivate::Value::valueToStore(value, valueOffset);
415 QJsonPrivate::Value::copyData(value, (char *)a + valueOffset, compressed);
419 \fn QJsonArray::iterator QJsonArray::insert(iterator before, const QJsonValue &value)
421 Inserts \a value before the position pointed to by \a before, and returns an iterator
422 pointing to the newly inserted item.
424 \sa erase(), insert()
428 \fn QJsonArray::iterator QJsonArray::erase(iterator it)
430 Removes the item pointed to by \a it, and returns an iterator pointing to the
437 Replaces the item at index position \a i with \a value. \a i must
438 be a valid index position in the array (i.e., \c{0 <= \a i < size()}).
440 \sa operator[](), removeAt()
442 void QJsonArray::replace(int i, const QJsonValue &value)
444 Q_ASSERT (a && i >= 0 && i < (int)(a->length));
447 int valueSize = QJsonPrivate::Value::requiredStorage(value, &compressed);
452 a->tableOffset = sizeof(QJsonPrivate::Array);
454 int valueOffset = a->reserveSpace(valueSize, i, 1, true);
455 QJsonPrivate::Value &v = (*a)[i];
456 v.type = (value.t == QJsonValue::Undefined ? QJsonValue::Null : value.t);
457 v.latinOrIntValue = compressed;
459 v.value = QJsonPrivate::Value::valueToStore(value, valueOffset);
461 QJsonPrivate::Value::copyData(value, (char *)a + valueOffset, compressed);
463 ++d->compactionCounter;
464 if (d->compactionCounter > 32u && d->compactionCounter >= unsigned(a->length) / 2u)
469 Returns \c true if the array contains an occurrence of \a value, otherwise \c false.
473 bool QJsonArray::contains(const QJsonValue &value) const
475 for (int i = 0; i < size(); i++) {
483 Returns the value at index position \a i as a modifiable reference.
484 \a i must be a valid index position in the array (i.e., \c{0 <= \a i <
487 The return value is of type QJsonValueRef, a helper class for QJsonArray
488 and QJsonObject. When you get an object of type QJsonValueRef, you can
489 use it as if it were a reference to a QJsonValue. If you assign to it,
490 the assignment will apply to the character in the QJsonArray of QJsonObject
491 from which you got the reference.
495 QJsonValueRef QJsonArray::operator [](int i)
497 Q_ASSERT(a && i >= 0 && i < (int)a->length);
498 return QJsonValueRef(this, i);
506 QJsonValue QJsonArray::operator[](int i) const
512 Returns \c true if this array is equal to \a other.
514 bool QJsonArray::operator==(const QJsonArray &other) const
520 return !other.a->length;
523 if (a->length != other.a->length)
526 for (int i = 0; i < (int)a->length; ++i) {
527 if (QJsonValue(d, a, a->at(i)) != QJsonValue(other.d, other.a, other.a->at(i)))
534 Returns \c true if this array is not equal to \a other.
536 bool QJsonArray::operator!=(const QJsonArray &other) const
538 return !(*this == other);
541 /*! \fn QJsonArray::iterator QJsonArray::begin()
543 Returns an \l{STL-style iterator} pointing to the first item in
546 \sa constBegin(), end()
549 /*! \fn QJsonArray::const_iterator QJsonArray::begin() const
554 /*! \fn QJsonArray::const_iterator QJsonArray::constBegin() const
556 Returns a const \l{STL-style iterator} pointing to the first item
559 \sa begin(), constEnd()
562 /*! \fn QJsonArray::iterator QJsonArray::end()
564 Returns an \l{STL-style iterator} pointing to the imaginary item
565 after the last item in the array.
567 \sa begin(), constEnd()
570 /*! \fn const_iterator QJsonArray::end() const
575 /*! \fn QJsonArray::const_iterator QJsonArray::constEnd() const
577 Returns a const \l{STL-style iterator} pointing to the imaginary
578 item after the last item in the array.
580 \sa constBegin(), end()
583 /*! \fn void QJsonArray::push_back(const QJsonValue &value)
585 This function is provided for STL compatibility. It is equivalent
586 to \l{QJsonArray::append()}{append(\a value)}.
589 /*! \fn void QJsonArray::push_front(const QJsonValue &value)
591 This function is provided for STL compatibility. It is equivalent
592 to \l{QJsonArray::prepend()}{prepend(\a value)}.
595 /*! \fn void QJsonArray::pop_front()
597 This function is provided for STL compatibility. It is equivalent
598 to removeFirst(). The array must not be empty. If the array can be
599 empty, call isEmpty() before calling this function.
602 /*! \fn void QJsonArray::pop_back()
604 This function is provided for STL compatibility. It is equivalent
605 to removeLast(). The array must not be empty. If the array can be
606 empty, call isEmpty() before calling this function.
609 /*! \fn bool QJsonArray::empty() const
611 This function is provided for STL compatibility. It is equivalent
612 to isEmpty() and returns \c true if the array is empty.
615 /*! \class QJsonArray::iterator
616 \brief The QJsonArray::iterator class provides an STL-style non-const iterator for QJsonArray.
618 QJsonArray::iterator allows you to iterate over a QJsonArray
619 and to modify the array item associated with the
620 iterator. If you want to iterate over a const QJsonArray, use
621 QJsonArray::const_iterator instead. It is generally a good practice to
622 use QJsonArray::const_iterator on a non-const QJsonArray as well, unless
623 you need to change the QJsonArray through the iterator. Const
624 iterators are slightly faster and improves code readability.
626 The default QJsonArray::iterator constructor creates an uninitialized
627 iterator. You must initialize it using a QJsonArray function like
628 QJsonArray::begin(), QJsonArray::end(), or QJsonArray::insert() before you can
631 Most QJsonArray functions accept an integer index rather than an
632 iterator. For that reason, iterators are rarely useful in
633 connection with QJsonArray. One place where STL-style iterators do
634 make sense is as arguments to \l{generic algorithms}.
636 Multiple iterators can be used on the same array. However, be
637 aware that any non-const function call performed on the QJsonArray
638 will render all existing iterators undefined.
640 \sa QJsonArray::const_iterator
643 /*! \typedef QJsonArray::iterator::iterator_category
645 A synonym for \e {std::random_access_iterator_tag} indicating
646 this iterator is a random access iterator.
649 /*! \typedef QJsonArray::iterator::difference_type
654 /*! \typedef QJsonArray::iterator::value_type
659 /*! \typedef QJsonArray::iterator::reference
664 /*! \fn QJsonArray::iterator::iterator()
666 Constructs an uninitialized iterator.
668 Functions like operator*() and operator++() should not be called
669 on an uninitialized iterator. Use operator=() to assign a value
670 to it before using it.
672 \sa QJsonArray::begin(), QJsonArray::end()
675 /*! \fn QJsonValueRef QJsonArray::iterator::operator*() const
677 Returns a modifiable reference to the current item.
679 You can change the value of an item by using operator*() on the
680 left side of an assignment.
682 The return value is of type QJsonValueRef, a helper class for QJsonArray
683 and QJsonObject. When you get an object of type QJsonValueRef, you can
684 use it as if it were a reference to a QJsonValue. If you assign to it,
685 the assignment will apply to the character in the QJsonArray of QJsonObject
686 from which you got the reference.
689 /*! \fn QJsonValueRef QJsonArray::iterator::operator[](int j) const
691 Returns a modifiable reference to the item at position \c{*this + j}.
693 This function is provided to make QJsonArray iterators behave like C++
696 The return value is of type QJsonValueRef, a helper class for QJsonArray
697 and QJsonObject. When you get an object of type QJsonValueRef, you can
698 use it as if it were a reference to a QJsonValue. If you assign to it,
699 the assignment will apply to the character in the QJsonArray of QJsonObject
700 from which you got the reference.
706 \fn bool QJsonArray::iterator::operator==(const iterator &other) const
707 \fn bool QJsonArray::iterator::operator==(const const_iterator &other) const
709 Returns \c true if \a other points to the same item as this
710 iterator; otherwise returns \c false.
716 \fn bool QJsonArray::iterator::operator!=(const iterator &other) const
717 \fn bool QJsonArray::iterator::operator!=(const const_iterator &other) const
719 Returns \c true if \a other points to a different item than this
720 iterator; otherwise returns \c false.
726 \fn bool QJsonArray::iterator::operator<(const iterator& other) const
727 \fn bool QJsonArray::iterator::operator<(const const_iterator& other) const
729 Returns \c true if the item pointed to by this iterator is less than
730 the item pointed to by the \a other iterator.
734 \fn bool QJsonArray::iterator::operator<=(const iterator& other) const
735 \fn bool QJsonArray::iterator::operator<=(const const_iterator& other) const
737 Returns \c true if the item pointed to by this iterator is less than
738 or equal to the item pointed to by the \a other iterator.
742 \fn bool QJsonArray::iterator::operator>(const iterator& other) const
743 \fn bool QJsonArray::iterator::operator>(const const_iterator& other) const
745 Returns \c true if the item pointed to by this iterator is greater
746 than the item pointed to by the \a other iterator.
750 \fn bool QJsonArray::iterator::operator>=(const iterator& other) const
751 \fn bool QJsonArray::iterator::operator>=(const const_iterator& other) const
753 Returns \c true if the item pointed to by this iterator is greater
754 than or equal to the item pointed to by the \a other iterator.
757 /*! \fn QJsonArray::iterator &QJsonArray::iterator::operator++()
759 The prefix ++ operator, \c{++it}, advances the iterator to the
760 next item in the array and returns an iterator to the new current
763 Calling this function on QJsonArray::end() leads to undefined results.
768 /*! \fn QJsonArray::iterator QJsonArray::iterator::operator++(int)
772 The postfix ++ operator, \c{it++}, advances the iterator to the
773 next item in the array and returns an iterator to the previously
777 /*! \fn QJsonArray::iterator &QJsonArray::iterator::operator--()
779 The prefix -- operator, \c{--it}, makes the preceding item
780 current and returns an iterator to the new current item.
782 Calling this function on QJsonArray::begin() leads to undefined results.
787 /*! \fn QJsonArray::iterator QJsonArray::iterator::operator--(int)
791 The postfix -- operator, \c{it--}, makes the preceding item
792 current and returns an iterator to the previously current item.
795 /*! \fn QJsonArray::iterator &QJsonArray::iterator::operator+=(int j)
797 Advances the iterator by \a j items. If \a j is negative, the
798 iterator goes backward.
800 \sa operator-=(), operator+()
803 /*! \fn QJsonArray::iterator &QJsonArray::iterator::operator-=(int j)
805 Makes the iterator go back by \a j items. If \a j is negative,
806 the iterator goes forward.
808 \sa operator+=(), operator-()
811 /*! \fn QJsonArray::iterator QJsonArray::iterator::operator+(int j) const
813 Returns an iterator to the item at \a j positions forward from
814 this iterator. If \a j is negative, the iterator goes backward.
816 \sa operator-(), operator+=()
819 /*! \fn QJsonArray::iterator QJsonArray::iterator::operator-(int j) const
821 Returns an iterator to the item at \a j positions backward from
822 this iterator. If \a j is negative, the iterator goes forward.
824 \sa operator+(), operator-=()
827 /*! \fn int QJsonArray::iterator::operator-(iterator other) const
829 Returns the number of items between the item pointed to by \a
830 other and the item pointed to by this iterator.
833 /*! \class QJsonArray::const_iterator
834 \brief The QJsonArray::const_iterator class provides an STL-style const iterator for QJsonArray.
836 QJsonArray::const_iterator allows you to iterate over a
837 QJsonArray. If you want to modify the QJsonArray as
838 you iterate over it, use QJsonArray::iterator instead. It is generally a
839 good practice to use QJsonArray::const_iterator on a non-const QJsonArray
840 as well, unless you need to change the QJsonArray through the
841 iterator. Const iterators are slightly faster and improves
844 The default QJsonArray::const_iterator constructor creates an
845 uninitialized iterator. You must initialize it using a QJsonArray
846 function like QJsonArray::constBegin(), QJsonArray::constEnd(), or
847 QJsonArray::insert() before you can start iterating.
849 Most QJsonArray functions accept an integer index rather than an
850 iterator. For that reason, iterators are rarely useful in
851 connection with QJsonArray. One place where STL-style iterators do
852 make sense is as arguments to \l{generic algorithms}.
854 Multiple iterators can be used on the same array. However, be
855 aware that any non-const function call performed on the QJsonArray
856 will render all existing iterators undefined.
858 \sa QJsonArray::iterator
861 /*! \fn QJsonArray::const_iterator::const_iterator()
863 Constructs an uninitialized iterator.
865 Functions like operator*() and operator++() should not be called
866 on an uninitialized iterator. Use operator=() to assign a value
867 to it before using it.
869 \sa QJsonArray::constBegin(), QJsonArray::constEnd()
872 /*! \typedef QJsonArray::const_iterator::iterator_category
874 A synonym for \e {std::random_access_iterator_tag} indicating
875 this iterator is a random access iterator.
878 /*! \typedef QJsonArray::const_iterator::difference_type
883 /*! \typedef QJsonArray::const_iterator::value_type
888 /*! \typedef QJsonArray::const_iterator::reference
893 /*! \fn QJsonArray::const_iterator::const_iterator(const const_iterator &other)
895 Constructs a copy of \a other.
898 /*! \fn QJsonArray::const_iterator::const_iterator(const iterator &other)
900 Constructs a copy of \a other.
903 /*! \fn QJsonValue QJsonArray::const_iterator::operator*() const
905 Returns the current item.
908 /*! \fn QJsonValue QJsonArray::const_iterator::operator[](int j) const
910 Returns the item at position \c{*this + j}.
912 This function is provided to make QJsonArray iterators behave like C++
918 /*! \fn bool QJsonArray::const_iterator::operator==(const const_iterator &other) const
920 Returns \c true if \a other points to the same item as this
921 iterator; otherwise returns \c false.
926 /*! \fn bool QJsonArray::const_iterator::operator!=(const const_iterator &other) const
928 Returns \c true if \a other points to a different item than this
929 iterator; otherwise returns \c false.
935 \fn bool QJsonArray::const_iterator::operator<(const const_iterator& other) const
937 Returns \c true if the item pointed to by this iterator is less than
938 the item pointed to by the \a other iterator.
942 \fn bool QJsonArray::const_iterator::operator<=(const const_iterator& other) const
944 Returns \c true if the item pointed to by this iterator is less than
945 or equal to the item pointed to by the \a other iterator.
949 \fn bool QJsonArray::const_iterator::operator>(const const_iterator& other) const
951 Returns \c true if the item pointed to by this iterator is greater
952 than the item pointed to by the \a other iterator.
956 \fn bool QJsonArray::const_iterator::operator>=(const const_iterator& other) const
958 Returns \c true if the item pointed to by this iterator is greater
959 than or equal to the item pointed to by the \a other iterator.
962 /*! \fn QJsonArray::const_iterator &QJsonArray::const_iterator::operator++()
964 The prefix ++ operator, \c{++it}, advances the iterator to the
965 next item in the array and returns an iterator to the new current
968 Calling this function on QJsonArray::end() leads to undefined results.
973 /*! \fn QJsonArray::const_iterator QJsonArray::const_iterator::operator++(int)
977 The postfix ++ operator, \c{it++}, advances the iterator to the
978 next item in the array and returns an iterator to the previously
982 /*! \fn QJsonArray::const_iterator &QJsonArray::const_iterator::operator--()
984 The prefix -- operator, \c{--it}, makes the preceding item
985 current and returns an iterator to the new current item.
987 Calling this function on QJsonArray::begin() leads to undefined results.
992 /*! \fn QJsonArray::const_iterator QJsonArray::const_iterator::operator--(int)
996 The postfix -- operator, \c{it--}, makes the preceding item
997 current and returns an iterator to the previously current item.
1000 /*! \fn QJsonArray::const_iterator &QJsonArray::const_iterator::operator+=(int j)
1002 Advances the iterator by \a j items. If \a j is negative, the
1003 iterator goes backward.
1005 \sa operator-=(), operator+()
1008 /*! \fn QJsonArray::const_iterator &QJsonArray::const_iterator::operator-=(int j)
1010 Makes the iterator go back by \a j items. If \a j is negative,
1011 the iterator goes forward.
1013 \sa operator+=(), operator-()
1016 /*! \fn QJsonArray::const_iterator QJsonArray::const_iterator::operator+(int j) const
1018 Returns an iterator to the item at \a j positions forward from
1019 this iterator. If \a j is negative, the iterator goes backward.
1021 \sa operator-(), operator+=()
1024 /*! \fn QJsonArray::const_iterator QJsonArray::const_iterator::operator-(int j) const
1026 Returns an iterator to the item at \a j positions backward from
1027 this iterator. If \a j is negative, the iterator goes forward.
1029 \sa operator+(), operator-=()
1032 /*! \fn int QJsonArray::const_iterator::operator-(const_iterator other) const
1034 Returns the number of items between the item pointed to by \a
1035 other and the item pointed to by this iterator.
1042 void QJsonArray::detach(uint reserve)
1045 d = new QJsonPrivate::Data(reserve, QJsonValue::Array);
1046 a = static_cast<QJsonPrivate::Array *>(d->header->root());
1050 if (reserve == 0 && d->ref.load() == 1)
1053 QJsonPrivate::Data *x = d->clone(a, reserve);
1055 if (!d->ref.deref())
1058 a = static_cast<QJsonPrivate::Array *>(d->header->root());
1064 void QJsonArray::compact()
1066 if (!d || !d->compactionCounter)
1071 a = static_cast<QJsonPrivate::Array *>(d->header->root());
1075 #ifndef QT_NO_DEBUG_STREAM
1076 QDebug operator<<(QDebug dbg, const QJsonArray &a)
1079 dbg << "QJsonArray()";
1083 QJsonPrivate::Writer::arrayToJson(a.a, json, 0, true);
1084 dbg.nospace() << "QJsonArray("
1085 << json.constData() // print as utf-8 string without extra quotation marks