本文整理了Java中okhttp3.internal.Util.delimiterOffset()
方法的一些代码示例,展示了Util.delimiterOffset()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Util.delimiterOffset()
方法的具体详情如下:
包路径:okhttp3.internal.Util
类名称:Util
方法名:delimiterOffset
[英]Returns the index of the first character in input that is delimiter. Returns limit if there is no such character.
[中]返回输入中作为分隔符的第一个字符的索引。如果没有这样的字符,则返回limit。
代码示例来源:origin: square/okhttp
/**
* Returns the username, or an empty string if none is set.
*
*
* URL {@code encodedUsername()}
* {@code http://host/} {@code ""}
* {@code http://username@host/} {@code "username"}
* {@code http://username:password@host/} {@code "username"}
* {@code http://a%20b:c%20d@host/} {@code "a%20b"}
*
*/
public String encodedUsername() {
if (username.isEmpty()) return "";
int usernameStart = scheme.length() + 3; // "://".length() == 3.
int usernameEnd = delimiterOffset(url, usernameStart, url.length(), ":@");
return url.substring(usernameStart, usernameEnd);
}
代码示例来源:origin: square/okhttp
/**
* Returns the entire path of this URL encoded for use in HTTP resource resolution. The returned
* path will start with {@code "/"}.
*
*
* URL {@code encodedPath()}
* {@code http://host/} {@code "/"}
* {@code http://host/a/b/c} {@code "/a/b/c"}
* {@code http://host/a/b%20c/d} {@code "/a/b%20c/d"}
*
*/
public String encodedPath() {
int pathStart = url.indexOf('/', scheme.length() + 3); // "://".length() == 3.
int pathEnd = delimiterOffset(url, pathStart, url.length(), "?#");
return url.substring(pathStart, pathEnd);
}
代码示例来源:origin: square/okhttp
private Builder addPathSegments(String pathSegments, boolean alreadyEncoded) {
int offset = 0;
do {
int segmentEnd = delimiterOffset(pathSegments, offset, pathSegments.length(), "/\\");
boolean addTrailingSlash = segmentEnd
offset = segmentEnd + 1;
} while (offset <= pathSegments.length());
return this;
}
代码示例来源:origin: square/okhttp
/**
* Returns a list of encoded path segments like {@code ["a", "b", "c"]} for the URL {@code
* http://host/a/b/c}. This list is never empty though it may contain a single empty string.
*
*
* URL {@code encodedPathSegments()}
* {@code http://host/} {@code [""]}
* {@code http://host/a/b/c} {@code ["a", "b", "c"]}
* {@code http://host/a/b%20c/d} {@code ["a", "b%20c", "d"]}
*
*/
public List
int pathStart = url.indexOf('/', scheme.length() + 3);
int pathEnd = delimiterOffset(url, pathStart, url.length(), "?#");
List
for (int i = pathStart; i
int segmentEnd = delimiterOffset(url, i, pathEnd, '/');
result.add(url.substring(i, segmentEnd));
i = segmentEnd;
}
return result;
}
代码示例来源:origin: square/okhttp
/**
* Returns the query of this URL, encoded for use in HTTP resource resolution. The returned string
* may be null (for URLs with no query), empty (for URLs with an empty query) or non-empty (all
* other URLs).
*
*
* URL {@code encodedQuery()}
* {@code http://host/} null
* {@code http://host/?} {@code ""}
* {@code http://host/?a=apple&k=key+lime} {@code
* "a=apple&k=key+lime"}
* {@code http://host/?a=apple&a=apricot} {@code "a=apple&a=apricot"}
* {@code http://host/?a=apple&b} {@code "a=apple&b"}
*
*/
public @Nullable String encodedQuery() {
if (queryNamesAndValues == null) return null; // No query.
int queryStart = url.indexOf('?') + 1;
int queryEnd = delimiterOffset(url, queryStart, url.length(), '#');
return url.substring(queryStart, queryEnd);
}
代码示例来源:origin: square/okhttp
private void resolvePath(String input, int pos, int limit) {
// Read a delimiter.
if (pos == limit) {
// Empty path: keep the base path as-is.
return;
}
char c = input.charAt(pos);
if (c == '/' || c == '\\') {
// Absolute path: reset to the default "/".
encodedPathSegments.clear();
encodedPathSegments.add("");
pos++;
} else {
// Relative path: clear everything after the last '/'.
encodedPathSegments.set(encodedPathSegments.size() - 1, "");
}
// Read path segments.
for (int i = pos; i
boolean segmentHasTrailingSlash = pathSegmentDelimiterOffset
i = pathSegmentDelimiterOffset;
if (segmentHasTrailingSlash) i++;
}
}
代码示例来源:origin: com.squareup.okhttp3/okhttp
/**
* Returns the entire path of this URL encoded for use in HTTP resource resolution. The returned
* path will start with {@code "/"}.
*
*
* URL {@code encodedPath()}
* {@code http://host/} {@code "/"}
* {@code http://host/a/b/c} {@code "/a/b/c"}
* {@code http://host/a/b%20c/d} {@code "/a/b%20c/d"}
*
*/
public String encodedPath() {
int pathStart = url.indexOf('/', scheme.length() + 3); // "://".length() == 3.
int pathEnd = delimiterOffset(url, pathStart, url.length(), "?#");
return url.substring(pathStart, pathEnd);
}
代码示例来源:origin: com.squareup.okhttp3/okhttp
/**
* Returns the username, or an empty string if none is set.
*
*
* URL {@code encodedUsername()}
* {@code http://host/} {@code ""}
* {@code http://username@host/} {@code "username"}
* {@code http://username:password@host/} {@code "username"}
* {@code http://a%20b:c%20d@host/} {@code "a%20b"}
*
*/
public String encodedUsername() {
if (username.isEmpty()) return "";
int usernameStart = scheme.length() + 3; // "://".length() == 3.
int usernameEnd = delimiterOffset(url, usernameStart, url.length(), ":@");
return url.substring(usernameStart, usernameEnd);
}
代码示例来源:origin: com.squareup.okhttp3/okhttp
private Builder addPathSegments(String pathSegments, boolean alreadyEncoded) {
int offset = 0;
do {
int segmentEnd = delimiterOffset(pathSegments, offset, pathSegments.length(), "/\\");
boolean addTrailingSlash = segmentEnd
offset = segmentEnd + 1;
} while (offset <= pathSegments.length());
return this;
}
代码示例来源:origin: com.squareup.okhttp3/okhttp
/**
* Returns the query of this URL, encoded for use in HTTP resource resolution. The returned string
* may be null (for URLs with no query), empty (for URLs with an empty query) or non-empty (all
* other URLs).
*
*
* URL {@code encodedQuery()}
* {@code http://host/} null
* {@code http://host/?} {@code ""}
* {@code http://host/?a=apple&k=key+lime} {@code
* "a=apple&k=key+lime"}
* {@code http://host/?a=apple&a=apricot} {@code "a=apple&a=apricot"}
* {@code http://host/?a=apple&b} {@code "a=apple&b"}
*
*/
public @Nullable String encodedQuery() {
if (queryNamesAndValues == null) return null; // No query.
int queryStart = url.indexOf('?') + 1;
int queryEnd = delimiterOffset(url, queryStart, url.length(), '#');
return url.substring(queryStart, queryEnd);
}
代码示例来源:origin: com.squareup.okhttp3/okhttp
/**
* Returns a list of encoded path segments like {@code ["a", "b", "c"]} for the URL {@code
* http://host/a/b/c}. This list is never empty though it may contain a single empty string.
*
*
* URL {@code encodedPathSegments()}
* {@code http://host/} {@code [""]}
* {@code http://host/a/b/c} {@code ["a", "b", "c"]}
* {@code http://host/a/b%20c/d} {@code ["a", "b%20c", "d"]}
*
*/
public List
int pathStart = url.indexOf('/', scheme.length() + 3);
int pathEnd = delimiterOffset(url, pathStart, url.length(), "?#");
List
for (int i = pathStart; i
int segmentEnd = delimiterOffset(url, i, pathEnd, '/');
result.add(url.substring(i, segmentEnd));
i = segmentEnd;
}
return result;
}
代码示例来源:origin: square/okhttp
List
for (int pos = 0, limit = header.length(), pairEnd; pos
int equalsSign = delimiterOffset(header, pos, pairEnd, '=');
String name = trimSubstring(header, pos, equalsSign);
if (name.startsWith("$")) continue;
代码示例来源:origin: com.squareup.okhttp3/okhttp
private void resolvePath(String input, int pos, int limit) {
// Read a delimiter.
if (pos == limit) {
// Empty path: keep the base path as-is.
return;
}
char c = input.charAt(pos);
if (c == '/' || c == '\\') {
// Absolute path: reset to the default "/".
encodedPathSegments.clear();
encodedPathSegments.add("");
pos++;
} else {
// Relative path: clear everything after the last '/'.
encodedPathSegments.set(encodedPathSegments.size() - 1, "");
}
// Read path segments.
for (int i = pos; i
boolean segmentHasTrailingSlash = pathSegmentDelimiterOffset
i = pathSegmentDelimiterOffset;
if (segmentHasTrailingSlash) i++;
}
}
代码示例来源:origin: square/okhttp
代码示例来源:origin: square/okhttp 代码示例来源:origin: com.squareup.okhttp3/okhttp 代码示例来源:origin: com.squareup.okhttp3/okhttp 代码示例来源:origin: duzechao/OKHttpUtils 代码示例来源:origin: duzechao/OKHttpUtils 代码示例来源:origin: duzechao/OKHttpUtilsstatic @Nullable COOKIE parse(long currentTimeMillis, HttpUrl url, String setCOOKIE) {
int pos = 0;
int limit = setCOOKIE.length();
int COOKIEPairEnd = delimiterOffset(setCOOKIE, pos, limit, ';');
int pairEqualsSign = delimiterOffset(setCOOKIE, pos, COOKIEPairEnd, '=');
if (pairEqualsSign == COOKIEPairEnd) return null;
int attributePairEnd = delimiterOffset(setCOOKIE, pos, limit, ';');
int attributeEqualsSign = delimiterOffset(setCOOKIE, pos, attributePairEnd, '=');
String attributeName = trimSubstring(setCOOKIE, pos, attributeEqualsSign);
String attributeValue = attributeEqualsSign authority:
while (true) {
int compOnentDelimiterOffset= delimiterOffset(input, pos, limit, "@/\\?#");
int c = componentDelimiterOffset != limit
? input.charAt(componentDelimiterOffset)
int passwordColOnOffset= delimiterOffset(
input, pos, componentDelimiterOffset, ':');
String canOnicalUsername= canonicalize(input, pos, passwordColonOffset,
int pathDelimiterOffset = delimiterOffset(input, pos, limit, "?#");
resolvePath(input, pos, pathDelimiterOffset);
pos = pathDelimiterOffset;
int queryDelimiterOffset = delimiterOffset(input, pos, limit, '#');
this.encodedQueryNamesAndValues = queryStringToNamesAndValues(canonicalize(
input, pos + 1, queryDelimiterOffset, QUERY_ENCODE_SET, true, false, true, true, null));static @Nullable COOKIE parse(long currentTimeMillis, HttpUrl url, String setCOOKIE) {
int pos = 0;
int limit = setCOOKIE.length();
int COOKIEPairEnd = delimiterOffset(setCOOKIE, pos, limit, ';');
int pairEqualsSign = delimiterOffset(setCOOKIE, pos, COOKIEPairEnd, '=');
if (pairEqualsSign == COOKIEPairEnd) return null;
int attributePairEnd = delimiterOffset(setCOOKIE, pos, limit, ';');
int attributeEqualsSign = delimiterOffset(setCOOKIE, pos, attributePairEnd, '=');
String attributeName = trimSubstring(setCOOKIE, pos, attributeEqualsSign);
String attributeValue = attributeEqualsSign authority:
while (true) {
int compOnentDelimiterOffset= delimiterOffset(input, pos, limit, "@/\\?#");
int c = componentDelimiterOffset != limit
? input.charAt(componentDelimiterOffset)
int passwordColOnOffset= delimiterOffset(
input, pos, componentDelimiterOffset, ':');
String canOnicalUsername= canonicalize(input, pos, passwordColonOffset,
int pathDelimiterOffset = delimiterOffset(input, pos, limit, "?#");
resolvePath(input, pos, pathDelimiterOffset);
pos = pathDelimiterOffset;
int queryDelimiterOffset = delimiterOffset(input, pos, limit, '#');
this.encodedQueryNamesAndValues = queryStringToNamesAndValues(canonicalize(
input, pos + 1, queryDelimiterOffset, QUERY_ENCODE_SET, true, false, true, true, null));public List
int pathStart = url.indexOf('/', scheme.length() + 3);
int pathEnd = delimiterOffset(url, pathStart, url.length(), "?#");
List
for (int i = pathStart; i
int segmentEnd = delimiterOffset(url, i, pathEnd, '/');
result.add(url.substring(i, segmentEnd));
i = segmentEnd;
}
return result;
}/**
* Returns the query of this URL, encoded for use in HTTP resource resolution. The returned string
* may be null (for URLs with no query), empty (for URLs with an empty query) or non-empty (all
* other URLs).
*/
public String encodedQuery() {
if (queryNamesAndValues == null) return null; // No query.
int queryStart = url.indexOf('?') + 1;
int queryEnd = delimiterOffset(url, queryStart + 1, url.length(), '#');
return url.substring(queryStart, queryEnd);
}/** Returns the username, or an empty string if none is set. */
public String encodedUsername() {
if (username.isEmpty()) return "";
int usernameStart = scheme.length() + 3; // "://".length() == 3.
int usernameEnd = delimiterOffset(url, usernameStart, url.length(), ":@");
return url.substring(usernameStart, usernameEnd);
}