mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
URLUtil.splitScheme(): rewrite in a more clear way.
* Use method proposed in CR-IC-374
* Change behavior: return the scheme without scheme separator ("://")
This commit is contained in:
@@ -16,6 +16,8 @@
|
||||
|
||||
package com.intellij.util.io;
|
||||
|
||||
import com.google.common.base.Splitter;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.intellij.openapi.util.Pair;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import gnu.trove.TIntArrayList;
|
||||
@@ -28,10 +30,14 @@ import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.URL;
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.ArrayList;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipFile;
|
||||
|
||||
public class URLUtil {
|
||||
|
||||
public static final String SCHEME_SEPARATOR = "://";
|
||||
|
||||
private URLUtil() {
|
||||
}
|
||||
|
||||
@@ -145,24 +151,21 @@ public class URLUtil {
|
||||
return -1;
|
||||
}
|
||||
|
||||
public static boolean containsScheme(String url) {
|
||||
return url.contains("://");
|
||||
public static boolean containsScheme(@NotNull String url) {
|
||||
return url.contains(SCHEME_SEPARATOR);
|
||||
}
|
||||
|
||||
/**
|
||||
* Splits the url into 2 parts: the scheme ("http://" for instance) and the rest of the URL.
|
||||
* Splits the url into 2 parts: the scheme ("http", for instance) and the rest of the URL. <br/>
|
||||
* Scheme separator is not included neither to the scheme part, nor to the url part. <br/>
|
||||
* The scheme can be absent, in which case empty string is written to the first item of the Pair.
|
||||
*/
|
||||
@NotNull
|
||||
public static Pair<String, String> splitScheme(@NotNull String url) {
|
||||
final String schemeSeparator = "://";
|
||||
int ind = url.indexOf(schemeSeparator);
|
||||
if (ind >= 0) {
|
||||
String scheme = url.substring(0, ind + schemeSeparator.length());
|
||||
return Pair.create(scheme, url.substring(ind + schemeSeparator.length()));
|
||||
}
|
||||
else {
|
||||
return Pair.create("", url);
|
||||
ArrayList<String> list = Lists.newArrayList(Splitter.on(SCHEME_SEPARATOR).limit(2).split(url));
|
||||
if (list.size() == 1) {
|
||||
return Pair.create("", list.get(0));
|
||||
}
|
||||
return Pair.create(list.get(0), list.get(1));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
<orderEntry type="library" name="OroMatcher" level="project" />
|
||||
<orderEntry type="library" scope="TEST" name="JUnit4" level="project" />
|
||||
<orderEntry type="library" scope="TEST" name="Groovy" level="project" />
|
||||
<orderEntry type="library" name="Guava" level="project" />
|
||||
</component>
|
||||
<component name="copyright">
|
||||
<Base>
|
||||
|
||||
@@ -176,7 +176,7 @@ class GitHttpGuiAuthenticator implements GitHttpAuthenticator {
|
||||
String scheme = split.getFirst();
|
||||
String urlItself = split.getSecond();
|
||||
int pathStart = urlItself.indexOf("/");
|
||||
return scheme + urlItself.substring(0, pathStart);
|
||||
return scheme + URLUtil.SCHEME_SEPARATOR + urlItself.substring(0, pathStart);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -232,7 +232,7 @@ class GitHttpGuiAuthenticator implements GitHttpAuthenticator {
|
||||
Pair<String,String> pair = URLUtil.splitScheme(url);
|
||||
String scheme = pair.getFirst();
|
||||
if (StringUtil.isEmpty(scheme)) {
|
||||
return scheme + login + "@" + pair.getSecond();
|
||||
return scheme + URLUtil.SCHEME_SEPARATOR + login + "@" + pair.getSecond();
|
||||
}
|
||||
return login + "@" + url;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user