Exemple #1
0
/*
 * Compiles a segment of path into a matchable segment object.
 *
 * @param path_segment the segment of path to compile
 *
 * @return a segment matcher compiled from the path segment
 */
inline segment_matcher_ptr
compile_to_matcher(const std::string & path_segment)
{
	if ( path_segment.empty() )
	{
		return segment_matcher_ptr(new empty_matcher());
	}
	if ( path_segment[0] == '{' && path_segment[path_segment.length() - 1] == '}' )
	{
		std::string trimmed_segment(path_segment.substr(1, path_segment.length() - 2));
		size_t colon_index = trimmed_segment.find(':');
		if ( colon_index == std::string::npos )
		{
			return segment_matcher_ptr(
				new variable_matcher(trimmed_segment)
			);
		}
		return segment_matcher_ptr(
			new regex_matcher(
				trimmed_segment.substr(0, colon_index),
				trimmed_segment.substr(colon_index + 1, std::string::npos)
			));
	}
	return segment_matcher_ptr(new static_matcher(path_segment));
}
Exemple #2
0
SegmentMatcherPtr path_segment_to_matcher(const std::string& path_segment) {
    if (path_segment.empty()) {
        return std::make_shared<EmptyMatcher>();
    }
    if (path_segment[0] == '{' &&
            path_segment[path_segment.length() - 1] == '}') {

        std::string trimmed_segment(path_segment.substr(1, path_segment.length() - 2));
        auto colon_index = trimmed_segment.find(':');
        if (colon_index == std::string::npos) {
            return std::make_shared<VariableMatcher>(trimmed_segment);
        }
        return std::make_shared<RegexMatcher>(
                trimmed_segment.substr(0, colon_index),
                trimmed_segment.substr(colon_index + 1, std::string::npos));
    }
    return std::make_shared<StaticMatcher>(path_segment);
}