コード例 #1
0
ファイル: DebugServer.cpp プロジェクト: yunxiaoxiao110/haiku
static bool
match_team_name(const char* teamName, const char* parameterName)
{
    RegExp expressionMatcher;
    if (expressionMatcher.SetPattern(parameterName,
                                     RegExp::PATTERN_TYPE_WILDCARD)) {
        BString value = teamName;
        if (parameterName[0] != '/') {
            // the expression in question is a team name match only,
            // so we need to extract that.
            BPath path(teamName);
            if (path.InitCheck() == B_OK)
                value = path.Leaf();
        }

        RegExp::MatchResult match = expressionMatcher.Match(value);
        if (match.HasMatched())
            return true;
    }

    return false;
}
コード例 #2
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
	if (match.GroupEndOffsetAt(2) - match.GroupStartOffsetAt(2) > 0)
	{
		url.CopyInto(fAuthority, match.GroupStartOffsetAt(3),
			match.GroupEndOffsetAt(3) - match.GroupStartOffsetAt(3));
		SetAuthority(fAuthority);
	} else {
		fHasHost = false;
		fHasPort = false;
		fHasUserName = false;
		fHasPassword = false;
	}

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

	// Query
	if (match.GroupEndOffsetAt(5) - match.GroupStartOffsetAt(5) > 0)
	{
		url.CopyInto(fRequest, match.GroupStartOffsetAt(6),
			match.GroupEndOffsetAt(6) - match.GroupStartOffsetAt(6));
		fHasRequest = true;
	} else {
		fRequest = "";
		fHasRequest = false;
	}

	// Fragment
	if (match.GroupEndOffsetAt(7) - match.GroupStartOffsetAt(7) > 0)
	{
		url.CopyInto(fFragment, match.GroupStartOffsetAt(8),
			match.GroupEndOffsetAt(8) - match.GroupStartOffsetAt(8));
		fHasFragment = true;
	} else {
		fFragment = "";
		fHasFragment = false;
	}
}