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 ****************************************************************************/
45 #include <QtCore/qrefcount.h>
46 #include <QtCore/qnamespace.h>
52 #error qbytearray.h must be included before any header file that defines truncate
55 #if defined(Q_CC_GNU) && (__GNUC__ == 4 && __GNUC_MINOR__ == 0)
56 //There is a bug in GCC 4.0 that tries to instantiate template of annonymous enum
57 # ifdef QT_USE_FAST_OPERATOR_PLUS
58 # undef QT_USE_FAST_OPERATOR_PLUS
60 # ifdef QT_USE_QSTRINGBUILDER
61 # undef QT_USE_QSTRINGBUILDER
72 /*****************************************************************************
73 Safe and portable C string functions; extensions to standard string.h
74 *****************************************************************************/
76 Q_CORE_EXPORT char *qstrdup(const char *);
78 inline uint qstrlen(const char *str)
79 { return str ? uint(strlen(str)) : 0; }
81 inline uint qstrnlen(const char *str, uint maxlen)
85 while (length < maxlen && *str++)
91 Q_CORE_EXPORT char *qstrcpy(char *dst, const char *src);
92 Q_CORE_EXPORT char *qstrncpy(char *dst, const char *src, uint len);
94 Q_CORE_EXPORT int qstrcmp(const char *str1, const char *str2);
95 Q_CORE_EXPORT int qstrcmp(const QByteArray &str1, const QByteArray &str2);
96 Q_CORE_EXPORT int qstrcmp(const QByteArray &str1, const char *str2);
97 static inline int qstrcmp(const char *str1, const QByteArray &str2)
98 { return -qstrcmp(str2, str1); }
100 inline int qstrncmp(const char *str1, const char *str2, uint len)
102 return (str1 && str2) ? strncmp(str1, str2, len)
103 : (str1 ? 1 : (str2 ? -1 : 0));
105 Q_CORE_EXPORT int qstricmp(const char *, const char *);
106 Q_CORE_EXPORT int qstrnicmp(const char *, const char *, uint len);
108 // implemented in qvsnprintf.cpp
109 Q_CORE_EXPORT int qvsnprintf(char *str, size_t n, const char *fmt, va_list ap);
110 Q_CORE_EXPORT int qsnprintf(char *str, size_t n, const char *fmt, ...);
112 // qChecksum: Internet checksum
114 Q_CORE_EXPORT quint16 qChecksum(const char *s, uint len);
119 template <typename T> class QList;
121 struct QByteArrayData
123 QtPrivate::RefCount ref;
126 uint capacityReserved : 1;
128 qptrdiff offset; // will always work as we add/subtract from a ushort ptr
129 char d[sizeof(qptrdiff)];
131 inline char *data() { return d + sizeof(qptrdiff) + offset; }
132 inline const char *data() const { return d + sizeof(qptrdiff) + offset; }
135 template<int N> struct QStaticByteArrayData
141 template<int N> struct QStaticByteArrayDataPtr
143 const QStaticByteArrayData<N> *ptr;
147 #if defined(Q_COMPILER_LAMBDA)
148 # define QByteArrayLiteral(str) ([]() -> QStaticByteArrayDataPtr<sizeof(str) - 1> { \
149 enum { Size = sizeof(str) - 1 }; \
150 static const QStaticByteArrayData<Size> qbytearray_literal = \
151 { { Q_REFCOUNT_INITIALIZE_STATIC, Size, 0, 0, { 0 } }, str }; \
152 QStaticByteArrayDataPtr<Size> holder = { &qbytearray_literal }; \
155 #elif defined(Q_CC_GNU)
156 // We need to create a QByteArrayData in the .rodata section of memory
157 // and the only way to do that is to create a "static const" variable.
158 // To do that, we need the __extension__ {( )} trick which only GCC supports
160 # define QByteArrayLiteral(str) \
162 enum { Size = sizeof(str) - 1 }; \
163 static const QStaticByteArrayData<Size> qbytearray_literal = \
164 { { Q_REFCOUNT_INITIALIZE_STATIC, Size, 0, 0, { 0 } }, str }; \
165 QStaticByteArrayDataPtr<Size> holder = { &qbytearray_literal }; \
169 #ifndef QByteArrayLiteral
170 // no lambdas, not GCC, use const char * instead
172 # define QByteArrayLiteral(str) (str)
176 class Q_CORE_EXPORT QByteArray
179 typedef QByteArrayData Data;
183 QByteArray(const char *, int size = -1);
184 QByteArray(int size, char c);
185 QByteArray(int size, Qt::Initialization);
186 inline QByteArray(const QByteArray &);
187 inline ~QByteArray();
189 QByteArray &operator=(const QByteArray &);
190 QByteArray &operator=(const char *str);
191 #ifdef Q_COMPILER_RVALUE_REFS
192 inline QByteArray &operator=(QByteArray &&other)
193 { qSwap(d, other.d); return *this; }
196 inline void swap(QByteArray &other) { qSwap(d, other.d); }
198 inline int size() const;
199 bool isEmpty() const;
200 void resize(int size);
202 QByteArray &fill(char c, int size = -1);
204 int capacity() const;
205 void reserve(int size);
208 #ifndef QT_NO_CAST_FROM_BYTEARRAY
209 operator const char *() const;
210 operator const void *() const;
213 const char *data() const;
214 inline const char *constData() const;
215 inline void detach();
216 bool isDetached() const;
217 inline bool isSharedWith(const QByteArray &other) const { return d == other.d; }
220 char at(int i) const;
221 char operator[](int i) const;
222 char operator[](uint i) const;
223 QByteRef operator[](int i);
224 QByteRef operator[](uint i);
226 int indexOf(char c, int from = 0) const;
227 int indexOf(const char *c, int from = 0) const;
228 int indexOf(const QByteArray &a, int from = 0) const;
229 int lastIndexOf(char c, int from = -1) const;
230 int lastIndexOf(const char *c, int from = -1) const;
231 int lastIndexOf(const QByteArray &a, int from = -1) const;
233 bool contains(char c) const;
234 bool contains(const char *a) const;
235 bool contains(const QByteArray &a) const;
236 int count(char c) const;
237 int count(const char *a) const;
238 int count(const QByteArray &a) const;
240 QByteArray left(int len) const;
241 QByteArray right(int len) const;
242 QByteArray mid(int index, int len = -1) const;
244 bool startsWith(const QByteArray &a) const;
245 bool startsWith(char c) const;
246 bool startsWith(const char *c) const;
248 bool endsWith(const QByteArray &a) const;
249 bool endsWith(char c) const;
250 bool endsWith(const char *c) const;
252 void truncate(int pos);
255 QByteArray toLower() const;
256 QByteArray toUpper() const;
258 QByteArray trimmed() const;
259 QByteArray simplified() const;
260 QByteArray leftJustified(int width, char fill = ' ', bool truncate = false) const;
261 QByteArray rightJustified(int width, char fill = ' ', bool truncate = false) const;
263 QByteArray &prepend(char c);
264 QByteArray &prepend(const char *s);
265 QByteArray &prepend(const char *s, int len);
266 QByteArray &prepend(const QByteArray &a);
267 QByteArray &append(char c);
268 QByteArray &append(const char *s);
269 QByteArray &append(const char *s, int len);
270 QByteArray &append(const QByteArray &a);
271 QByteArray &insert(int i, char c);
272 QByteArray &insert(int i, const char *s);
273 QByteArray &insert(int i, const char *s, int len);
274 QByteArray &insert(int i, const QByteArray &a);
275 QByteArray &remove(int index, int len);
276 QByteArray &replace(int index, int len, const char *s);
277 QByteArray &replace(int index, int len, const char *s, int alen);
278 QByteArray &replace(int index, int len, const QByteArray &s);
279 QByteArray &replace(char before, const char *after);
280 QByteArray &replace(char before, const QByteArray &after);
281 QByteArray &replace(const char *before, const char *after);
282 QByteArray &replace(const char *before, int bsize, const char *after, int asize);
283 QByteArray &replace(const QByteArray &before, const QByteArray &after);
284 QByteArray &replace(const QByteArray &before, const char *after);
285 QByteArray &replace(const char *before, const QByteArray &after);
286 QByteArray &replace(char before, char after);
287 QByteArray &operator+=(char c);
288 QByteArray &operator+=(const char *s);
289 QByteArray &operator+=(const QByteArray &a);
291 QList<QByteArray> split(char sep) const;
293 QByteArray repeated(int times) const;
295 #ifndef QT_NO_CAST_TO_ASCII
296 QT_ASCII_CAST_WARN QByteArray &append(const QString &s);
297 QT_ASCII_CAST_WARN QByteArray &insert(int i, const QString &s);
298 QT_ASCII_CAST_WARN QByteArray &replace(const QString &before, const char *after);
299 QT_ASCII_CAST_WARN QByteArray &replace(char c, const QString &after);
300 QT_ASCII_CAST_WARN QByteArray &replace(const QString &before, const QByteArray &after);
302 QT_ASCII_CAST_WARN QByteArray &operator+=(const QString &s);
303 QT_ASCII_CAST_WARN int indexOf(const QString &s, int from = 0) const;
304 QT_ASCII_CAST_WARN int lastIndexOf(const QString &s, int from = -1) const;
306 #ifndef QT_NO_CAST_FROM_ASCII
307 inline QT_ASCII_CAST_WARN bool operator==(const QString &s2) const;
308 inline QT_ASCII_CAST_WARN bool operator!=(const QString &s2) const;
309 inline QT_ASCII_CAST_WARN bool operator<(const QString &s2) const;
310 inline QT_ASCII_CAST_WARN bool operator>(const QString &s2) const;
311 inline QT_ASCII_CAST_WARN bool operator<=(const QString &s2) const;
312 inline QT_ASCII_CAST_WARN bool operator>=(const QString &s2) const;
315 short toShort(bool *ok = 0, int base = 10) const;
316 ushort toUShort(bool *ok = 0, int base = 10) const;
317 int toInt(bool *ok = 0, int base = 10) const;
318 uint toUInt(bool *ok = 0, int base = 10) const;
319 long toLong(bool *ok = 0, int base = 10) const;
320 ulong toULong(bool *ok = 0, int base = 10) const;
321 qlonglong toLongLong(bool *ok = 0, int base = 10) const;
322 qulonglong toULongLong(bool *ok = 0, int base = 10) const;
323 float toFloat(bool *ok = 0) const;
324 double toDouble(bool *ok = 0) const;
325 QByteArray toBase64() const;
326 QByteArray toHex() const;
327 QByteArray toPercentEncoding(const QByteArray &exclude = QByteArray(),
328 const QByteArray &include = QByteArray(),
329 char percent = '%') const;
331 QByteArray &setNum(short, int base = 10);
332 QByteArray &setNum(ushort, int base = 10);
333 QByteArray &setNum(int, int base = 10);
334 QByteArray &setNum(uint, int base = 10);
335 QByteArray &setNum(qlonglong, int base = 10);
336 QByteArray &setNum(qulonglong, int base = 10);
337 QByteArray &setNum(float, char f = 'g', int prec = 6);
338 QByteArray &setNum(double, char f = 'g', int prec = 6);
339 QByteArray &setRawData(const char *a, uint n); // ### Qt 5: use an int
341 static QByteArray number(int, int base = 10);
342 static QByteArray number(uint, int base = 10);
343 static QByteArray number(qlonglong, int base = 10);
344 static QByteArray number(qulonglong, int base = 10);
345 static QByteArray number(double, char f = 'g', int prec = 6);
346 static QByteArray fromRawData(const char *, int size);
347 static QByteArray fromBase64(const QByteArray &base64);
348 static QByteArray fromHex(const QByteArray &hexEncoded);
349 static QByteArray fromPercentEncoding(const QByteArray &pctEncoded, char percent = '%');
352 typedef char *iterator;
353 typedef const char *const_iterator;
354 typedef iterator Iterator;
355 typedef const_iterator ConstIterator;
357 const_iterator begin() const;
358 const_iterator constBegin() const;
360 const_iterator end() const;
361 const_iterator constEnd() const;
364 typedef const char & const_reference;
365 typedef char & reference;
366 typedef char value_type;
367 void push_back(char c);
368 void push_back(const char *c);
369 void push_back(const QByteArray &a);
370 void push_front(char c);
371 void push_front(const char *c);
372 void push_front(const QByteArray &a);
374 inline int count() const { return d->size; }
375 int length() const { return d->size; }
379 inline QByteArray(const QStaticByteArrayData<n> &dd)
380 : d(const_cast<QByteArrayData *>(&dd.str)) {}
382 Q_DECL_CONSTEXPR inline QByteArray(QStaticByteArrayDataPtr<N> dd)
383 : d(const_cast<QByteArrayData *>(&dd.ptr->ba)) {}
386 operator QNoImplicitBoolCast() const;
387 static const QStaticByteArrayData<1> shared_null;
388 static const QStaticByteArrayData<1> shared_empty;
390 QByteArray(Data *dd, int /*dummy*/, int /*dummy*/) : d(dd) {}
391 void realloc(int alloc);
393 QByteArray nulTerminated() const;
395 friend class QByteRef;
396 friend class QString;
397 friend Q_CORE_EXPORT QByteArray qUncompress(const uchar *data, int nbytes);
399 typedef Data * DataPtr;
400 inline DataPtr &data_ptr() { return d; }
403 inline QByteArray::QByteArray(): d(const_cast<Data *>(&shared_null.ba)) { }
404 inline QByteArray::~QByteArray() { if (!d->ref.deref()) qFree(d); }
405 inline int QByteArray::size() const
408 inline char QByteArray::at(int i) const
409 { Q_ASSERT(i >= 0 && i < size()); return d->data()[i]; }
410 inline char QByteArray::operator[](int i) const
411 { Q_ASSERT(i >= 0 && i < size()); return d->data()[i]; }
412 inline char QByteArray::operator[](uint i) const
413 { Q_ASSERT(i < uint(size())); return d->data()[i]; }
415 inline bool QByteArray::isEmpty() const
416 { return d->size == 0; }
417 #ifndef QT_NO_CAST_FROM_BYTEARRAY
418 inline QByteArray::operator const char *() const
419 { return d->data(); }
420 inline QByteArray::operator const void *() const
421 { return d->data(); }
423 inline char *QByteArray::data()
424 { detach(); return d->data(); }
425 inline const char *QByteArray::data() const
426 { return d->data(); }
427 inline const char *QByteArray::constData() const
428 { return d->data(); }
429 inline void QByteArray::detach()
430 { if (d->ref.isShared() || d->offset) realloc(d->size); }
431 inline bool QByteArray::isDetached() const
432 { return !d->ref.isShared(); }
433 inline QByteArray::QByteArray(const QByteArray &a) : d(a.d)
436 inline int QByteArray::capacity() const
439 inline void QByteArray::reserve(int asize)
441 if (d->ref.isShared() || asize > int(d->alloc))
444 if (!d->capacityReserved) {
445 // cannot set unconditionally, since d could be the shared_null/shared_empty (which is const)
446 d->capacityReserved = true;
450 inline void QByteArray::squeeze()
452 if (d->ref.isShared() || d->size < int(d->alloc))
455 if (d->capacityReserved) {
456 // cannot set unconditionally, since d could be shared_null or
458 d->capacityReserved = false;
462 class Q_CORE_EXPORT QByteRef {
465 inline QByteRef(QByteArray &array, int idx)
467 friend class QByteArray;
469 inline operator char() const
470 { return i < a.d->size ? a.d->data()[i] : char(0); }
471 inline QByteRef &operator=(char c)
472 { if (i >= a.d->size) a.expand(i); else a.detach();
473 a.d->data()[i] = c; return *this; }
474 inline QByteRef &operator=(const QByteRef &c)
475 { if (i >= a.d->size) a.expand(i); else a.detach();
476 a.d->data()[i] = c.a.d->data()[c.i]; return *this; }
477 inline bool operator==(char c) const
478 { return a.d->data()[i] == c; }
479 inline bool operator!=(char c) const
480 { return a.d->data()[i] != c; }
481 inline bool operator>(char c) const
482 { return a.d->data()[i] > c; }
483 inline bool operator>=(char c) const
484 { return a.d->data()[i] >= c; }
485 inline bool operator<(char c) const
486 { return a.d->data()[i] < c; }
487 inline bool operator<=(char c) const
488 { return a.d->data()[i] <= c; }
491 inline QByteRef QByteArray::operator[](int i)
492 { Q_ASSERT(i >= 0); return QByteRef(*this, i); }
493 inline QByteRef QByteArray::operator[](uint i)
494 { return QByteRef(*this, i); }
495 inline QByteArray::iterator QByteArray::begin()
496 { detach(); return d->data(); }
497 inline QByteArray::const_iterator QByteArray::begin() const
498 { return d->data(); }
499 inline QByteArray::const_iterator QByteArray::constBegin() const
500 { return d->data(); }
501 inline QByteArray::iterator QByteArray::end()
502 { detach(); return d->data() + d->size; }
503 inline QByteArray::const_iterator QByteArray::end() const
504 { return d->data() + d->size; }
505 inline QByteArray::const_iterator QByteArray::constEnd() const
506 { return d->data() + d->size; }
507 inline QByteArray &QByteArray::operator+=(char c)
508 { return append(c); }
509 inline QByteArray &QByteArray::operator+=(const char *s)
510 { return append(s); }
511 inline QByteArray &QByteArray::operator+=(const QByteArray &a)
512 { return append(a); }
513 inline void QByteArray::push_back(char c)
515 inline void QByteArray::push_back(const char *c)
517 inline void QByteArray::push_back(const QByteArray &a)
519 inline void QByteArray::push_front(char c)
521 inline void QByteArray::push_front(const char *c)
523 inline void QByteArray::push_front(const QByteArray &a)
525 inline bool QByteArray::contains(const QByteArray &a) const
526 { return indexOf(a) != -1; }
527 inline bool QByteArray::contains(char c) const
528 { return indexOf(c) != -1; }
529 inline bool operator==(const QByteArray &a1, const QByteArray &a2)
530 { return (a1.size() == a2.size()) && (memcmp(a1.constData(), a2.constData(), a1.size())==0); }
531 inline bool operator==(const QByteArray &a1, const char *a2)
532 { return a2 ? qstrcmp(a1,a2) == 0 : a1.isEmpty(); }
533 inline bool operator==(const char *a1, const QByteArray &a2)
534 { return a1 ? qstrcmp(a1,a2) == 0 : a2.isEmpty(); }
535 inline bool operator!=(const QByteArray &a1, const QByteArray &a2)
536 { return !(a1==a2); }
537 inline bool operator!=(const QByteArray &a1, const char *a2)
538 { return a2 ? qstrcmp(a1,a2) != 0 : !a1.isEmpty(); }
539 inline bool operator!=(const char *a1, const QByteArray &a2)
540 { return a1 ? qstrcmp(a1,a2) != 0 : !a2.isEmpty(); }
541 inline bool operator<(const QByteArray &a1, const QByteArray &a2)
542 { return qstrcmp(a1, a2) < 0; }
543 inline bool operator<(const QByteArray &a1, const char *a2)
544 { return qstrcmp(a1, a2) < 0; }
545 inline bool operator<(const char *a1, const QByteArray &a2)
546 { return qstrcmp(a1, a2) < 0; }
547 inline bool operator<=(const QByteArray &a1, const QByteArray &a2)
548 { return qstrcmp(a1, a2) <= 0; }
549 inline bool operator<=(const QByteArray &a1, const char *a2)
550 { return qstrcmp(a1, a2) <= 0; }
551 inline bool operator<=(const char *a1, const QByteArray &a2)
552 { return qstrcmp(a1, a2) <= 0; }
553 inline bool operator>(const QByteArray &a1, const QByteArray &a2)
554 { return qstrcmp(a1, a2) > 0; }
555 inline bool operator>(const QByteArray &a1, const char *a2)
556 { return qstrcmp(a1, a2) > 0; }
557 inline bool operator>(const char *a1, const QByteArray &a2)
558 { return qstrcmp(a1, a2) > 0; }
559 inline bool operator>=(const QByteArray &a1, const QByteArray &a2)
560 { return qstrcmp(a1, a2) >= 0; }
561 inline bool operator>=(const QByteArray &a1, const char *a2)
562 { return qstrcmp(a1, a2) >= 0; }
563 inline bool operator>=(const char *a1, const QByteArray &a2)
564 { return qstrcmp(a1, a2) >= 0; }
565 #if !defined(QT_USE_QSTRINGBUILDER)
566 inline const QByteArray operator+(const QByteArray &a1, const QByteArray &a2)
567 { return QByteArray(a1) += a2; }
568 inline const QByteArray operator+(const QByteArray &a1, const char *a2)
569 { return QByteArray(a1) += a2; }
570 inline const QByteArray operator+(const QByteArray &a1, char a2)
571 { return QByteArray(a1) += a2; }
572 inline const QByteArray operator+(const char *a1, const QByteArray &a2)
573 { return QByteArray(a1) += a2; }
574 inline const QByteArray operator+(char a1, const QByteArray &a2)
575 { return QByteArray(&a1, 1) += a2; }
576 #endif // QT_USE_QSTRINGBUILDER
577 inline bool QByteArray::contains(const char *c) const
578 { return indexOf(c) != -1; }
579 inline QByteArray &QByteArray::replace(char before, const char *c)
580 { return replace(&before, 1, c, qstrlen(c)); }
581 inline QByteArray &QByteArray::replace(const QByteArray &before, const char *c)
582 { return replace(before.constData(), before.size(), c, qstrlen(c)); }
583 inline QByteArray &QByteArray::replace(const char *before, const char *after)
584 { return replace(before, qstrlen(before), after, qstrlen(after)); }
586 inline QByteArray &QByteArray::setNum(short n, int base)
587 { return setNum(qlonglong(n), base); }
588 inline QByteArray &QByteArray::setNum(ushort n, int base)
589 { return setNum(qulonglong(n), base); }
590 inline QByteArray &QByteArray::setNum(int n, int base)
591 { return setNum(qlonglong(n), base); }
592 inline QByteArray &QByteArray::setNum(uint n, int base)
593 { return setNum(qulonglong(n), base); }
594 inline QByteArray &QByteArray::setNum(float n, char f, int prec)
595 { return setNum(double(n),f,prec); }
598 #if !defined(QT_NO_DATASTREAM) || (defined(QT_BOOTSTRAPPED) && !defined(QT_BUILD_QMAKE))
599 Q_CORE_EXPORT QDataStream &operator<<(QDataStream &, const QByteArray &);
600 Q_CORE_EXPORT QDataStream &operator>>(QDataStream &, QByteArray &);
603 #ifndef QT_NO_COMPRESS
604 Q_CORE_EXPORT QByteArray qCompress(const uchar* data, int nbytes, int compressionLevel = -1);
605 Q_CORE_EXPORT QByteArray qUncompress(const uchar* data, int nbytes);
606 inline QByteArray qCompress(const QByteArray& data, int compressionLevel = -1)
607 { return qCompress(reinterpret_cast<const uchar *>(data.constData()), data.size(), compressionLevel); }
608 inline QByteArray qUncompress(const QByteArray& data)
609 { return qUncompress(reinterpret_cast<const uchar*>(data.constData()), data.size()); }
612 Q_DECLARE_TYPEINFO(QByteArray, Q_MOVABLE_TYPE);
613 Q_DECLARE_SHARED(QByteArray)
619 #ifdef QT_USE_QSTRINGBUILDER
620 #include <QtCore/qstring.h>
623 #endif // QBYTEARRAY_H