Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qurlrecode.cpp File Reference

(dc45850c1e64565af5bcd8446389fd558131e58b)

#include "qurl.h"
#include "private/qstringconverter_p.h"
#include "private/qtools_p.h"
#include "private/qsimd_p.h"
Include dependency graph for qurlrecode.cpp:

Go to the source code of this file.

Enumerations

enum  EncodingAction {
  DecodeCharacter = 0 , LeaveCharacter = 1 , EncodeCharacter = 2 , DecodeCharacter = 0 ,
  LeaveCharacter = 1 , EncodeCharacter = 2
}
enum  EncodingAction {
  DecodeCharacter = 0 , LeaveCharacter = 1 , EncodeCharacter = 2 , DecodeCharacter = 0 ,
  LeaveCharacter = 1 , EncodeCharacter = 2
}

Functions

static bool isHex (char16_t c)
static bool isUpperHex (char16_t c)
static char16_t toUpperHex (char16_t c)
static ushort decodeNibble (char16_t c)
static char16_t decodePercentEncoding (const char16_t *input)
static char16_t encodeNibble (ushort c)
static void ensureDetached (QString &result, char16_t *&output, const char16_t *begin, const char16_t *input, const char16_t *end, int add=0)
static bool encodedUtf8ToUtf16 (QString &result, char16_t *&output, const char16_t *begin, const char16_t *&input, const char16_t *end, char16_t decoded)
static void unicodeToEncodedUtf8 (QString &result, char16_t *&output, const char16_t *begin, const char16_t *&input, const char16_t *end, char16_t decoded)
static int recode (QString &result, const char16_t *begin, const char16_t *end, QUrl::ComponentFormattingOptions encoding, const uchar *actionTable, bool retryBadEncoding)
static bool simdCheckNonEncoded (...)
static qsizetype decode (QString &appendTo, QStringView in)
template<size_t N>
static void maskTable (uchar(&table)[N], const uchar(&mask)[N])
Q_AUTOTEST_EXPORT qsizetype qt_urlRecode (QString &appendTo, QStringView in, QUrl::ComponentFormattingOptions encoding, const ushort *tableModifications)
qsizetype qt_encodeFromUser (QString &appendTo, const QString &in, const ushort *tableModifications)

Variables

static const uchar defaultActionTable [96]
static const uchar reservedMask [96]

Enumeration Type Documentation

◆ EncodingAction [1/2]

Enumerator
DecodeCharacter 
LeaveCharacter 
EncodeCharacter 
DecodeCharacter 
LeaveCharacter 
EncodeCharacter 

Definition at line 13 of file qurlrecode.cpp.

◆ EncodingAction [2/2]

Enumerator
DecodeCharacter 
LeaveCharacter 
EncodeCharacter 
DecodeCharacter 
LeaveCharacter 
EncodeCharacter 

Definition at line 13 of file qurlrecode.cpp.

Function Documentation

◆ decode()

qsizetype decode ( QString & appendTo,
QStringView in )
static
Since
5.0

This function decodes a percent-encoded string located in in by appending each character to appendTo. It returns the number of characters appended. Each percent-encoded sequence is decoded as follows:

\list

  • from %00 to %7F: the exact decoded value is appended;
  • from %80 to FF: QChar::ReplacementCharacter is appended;
  • bad encoding: original input is copied to the output, undecoded. \endlist

Given the above, it's important for the input to already have all UTF-8 percent sequences decoded by qt_urlRecode (that is, the input should not have been processed with QUrl::EncodeUnicode).

The input should also be a valid percent-encoded sequence (the output of qt_urlRecode is always valid).

Definition at line 546 of file qurlrecode.cpp.

References isHex().

Here is the call graph for this function:

◆ decodeNibble()

ushort decodeNibble ( char16_t c)
inlinestatic

Definition at line 151 of file qurlrecode.cpp.

◆ decodePercentEncoding()

char16_t decodePercentEncoding ( const char16_t * input)
inlinestatic

Definition at line 159 of file qurlrecode.cpp.

References isHex().

Referenced by recode().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ encodedUtf8ToUtf16()

bool encodedUtf8ToUtf16 ( QString & result,
char16_t *& output,
const char16_t * begin,
const char16_t *& input,
const char16_t * end,
char16_t decoded )
static

Definition at line 256 of file qurlrecode.cpp.

◆ encodeNibble()

char16_t encodeNibble ( ushort c)
inlinestatic

Definition at line 168 of file qurlrecode.cpp.

◆ ensureDetached()

void ensureDetached ( QString & result,
char16_t *& output,
const char16_t * begin,
const char16_t * input,
const char16_t * end,
int add = 0 )
static

Definition at line 173 of file qurlrecode.cpp.

◆ isHex()

bool isHex ( char16_t c)
inlinestatic

Definition at line 135 of file qurlrecode.cpp.

Referenced by decode(), and decodePercentEncoding().

Here is the caller graph for this function:

◆ isUpperHex()

bool isUpperHex ( char16_t c)
inlinestatic

Definition at line 140 of file qurlrecode.cpp.

Referenced by recode(), and toUpperHex().

Here is the caller graph for this function:

◆ maskTable()

template<size_t N>
void maskTable ( uchar(&) table[N],
const uchar(&) mask[N] )
static

Definition at line 600 of file qurlrecode.cpp.

◆ qt_encodeFromUser()

qsizetype qt_encodeFromUser ( QString & appendTo,
const QString & in,
const ushort * tableModifications )

Definition at line 664 of file qurlrecode.cpp.

References defaultActionTable, and EncodeCharacter.

◆ qt_urlRecode()

Q_AUTOTEST_EXPORT qsizetype qt_urlRecode ( QString & appendTo,
QStringView in,
QUrl::ComponentFormattingOptions encoding,
const ushort * tableModifications )

Recodes the string from begin to end. If any transformations are done, append them to appendTo and return the number of characters added. If no transformations were required, return 0.

The encoding option modifies the default behaviour: \list

  • QUrl::DecodeReserved: if set, reserved characters will be decoded; if unset, reserved characters will be encoded
  • QUrl::EncodeSpaces: if set, spaces will be encoded to "%20"; if unset, they will be " "
  • QUrl::EncodeUnicode: if set, characters above U+0080 will be encoded to their UTF-8 percent-encoded form; if unset, they will be decoded to UTF-16
  • QUrl::FullyDecoded: if set, this function will decode all percent-encoded sequences, including that of the percent character. The resulting string will not be percent-encoded anymore. Use with caution! In this mode, the behaviour is undefined if the input string contains any percent-encoding sequences above %80. Also, the function will not correct bad % sequences. \endlist

Other flags are ignored (including QUrl::EncodeReserved).

The tableModifications argument can be used to supply extra modifications to the tables, to be applied after the flags above are handled. It consists of a sequence of 16-bit values, where the low 8 bits indicate the character in question and the high 8 bits are either EncodeCharacter, LeaveCharacter or DecodeCharacter.

This function corrects percent-encoded errors by interpreting every '' as meaning "%25" (all percents in the same content).

Definition at line 641 of file qurlrecode.cpp.

◆ recode()

int recode ( QString & result,
const char16_t * begin,
const char16_t * end,
QUrl::ComponentFormattingOptions encoding,
const uchar * actionTable,
bool retryBadEncoding )
static

Definition at line 339 of file qurlrecode.cpp.

References DecodeCharacter, decodePercentEncoding(), EncodeCharacter, isUpperHex(), LeaveCharacter, and toUpperHex().

Here is the call graph for this function:

◆ simdCheckNonEncoded()

bool simdCheckNonEncoded ( ...)
static

Definition at line 519 of file qurlrecode.cpp.

◆ toUpperHex()

char16_t toUpperHex ( char16_t c)
inlinestatic

Definition at line 146 of file qurlrecode.cpp.

References isUpperHex().

Referenced by recode().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ unicodeToEncodedUtf8()

void unicodeToEncodedUtf8 ( QString & result,
char16_t *& output,
const char16_t * begin,
const char16_t *& input,
const char16_t * end,
char16_t decoded )
static

Definition at line 285 of file qurlrecode.cpp.

Variable Documentation

◆ defaultActionTable

const uchar defaultActionTable
static

Definition at line 25 of file qurlrecode.cpp.

Referenced by qt_encodeFromUser().

◆ reservedMask

const uchar reservedMask
static

Definition at line 82 of file qurlrecode.cpp.