From a1b0ca1807c78d1b715bb68f8f8fa08b797bd4a5 Mon Sep 17 00:00:00 2001 From: Christian Halstrick Date: Wed, 6 Oct 2010 14:02:05 +0200 Subject: Introduce commented constants for the segments of an URI regex The regular expressions used to parse URI's are constructed by concatenating different segments to a big String. Introduce String constants for these segements and document them. Change-Id: If8b9dbaaf57ca333ac0b6c9610c3d3a515c540f9 Signed-off-by: Christian Halstrick --- .../src/org/eclipse/jgit/transport/URIish.java | 57 +++++++++++++++++++--- 1 file changed, 51 insertions(+), 6 deletions(-) (limited to 'org.eclipse.jgit/src/org/eclipse') diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/URIish.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/URIish.java index 206cc823a4..44ba632d12 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/URIish.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/URIish.java @@ -61,19 +61,64 @@ import org.eclipse.jgit.lib.Constants; * any special character is written as-is. */ public class URIish implements Serializable { + /** + * Part of a pattern which matches the scheme part (git, http, ...) of an + * URI. Defines one capturing group containing the scheme without the + * trailing colon and slashes + */ + private static final String SCHEME_P = "([a-z][a-z0-9+-]+)://"; + + /** + * Part of a pattern which matches the optional user/password part (e.g. + * root:pwd@ in git://root:pwd@host.xyz/a.git) of URIs. Defines two + * capturing groups: the first containing the user and the second containing + * the password + */ + private static final String OPT_USER_PWD_P = "(?:([^/]+?)(?::([^/]+?))?@)?"; + + /** + * Part of a pattern which matches the optional host part of URIs. Defines + * one capturing group containing the host name. + */ + private static final String OPT_HOST_P = "(?:([^/]+?))?"; + + /** + * Part of a pattern which matches the optional port part of URIs. Defines + * one capturing group containing the port without the preceding colon. + */ + private static final String OPT_PORT_P = "(?::(\\d+))?"; + + /** + * Part of a pattern which matches the optional drive letter in paths (e.g. + * D: in file:///D:/a.txt). Defines no capturing group. + */ + private static final String OPT_DRIVE_LETTER_P = "(?:[A-Za-z]:)?"; + + /** + * Part of a pattern which matches a relative path. Relative paths don't + * start with slash or drive letters. Defines no capturing group. + */ + private static final String OPT_RELATIVE_PATH_P = "(?:\\.\\.)?"; + private static final long serialVersionUID = 1L; + /** + * A pattern matching standard URI:
+ * scheme "://" user_password? hostname? portnumber? path + */ private static final Pattern FULL_URI = Pattern.compile("^" // + "(?:" // - + "([a-z][a-z0-9+-]+)://" // optional http:// - + "(?:([^/]+?)(?::([^/]+?))?@)?" // optional user:password@ - + "(?:([^/]+?))?(?::(\\d+))?" // optional example.com:1337 + + SCHEME_P // + + OPT_USER_PWD_P // + + OPT_HOST_P // + + OPT_PORT_P // + ")?" // - + "(" + "(?:[A-Za-z]:)?" // optional drive-letter: - + "(?:\\.\\.)?" // optionally a relative path - + "/.+" // + + "(" + OPT_DRIVE_LETTER_P + OPT_RELATIVE_PATH_P + "/.+" // + ")$"); // /anything + /** + * A pattern matching SCP URI's of the form user@host:path/to/repo.git + */ private static final Pattern SCP_URI = Pattern.compile("^" // + "(?:([^@]+?)@)?" // + "([^:]+?)" // -- cgit v1.2.3