public static UriPattern parse(String uri) {
        if (uri.endsWith("?")) {
            throw new InvalidUriPatternException("URI patterns must not end with '?'. Found " + uri);
        } else if (!uri.startsWith("/")) {
            throw new InvalidUriPatternException("URI pattern must start with '/'. Found " + uri);
        } else if (uri.contains("#")) {
            throw new InvalidUriPatternException("URI pattern must not contain a fragment. Found " + uri);
        }

        String[] parts = uri.split(Pattern.quote("?"), 2);
        String[] unparsedSegments = parts[0].split(Pattern.quote("/"));
        List<Segment> segments = new ArrayList<>();
        // Skip the first "/" segment, and thus assume offset of 1.
        int offset = 1;
        for (int i = 1; i < unparsedSegments.length; i++) {
            String segment = unparsedSegments[i];
            segments.add(Segment.parse(segment, offset));
            // Add one to account for `/`
            offset += segment.length() + 1;
        }

        Map<String, String> queryLiterals = new LinkedHashMap<>();
        // Parse the query literals outside of the general pattern
        if (parts.length == 2) {
            if (parts[1].contains("{") || parts[1].contains("}")) {
                throw new InvalidUriPatternException("URI labels must not appear in the query string. Found " + uri);
            }
            for (String kvp : parts[1].split(Pattern.quote("&"))) {
                String[] parameterParts = kvp.split("=", 2);
                String actualKey = parameterParts[0];
                if (queryLiterals.containsKey(actualKey)) {
                    throw new InvalidUriPatternException("Literal query parameters must not be repeated: " + uri);
                }
                queryLiterals.put(actualKey, parameterParts.length == 2 ? parameterParts[1] : "");
            }
        }

        return new UriPattern(builder().pattern(uri).segments(segments), queryLiterals);
    }
Parse a URI pattern string into a UriPattern.

<p>The provided value must match the origin-form request-target
grammar production in RFC 9112, section 3.2.1.

@param uri URI pattern to parse.
@return Returns the parsed URI pattern.
@throws InvalidUriPatternException for invalid URI patterns.
@see <a href="https://tools.ietf.org/html/rfc9112#section-3.2.1">RFC 9112 Section 3.2.1</a>
smithy-model/src/main/java/software/amazon/smithy/model/pattern/UriPattern.java