📄 qurl.cpp
字号:
static bool QT_FASTCALL _ALPHA_(char **ptr, char *c){ char ch = **ptr; if ((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z')) { *c = ch; ++(*ptr); return true; } return false;}static bool QT_FASTCALL _DIGIT_(char **ptr, char *c){ char ch = **ptr; if (ch >= '0' && ch <= '9') { *c = ch; ++(*ptr); return true; } return false;}// unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~"static bool QT_FASTCALL _unreserved(char **ptr, char *c, ErrorInfo *errorInfo){ if (_ALPHA_(ptr, c) || _DIGIT_(ptr, c)) return true; char ch = **ptr; switch (ch) { case '-': case '.': case '_': case '~': *c = ch; ++(*ptr); return true; default: errorInfo->setParams(*ptr, QLatin1String(QT_TRANSLATE_NOOP(QUrl, "expected unreserved (alpha, digit,")) + QLatin1String("\'=\', \'.\', \'_\', \'~\'"), QLatin1Char('\0'), QLatin1Char(ch)); return false; }}// scheme = ALPHA *( ALPHA / DIGIT / "+" / "-" / "." )static bool QT_FASTCALL _scheme(char **ptr, QByteArray *scheme){ bool first = true; for (;;) { char ch = **ptr; if ((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z')) { *scheme += ch; } else if (!first && ((ch >= '0' && ch <= '9') || ch == '+' || ch == '-' || ch == '.')) { *scheme += ch; } else { break; } ++(*ptr); first = false; } return true;}// IPvFuture = "v" 1*HEXDIG "." 1*( unreserved / sub-delims / ":" )static bool QT_FASTCALL _IPvFuture(char **ptr, QByteArray *host, ErrorInfo *errorInfo){ char *ptrBackup = *ptr; char ch = *((*ptr)++); if (ch != 'v') { *ptr = ptrBackup; errorInfo->setParams(*ptr, QLatin1String(""), QLatin1Char('v'), QLatin1Char(ch)); return false; } *host += ch; if (!_HEXDIG(ptr, &ch, errorInfo)) { *ptr = ptrBackup; return false; } *host += ch; while (_HEXDIG(ptr, &ch, errorInfo)) *host += ch; char c = *((*ptr)++); if (c != '.') { *ptr = ptrBackup; errorInfo->setParams(*ptr, QLatin1String(""), QLatin1Char('.'), QLatin1Char(c)); return false; } if (!_unreserved(ptr, &ch, errorInfo) && !_subDelims(ptr, &ch, errorInfo) && (ch = *((*ptr)++)) != ':') { *ptr = ptrBackup; errorInfo->setParams(*ptr, QLatin1String(""), QLatin1Char(':'), QLatin1Char(ch)); return false; } *host += ch; while (_unreserved(ptr, &ch, errorInfo) || _subDelims(ptr, &ch, errorInfo) || (ch = *((*ptr)++)) == ':') *host += ch; return true;}// h16 = 1*4HEXDIG// ; 16 bits of address represented in hexadecimalstatic bool QT_FASTCALL _h16(char **ptr, QByteArray *c, ErrorInfo *errorInfo){ char ch; if (!_HEXDIG(ptr, &ch, errorInfo)) return false; *c += ch; for (int i = 0; i < 3; ++i) { if (!_HEXDIG(ptr, &ch, errorInfo)) break; *c += ch; } return true;}// dec-octet = DIGIT ; 0-9// / %x31-39 DIGIT ; 10-99// / "1" 2DIGIT ; 100-199// / "2" %x30-34 DIGIT ; 200-249// / "25" %x30-35 ; 250-255static bool QT_FASTCALL _decOctet(char **ptr, QByteArray *octet, ErrorInfo *errorInfo){ char c1 = **ptr; if (c1 < '0' || c1 > '9') { errorInfo->setParams(*ptr, QLatin1String(QT_TRANSLATE_NOOP(QUrl, "expected decimal digit (0-9)")), QLatin1Char('\0'), QLatin1Char(c1)); return false; } *octet += c1; ++(*ptr); if (c1 == '0') return true; char c2 = **ptr; if (c2 < '0' || c2 > '9') return true; *octet += c2; ++(*ptr); char c3 = **ptr; if (c3 < '0' || c3 > '9') return true; *octet += c3; // If there is a three digit number larger than 255, reject the // whole token. if (c1 >= '2' && c2 >= '5' && c3 > '5') { errorInfo->setParams(*ptr, QLatin1String(QT_TRANSLATE_NOOP(QUrl, "digit number larger than 255")), QLatin1Char('\0'), QLatin1Char('\0')); return false; } ++(*ptr); return true;}// IPv4address = dec-octet "." dec-octet "." dec-octet "." dec-octetstatic bool QT_FASTCALL _IPv4Address(char **ptr, QByteArray *c, ErrorInfo *errorInfo){ char *ptrBackup = *ptr; QByteArray tmp1; tmp1.reserve(32); if (!_decOctet(ptr, &tmp1, errorInfo)) { *ptr = ptrBackup; return false; } for (int i = 0; i < 3; ++i) { char ch = *((*ptr)++); if (ch != '.') { *ptr = ptrBackup; errorInfo->setParams(*ptr, QLatin1String(""), QLatin1Char('.'), QLatin1Char(ch)); return false; } tmp1 += '.'; if (!_decOctet(ptr, &tmp1, errorInfo)) { *ptr = ptrBackup; return false; } } *c += tmp1; return true;}// ls32 = ( h16 ":" h16 ) / IPv4address// ; least-significant 32 bits of addressstatic bool QT_FASTCALL _ls32(char **ptr, QByteArray *c, ErrorInfo *errorInfo){ char *ptrBackup = *ptr; QByteArray tmp1; QByteArray tmp2; if (_h16(ptr, &tmp1, errorInfo) && _char(ptr, ':', errorInfo) && _h16(ptr, &tmp2, errorInfo)) { *c += tmp1; *c += ':'; *c += tmp2; return true; } *ptr = ptrBackup; return _IPv4Address(ptr, c, errorInfo);}// IPv6address = 6( h16 ":" ) ls32 // case 1// / "::" 5( h16 ":" ) ls32 // case 2// / [ h16 ] "::" 4( h16 ":" ) ls32 // case 3// / [ *1( h16 ":" ) h16 ] "::" 3( h16 ":" ) ls32 // case 4// / [ *2( h16 ":" ) h16 ] "::" 2( h16 ":" ) ls32 // case 5// / [ *3( h16 ":" ) h16 ] "::" h16 ":" ls32 // case 6// / [ *4( h16 ":" ) h16 ] "::" ls32 // case 7// / [ *5( h16 ":" ) h16 ] "::" h16 // case 8// / [ *6( h16 ":" ) h16 ] "::" // case 9static bool QT_FASTCALL _IPv6Address(char **ptr, QByteArray *host, ErrorInfo *errorInfo){ char *ptrBackup = *ptr; QByteArray tmp; // count of (h16 ":") to the left of and including :: int leftHexColons = 0; // count of (h16 ":") to the right of :: int rightHexColons = 0; // first count the number of (h16 ":") on the left of :: while (_h16(ptr, &tmp, errorInfo)) { // an h16 not followed by a colon is considered an // error. if (!_char(ptr, ':', errorInfo)) { *ptr = ptrBackup; return false; } tmp += ':'; ++leftHexColons; // check for case 1, the only time when there can be no :: if (leftHexColons == 6 && _ls32(ptr, &tmp, errorInfo)) { *host += tmp; return true; } } // check for case 2 where the address starts with a : if (leftHexColons == 0 && _char(ptr, ':', errorInfo)) tmp += ':'; // check for the second colon in :: if (!_char(ptr, ':', errorInfo)) { *ptr = ptrBackup; return false; } tmp += ':'; int canBeCase = -1; bool ls32WasRead = false; QByteArray tmp2; char *tmpBackup = *ptr; // count the number of (h16 ":") on the right of :: for (;;) { tmpBackup = *ptr; if (!_h16(ptr, &tmp2, errorInfo)) { if (!_ls32(ptr, &tmp, errorInfo)) { if (rightHexColons != 0) { *ptr = ptrBackup; errorInfo->setParams(*ptr, QLatin1String(QT_TRANSLATE_NOOP(QUrl, "too many colons (\':\'))")), QLatin1Char('\0'), QLatin1Char('\0')); return false; } // the address ended with :: (case 9) // only valid if 1 <= leftHexColons <= 7 canBeCase = 9; } else { ls32WasRead = true; } break; } ++rightHexColons; if (!_char(ptr, ':', errorInfo)) { // no colon could mean that what was read as an h16 // was in fact the first part of an ls32. we backtrack // and retry. char *pb = *ptr; *ptr = tmpBackup; if (_ls32(ptr, &tmp, errorInfo)) { ls32WasRead = true; --rightHexColons; } else { *ptr = pb; // address ends with only 1 h16 after :: (case 8) if (rightHexColons == 1) canBeCase = 8; tmp += tmp2; } break; } tmp += tmp2 + ':'; tmp2.truncate(0); } // determine which case it is based on the number of rightHexColons if (canBeCase == -1) { // check if a ls32 was read. If it wasn't and rightHexColons >= 2 then the // last 2 HexColons are in fact a ls32 if (!ls32WasRead && rightHexColons >= 2) rightHexColons -= 2; canBeCase = 7 - rightHexColons; } // based on the case we need to check that the number of leftHexColons is valid if (leftHexColons > (canBeCase - 2)) { *ptr = ptrBackup; errorInfo->setParams(*ptr, QLatin1String(QT_TRANSLATE_NOOP(QUrl, "too many colons (\':\')")), QLatin1Char('\0'), QLatin1Char('\0')); return false; } *host += tmp; return true;}// IP-literal = "[" ( IPv6address / IPvFuture ) "]"static bool QT_FASTCALL _IPLiteral(char **ptr, QByteArray *host, ErrorInfo *errorInfo){ char *ptrBackup = *ptr; if (!_char(ptr, '[', errorInfo)) return false; *host += '[';
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -