本文整理匯總了Java中com.google.common.base.CharMatcher.matches方法的典型用法代碼示例。如果您正苦於以下問題:Java CharMatcher.matches方法的具體用法?Java CharMatcher.matches怎麽用?Java CharMatcher.matches使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.google.common.base.CharMatcher
的用法示例。
在下文中一共展示了CharMatcher.matches方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: ignoringReader
import com.google.common.base.CharMatcher; //導入方法依賴的package包/類
@GwtIncompatible // Reader
static Reader ignoringReader(final Reader delegate, final CharMatcher toIgnore) {
checkNotNull(delegate);
checkNotNull(toIgnore);
return new Reader() {
@Override
public int read() throws IOException {
int readChar;
do {
readChar = delegate.read();
} while (readChar != -1 && toIgnore.matches((char) readChar));
return readChar;
}
@Override
public int read(char[] cbuf, int off, int len) throws IOException {
throw new UnsupportedOperationException();
}
@Override
public void close() throws IOException {
delegate.close();
}
};
}
示例2: ignoringReader
import com.google.common.base.CharMatcher; //導入方法依賴的package包/類
@GwtIncompatible // Reader
static Reader ignoringReader(
final Reader delegate, final CharMatcher toIgnore) {
checkNotNull(delegate);
checkNotNull(toIgnore);
return new Reader() {
@Override
public int read() throws IOException {
int readChar;
do {
readChar = delegate.read();
} while (readChar != -1 && toIgnore.matches((char) readChar));
return readChar;
}
@Override
public int read(char[] cbuf, int off, int len) throws IOException {
throw new UnsupportedOperationException();
}
@Override
public void close() throws IOException {
delegate.close();
}
};
}
示例3: isGoodWord
import com.google.common.base.CharMatcher; //導入方法依賴的package包/類
/**
*
* A good word should start from the letter: it may contain a letter,
* a dash, or an apostrophe.
*
* @param text input
* @param isStrict if true, use a stricter definition of a good term.
* @return true if a good word.
*/
private boolean isGoodWord(String text, boolean isStrict) {
if (text.isEmpty()) return false;
CharMatcher m = isStrict ? CharMatcher.JAVA_LETTER :
CharMatcher.JAVA_LETTER_OR_DIGIT;
if (!m.matches(text.charAt(0))) return false;
for (int i = 0; i < text.length(); ++i) {
char c = text.charAt(i);
if (c != '-' && c != '\'' && !m.matches(c)) {
return false;
}
}
return true;
}
示例4: indexOfUnescapedChar
import com.google.common.base.CharMatcher; //導入方法依賴的package包/類
/**
* Returns the index of the next unescaped occurrence matching {@code ch} in {@code str} (after {@code fromIndex}). If no such match exists the method must
* return {@code str#length()}.
*
* @param str
* the string, must not be {@code null}
* @param ch
* character match, must not be {@code null}
* @param fromIndex
* index at which to start scanning for matches
* @return index of the next occurrence in the given string, or {@code str#length()} if none can be found
*/
protected int indexOfUnescapedChar(final String str, final CharMatcher ch, final int fromIndex) {
boolean escaped = false;
for (int index = fromIndex; index < str.length(); index++) {
if (escaped) {
escaped = false;
continue;
}
char c = str.charAt(index);
if (ch.matches(c)) {
return index;
} else if (c == ESCAPE_CHARACTER) {
escaped = true;
}
}
return str.length();
}
示例5: escape
import com.google.common.base.CharMatcher; //導入方法依賴的package包/類
/**
* Escapes the escape characters contained in the given text.
* <p>
* Reserved characters for e.g. segment and list separation cannot be used by custom fragment providers unless escaped, i.e. prefixed with a '\'. Such URI
* segments need to be escaped when forming the URI fragment, and consequently unescaped when reading the URI segments.
* </p>
*
* @param text
* the text to escape, must not be {@code null}
* @param charactersToEscape
* the characters to escape, must not be {@code null}
* @return the escaped text, never {@code null}
*/
protected String escape(final String text, final CharMatcher charactersToEscape) {
if (CharMatcher.NONE.equals(charactersToEscape)) {
return text;
}
final StringBuilder result = new StringBuilder(text.length());
int lastIndex = 0;
for (int index = 0; index < text.length(); index++) {
char character = text.charAt(index);
if (charactersToEscape.matches(character)) {
result.append(text.substring(lastIndex, index)).append(ESCAPE_CHARACTER).append(character);
lastIndex = index + 1;
}
}
if (result.length() == 0) {
return text;
}
result.append(text.substring(lastIndex));
return result.toString();
}
示例6: unescape
import com.google.common.base.CharMatcher; //導入方法依賴的package包/類
/**
* Unescapes the given escape characters contained in the given text.
* <p>
* Reserved characters for e.g. segment and list separation cannot be used by custom fragment providers unless escaped, i.e. prefixed with a '\'. Such URI
* segments need to be escaped when forming the URI fragment, and consequently unescaped when reading the URI segments.
* </p>
*
* @param text
* the text to unescape, must not be {@code null}
* @param charactersToEscape
* the characters to escape, must not be {@code null}
* @return the unescaped text, never {@code null}
*/
protected String unescape(final String text, final CharMatcher charactersToEscape) {
if (CharMatcher.NONE.equals(charactersToEscape)) {
return text;
}
final StringBuilder result = new StringBuilder(text.length());
int lastIndex = 0;
boolean escaped = false;
for (int index = 0; index < text.length(); index++) {
char character = text.charAt(index);
if (escaped) {
escaped = false;
if (charactersToEscape.matches(character)) {
result.append(text.substring(lastIndex, index - 1)).append(character);
lastIndex = index + 1;
}
} else if (character == ESCAPE_CHARACTER) {
escaped = true;
}
}
if (result.length() == 0) {
return text;
}
result.append(text.substring(lastIndex));
return result.toString();
}
示例7: whileMatches
import com.google.common.base.CharMatcher; //導入方法依賴的package包/類
private int whileMatches(int p, CharMatcher matcher) {
for (;; p++) {
if (!matcher.matches(get(p))) {
return p;
}
}
}