當前位置: 首頁>>代碼示例>>Java>>正文


Java CharMatcher.matches方法代碼示例

本文整理匯總了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();
    }
  };
}
 
開發者ID:zugzug90,項目名稱:guava-mock,代碼行數:26,代碼來源:BaseEncoding.java

示例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();
    }
  };
}
 
開發者ID:antlr,項目名稱:codebuff,代碼行數:27,代碼來源:BaseEncoding.java

示例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;
}
 
開發者ID:oaqa,項目名稱:knn4qa,代碼行數:25,代碼來源:ExtractTextReps.java

示例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();
}
 
開發者ID:dsldevkit,項目名稱:dsl-devkit,代碼行數:29,代碼來源:AbstractFragmentProvider.java

示例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();
}
 
開發者ID:dsldevkit,項目名稱:dsl-devkit,代碼行數:33,代碼來源:AbstractFragmentProvider.java

示例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();
}
 
開發者ID:dsldevkit,項目名稱:dsl-devkit,代碼行數:39,代碼來源:AbstractFragmentProvider.java

示例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;
    }
  }
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:8,代碼來源:Code.java


注:本文中的com.google.common.base.CharMatcher.matches方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。