Ejemplo n.º 1
0
void
BUrl::_ExplodeUrlString(const BString& url)
{
	// The regexp is provided in RFC3986 (URI generic syntax), Appendix B
	static RegExp urlMatcher(
		"^(([^:/?#]+):)?(//([^/?#]*))?([^?#]*)(\\?([^#]*))?(#(.*))?");

	_ResetFields();

	RegExp::MatchResult match = urlMatcher.Match(url.String());

	if (!match.HasMatched())
		return; // TODO error reporting

	// Scheme/Protocol
	url.CopyInto(fProtocol, match.GroupStartOffsetAt(1),
		match.GroupEndOffsetAt(1) - match.GroupStartOffsetAt(1));
	if (!_IsProtocolValid()) {
		fHasProtocol = false;
		fProtocol.Truncate(0);
	} else
		fHasProtocol = true;

	// Authority (including user credentials, host, and port
	url.CopyInto(fAuthority, match.GroupStartOffsetAt(3),
		match.GroupEndOffsetAt(3) - match.GroupStartOffsetAt(3));
	SetAuthority(fAuthority);

	// Path
	url.CopyInto(fPath, match.GroupStartOffsetAt(4),
		match.GroupEndOffsetAt(4) - match.GroupStartOffsetAt(4));
	if (!fPath.IsEmpty())
		fHasPath = true;

	// Query
	url.CopyInto(fRequest, match.GroupStartOffsetAt(6),
		match.GroupEndOffsetAt(6) - match.GroupStartOffsetAt(6));
	if (!fRequest.IsEmpty())
		fHasRequest = true;

	// Fragment
	url.CopyInto(fFragment, match.GroupStartOffsetAt(8),
		match.GroupEndOffsetAt(8) - match.GroupStartOffsetAt(8));
	if (!fFragment.IsEmpty())
		fHasFragment = true;
}
Ejemplo n.º 2
0
void
BUrl::_ExtractProtocol(const BString& urlString, int16* origin)
{
	int16 firstColon = urlString.FindFirst(':', *origin);

	// If no colon is found, assume the protocol
	// is not present
	if (firstColon == -1) 
		return;
	else {
		urlString.CopyInto(fProtocol, *origin, firstColon - *origin);
		*origin = firstColon + 1;
	}

	if (!_IsProtocolValid()) {
		fHasProtocol = false;
		fProtocol.Truncate(0);
	} else
		fHasProtocol = true;
}