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

(05fc3aef53348fb58be6308076e000825b704e58)

#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)
 

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 12 of file qurlrecode.cpp.

◆ EncodingAction [2/2]

Enumerator
DecodeCharacter 
LeaveCharacter 
EncodeCharacter 
DecodeCharacter 
LeaveCharacter 
EncodeCharacter 

Definition at line 12 of file qurlrecode.cpp.

Function Documentation

◆ decode()

static 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 543 of file qurlrecode.cpp.

References isHex().

+ Here is the call graph for this function:

◆ decodeNibble()

static ushort decodeNibble ( char16_t c)
inlinestatic

Definition at line 150 of file qurlrecode.cpp.

◆ decodePercentEncoding()

static char16_t decodePercentEncoding ( const char16_t * input)
inlinestatic

Definition at line 158 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()

static 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 255 of file qurlrecode.cpp.

◆ encodeNibble()

static char16_t encodeNibble ( ushort c)
inlinestatic

Definition at line 167 of file qurlrecode.cpp.

◆ ensureDetached()

static 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 172 of file qurlrecode.cpp.

◆ isHex()

static bool isHex ( char16_t c)
inlinestatic

Definition at line 134 of file qurlrecode.cpp.

Referenced by decode(), and decodePercentEncoding().

+ Here is the caller graph for this function:

◆ isUpperHex()

static bool isUpperHex ( char16_t c)
inlinestatic

Definition at line 139 of file qurlrecode.cpp.

Referenced by recode(), and toUpperHex().

+ Here is the caller graph for this function:

◆ maskTable()

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

Definition at line 597 of file qurlrecode.cpp.

◆ 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 638 of file qurlrecode.cpp.

◆ recode()

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

Definition at line 336 of file qurlrecode.cpp.

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

+ Here is the call graph for this function:

◆ simdCheckNonEncoded()

static bool simdCheckNonEncoded ( ...)
static

Definition at line 516 of file qurlrecode.cpp.

◆ toUpperHex()

static char16_t toUpperHex ( char16_t c)
inlinestatic

Definition at line 145 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()

static 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 282 of file qurlrecode.cpp.

Variable Documentation

◆ defaultActionTable

static const uchar defaultActionTable
static

Definition at line 24 of file qurlrecode.cpp.

◆ reservedMask

static const uchar reservedMask
static

Definition at line 81 of file qurlrecode.cpp.