📄 qurl.cpp
字号:
} *host += ch; if (!_HEXDIG(ptr, &ch)) { *ptr = ptrBackup; return false; } *host += ch; while (_HEXDIG(ptr, &ch)) *host += ch; if (*((*ptr)++) != '.') { *ptr = ptrBackup; return false; } if (!_unreserved(ptr, &ch) && !_subDelims(ptr, &ch) && (ch = *((*ptr)++)) != ':') { *ptr = ptrBackup; return false; } *host += ch; while (_unreserved(ptr, &ch) || _subDelims(ptr, &ch) || (ch = *((*ptr)++)) == ':') *host += ch; return true;}// h16 = 1*4HEXDIG// ; 16 bits of address represented in hexadecimalstatic bool QT_FASTCALL _h16(char **ptr, QByteArray *c){ char ch; if (!_HEXDIG(ptr, &ch)) return false; *c += ch; for (int i = 0; i < 3; ++i) { if (!_HEXDIG(ptr, &ch)) 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){ char c1 = **ptr; if (c1 < '0' || c1 > '9') 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') return false; ++(*ptr); return true;}// IPv4address = dec-octet "." dec-octet "." dec-octet "." dec-octetstatic bool QT_FASTCALL _IPv4Address(char **ptr, QByteArray *c){ char *ptrBackup = *ptr; QByteArray tmp1; tmp1.reserve(32); if (!_decOctet(ptr, &tmp1)) { *ptr = ptrBackup; return false; } for (int i = 0; i < 3; ++i) { if (*((*ptr)++) != '.') { *ptr = ptrBackup; return false; } tmp1 += '.'; if (!_decOctet(ptr, &tmp1)) { *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){ char *ptrBackup = *ptr; QByteArray tmp1; QByteArray tmp2; if (_h16(ptr, &tmp1) && _char(ptr, ':') && _h16(ptr, &tmp2)) { *c += tmp1; *c += ':'; *c += tmp2; return true; } *ptr = ptrBackup; return _IPv4Address(ptr, c);}// 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){ 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)) { // an h16 not followed by a colon is considered an // error. if (!_char(ptr, ':')) { *ptr = ptrBackup; return false; } tmp += ':'; ++leftHexColons; // check for case 1, the only time when there can be no :: if (leftHexColons == 6 && _ls32(ptr, &tmp)) { *host += tmp; return true; } } // check for case 2 where the address starts with a : if (leftHexColons == 0 && _char(ptr, ':')) tmp += ':'; // check for the second colon in :: if (!_char(ptr, ':')) { *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)) { if (!_ls32(ptr, &tmp)) { if (rightHexColons != 0) { *ptr = ptrBackup; return false; } // the address ended with :: (case 9) // only valid if 1 <= leftHexColons <= 7 canBeCase = 9; } else { ls32WasRead = true; } break; } ++rightHexColons; if (!_char(ptr, ':')) { // 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)) { 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; return false; } *host += tmp; return true;}// IP-literal = "[" ( IPv6address / IPvFuture ) "]"static bool QT_FASTCALL _IPLiteral(char **ptr, QByteArray *host){ char *ptrBackup = *ptr; if (!_char(ptr, '[')) return false; *host += '['; if (!_IPv6Address(ptr, host) && !_IPvFuture(ptr, host)) { *ptr = ptrBackup; return false; } if (!_char(ptr, ']')) { *ptr = ptrBackup; return false; } *host += ']'; return true;}// reg-name = *( unreserved / pct-encoded / sub-delims )static bool QT_FASTCALL _regName(char **ptr, QByteArray *host){ char pctTmp[4]; for (;;) { char ch; if (!_unreserved(ptr, &ch) && !_subDelims(ptr, &ch)) { if (!_pctEncoded(ptr, pctTmp)) break; *host += pctTmp; } else { *host += ch; } } return true;}// host = IP-literal / IPv4address / reg-namestatic bool QT_FASTCALL _host(char **ptr, QByteArray *host){ return (_IPLiteral(ptr, host) || _IPv4Address(ptr, host) || _regName(ptr, host));}// userinfo = *( unreserved / pct-encoded / sub-delims / ":" )static bool QT_FASTCALL _userInfo(char **ptr, QByteArray *userInfo){ for (;;) { char ch; if (_unreserved(ptr, &ch) || _subDelims(ptr, &ch)) { *userInfo += ch; } else { char pctTmp[4]; if (_pctEncoded(ptr, pctTmp)) { *userInfo += pctTmp; } else if (_char(ptr, ':')) { *userInfo += ':'; } else { break; } } } return true;}// port = *DIGITstatic bool QT_FASTCALL _port(char **ptr, int *port){ bool first = true; for (;;) { char *ptrBackup = *ptr; char ch = *((*ptr)++); if (ch < '0' || ch > '9') { *ptr = ptrBackup; break; } if (first) { first = false; *port = 0; } *port *= 10; *port += ch - '0'; } return true;}// authority = [ userinfo "@" ] host [ ":" port ]static bool QT_FASTCALL _authority(char **ptr, QByteArray *userInfo, QByteArray *host, int *port){ char *ptrBackup = *ptr; if (_userInfo(ptr, userInfo)) { if (*((*ptr)++) != '@') { *ptr = ptrBackup; userInfo->clear(); // fall through } } if (!_host(ptr, host)) { *ptr = ptrBackup; return false; } char *ptrBackup2 = *ptr; if (*((*ptr)++) != ':') { *ptr = ptrBackup2; return true; } if (!_port(ptr, port)) { *ptr = ptrBackup2; return false; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -