summaryrefslogtreecommitdiffstats
path: root/src/corelib/text
diff options
context:
space:
mode:
authorThiago Macieira <thiago.macieira@intel.com>2020-05-22 17:37:18 -0700
committerThiago Macieira <thiago.macieira@intel.com>2020-08-05 21:51:24 -0700
commit60aa0d086886aea58d6b7a09484645ad1d92a220 (patch)
tree4eb23294c567c79fb9efcce053e6d34547cf1051 /src/corelib/text
parent9f4c9529f609d947e2884af527208ac4c76a12d6 (diff)
Allow use of charXX_t in QUtf8Functions
Even added an internal char8_t type if the compiler doesn't have one. Change-Id: Ied637aece2a7427b8a2dfffd1611813c345d10ec Reviewed-by: Lars Knoll <lars.knoll@qt.io>
Diffstat (limited to 'src/corelib/text')
-rw-r--r--src/corelib/text/qstringconverter_p.h44
1 files changed, 42 insertions, 2 deletions
diff --git a/src/corelib/text/qstringconverter_p.h b/src/corelib/text/qstringconverter_p.h
index 2e897c47eb..4e1efd3731 100644
--- a/src/corelib/text/qstringconverter_p.h
+++ b/src/corelib/text/qstringconverter_p.h
@@ -1,7 +1,7 @@
/****************************************************************************
**
-** Copyright (C) 2018 The Qt Company Ltd.
-** Copyright (C) 2018 Intel Corporation.
+** Copyright (C) 2020 The Qt Company Ltd.
+** Copyright (C) 2020 Intel Corporation.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the QtCore module of the Qt Toolkit.
@@ -58,6 +58,10 @@
QT_BEGIN_NAMESPACE
+#ifndef __cpp_char8_t
+enum char8_t : uchar {};
+#endif
+
struct QUtf8BaseTraits
{
static const bool isTrusted = false;
@@ -72,39 +76,75 @@ struct QUtf8BaseTraits
static void appendByte(uchar *&ptr, uchar b)
{ *ptr++ = b; }
+ static void appendByte(char8_t *&ptr, char8_t b)
+ { *ptr++ = b; }
+
static uchar peekByte(const uchar *ptr, qsizetype n = 0)
{ return ptr[n]; }
+ static uchar peekByte(const char8_t *ptr, int n = 0)
+ { return ptr[n]; }
+
static qptrdiff availableBytes(const uchar *ptr, const uchar *end)
{ return end - ptr; }
+ static qptrdiff availableBytes(const char8_t *ptr, const char8_t *end)
+ { return end - ptr; }
+
static void advanceByte(const uchar *&ptr, qsizetype n = 1)
{ ptr += n; }
+ static void advanceByte(const char8_t *&ptr, int n = 1)
+ { ptr += n; }
+
static void appendUtf16(ushort *&ptr, ushort uc)
{ *ptr++ = uc; }
+ static void appendUtf16(char16_t *&ptr, ushort uc)
+ { *ptr++ = char16_t(uc); }
+
static void appendUcs4(ushort *&ptr, uint uc)
{
appendUtf16(ptr, QChar::highSurrogate(uc));
appendUtf16(ptr, QChar::lowSurrogate(uc));
}
+ static void appendUcs4(char16_t *&ptr, char32_t uc)
+ {
+ appendUtf16(ptr, QChar::highSurrogate(uc));
+ appendUtf16(ptr, QChar::lowSurrogate(uc));
+ }
+
static ushort peekUtf16(const ushort *ptr, qsizetype n = 0)
{ return ptr[n]; }
+ static ushort peekUtf16(const char16_t *ptr, int n = 0)
+ { return ptr[n]; }
+
static qptrdiff availableUtf16(const ushort *ptr, const ushort *end)
{ return end - ptr; }
+ static qptrdiff availableUtf16(const char16_t *ptr, const char16_t *end)
+ { return end - ptr; }
+
static void advanceUtf16(const ushort *&ptr, qsizetype n = 1)
{ ptr += n; }
+ static void advanceUtf16(const char16_t *&ptr, int n = 1)
+ { ptr += n; }
+
// it's possible to output to UCS-4 too
static void appendUtf16(uint *&ptr, ushort uc)
{ *ptr++ = uc; }
+ static void appendUtf16(char32_t *&ptr, ushort uc)
+ { *ptr++ = char32_t(uc); }
+
static void appendUcs4(uint *&ptr, uint uc)
{ *ptr++ = uc; }
+
+ static void appendUcs4(char32_t *&ptr, uint uc)
+ { *ptr++ = char32_t(uc); }
};
struct QUtf8BaseTraitsNoAscii : public QUtf8BaseTraits