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


Java CharacterIterator.next方法代碼示例

本文整理匯總了Java中java.text.CharacterIterator.next方法的典型用法代碼示例。如果您正苦於以下問題:Java CharacterIterator.next方法的具體用法?Java CharacterIterator.next怎麽用?Java CharacterIterator.next使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.text.CharacterIterator的用法示例。


在下文中一共展示了CharacterIterator.next方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: escapeWindowsJvmOpt

import java.text.CharacterIterator; //導入方法依賴的package包/類
private String escapeWindowsJvmOpt(String jvmOpts) {
    boolean wasOnBackslash = false;
    StringBuilder escapedJvmOpt = new StringBuilder();
    CharacterIterator it = new StringCharacterIterator(jvmOpts);

    //argument quoting:
    // - " must be encoded as \"
    // - % must be encoded as %%
    // - pathological case: \" must be encoded as \\\", but other than that, \ MUST NOT be quoted
    // - other characters (including ') will not be quoted
    // - use a state machine rather than regexps
    for (char ch = it.first(); ch != CharacterIterator.DONE; ch = it.next()) {
        String repl = Character.toString(ch);

        if (ch == '%') {
            repl = "%%";
        } else if (ch == '"') {
            repl = (wasOnBackslash ? '\\' : "") + "\\\"";
        }
        wasOnBackslash = ch == '\\';
        escapedJvmOpt.append(repl);
    }

    return escapedJvmOpt.toString();
}
 
開發者ID:lxxlxx888,項目名稱:Reer,代碼行數:26,代碼來源:StartScriptTemplateBindingFactory.java

示例2: readHexValue

import java.text.CharacterIterator; //導入方法依賴的package包/類
public static int readHexValue(CharacterIterator i, int maxchars) {
    int accumul = 0;

    for (int cntr = 0; cntr < maxchars; cntr++) {
        final char c = i.current();

        if (c == CharacterIterator.DONE || !isHexDigit(c)) {
            break;
        }

        accumul = (accumul << 4) | hexValueOf(c);
        i.next();
    }

    return accumul;
}
 
開發者ID:arodchen,項目名稱:MaxSim,代碼行數:17,代碼來源:StringUtil.java

示例3: literal

import java.text.CharacterIterator; //導入方法依賴的package包/類
private boolean literal(String text) {
    CharacterIterator ci = new StringCharacterIterator(text);
    char t = ci.first();
    if (c != t) return false;
    
    int start = col;
    boolean ret = true;
    for (t = ci.next(); t != CharacterIterator.DONE; t = ci.next()) {
        if (t != nextCharacter()) {
            ret = false;
            break;
        }
    }
    nextCharacter();

    if (!ret) error("literal " + text, start);
    return ret;
}
 
開發者ID:1991wangliang,項目名稱:pay,代碼行數:19,代碼來源:JSONValidator.java

示例4: readDecimalString

import java.text.CharacterIterator; //導入方法依賴的package包/類
public static String readDecimalString(CharacterIterator i, int maxchars) {
    final StringBuffer buf = new StringBuffer();

    if (peekAndEat(i, '-')) {
        buf.append('-');
    }

    for (int cntr = 0; cntr < maxchars; cntr++) {
        final char c = i.current();

        if (!Character.isDigit(c)) {
            break;
        }

        buf.append(c);
        i.next();
    }

    return buf.toString();
}
 
開發者ID:arodchen,項目名稱:MaxSim,代碼行數:21,代碼來源:StringUtil.java

示例5: characterIteratorToString

import java.text.CharacterIterator; //導入方法依賴的package包/類
/**
 * Returns a string containing the characters from the given iterator.
 * 
 * @param iterator  the iterator (<code>null</code> not permitted).
 * 
 * @return A string.
 */
private String characterIteratorToString(CharacterIterator iterator) {
    int endIndex = iterator.getEndIndex();
    int beginIndex = iterator.getBeginIndex();
    int count = endIndex - beginIndex;
    if (count <= 0) {
        return "";
    }
    char[] chars = new char[count];
    int i = 0;
    char c = iterator.first();
    while (c != CharacterIterator.DONE) {
        chars[i] = c;
        i++;
        c = iterator.next();
    }
    return new String(chars);
}
 
開發者ID:parabuild-ci,項目名稱:parabuild-ci,代碼行數:25,代碼來源:LegendItem.java

示例6: current32

import java.text.CharacterIterator; //導入方法依賴的package包/類
public static int current32(CharacterIterator ci) {
    char  lead   = ci.current();
    int   retVal = lead;
    if (retVal < UTF16.LEAD_SURROGATE_MIN_VALUE) {
        return retVal;   
    }
    if (UTF16.isLeadSurrogate(lead)) {
        int  trail = (int)ci.next();
        ci.previous();
        if (UTF16.isTrailSurrogate((char)trail)) {
            retVal = ((lead  - UTF16.LEAD_SURROGATE_MIN_VALUE) << 10) +
                     (trail - UTF16.TRAIL_SURROGATE_MIN_VALUE) +
                     UTF16.SUPPLEMENTARY_MIN_VALUE;
        }
     } else {
        if (lead == CharacterIterator.DONE) {
            if (ci.getIndex() >= ci.getEndIndex())   {
                retVal = DONE32;   
            }
        }
     }
    return retVal;
}
 
開發者ID:abhijitvalluri,項目名稱:fitnotifications,代碼行數:24,代碼來源:CharacterIteration.java

示例7: literal

import java.text.CharacterIterator; //導入方法依賴的package包/類
private boolean literal(String text) {
    CharacterIterator ci = new StringCharacterIterator(text);
    char t = ci.first();
    if (c != t) return false;

    int start = col;
    boolean ret = true;
    for (t = ci.next(); t != CharacterIterator.DONE; t = ci.next()) {
        if (t != nextCharacter()) {
            ret = false;
            break;
        }
    }
    nextCharacter();

    if (!ret) error("literal " + text, start);
    return ret;
}
 
開發者ID:arccode,項目名稱:wechat-pay-sdk,代碼行數:19,代碼來源:JSONValidator.java

示例8: canDisplayUpTo

import java.text.CharacterIterator; //導入方法依賴的package包/類
/**
 * Indicates whether or not this {@code Font} can display the
 * text specified by the {@code iter} starting at
 * {@code start} and ending at {@code limit}.
 *
 * @param iter  a {@link CharacterIterator} object
 * @param start the specified starting offset into the specified
 *              {@code CharacterIterator}.
 * @param limit the specified ending offset into the specified
 *              {@code CharacterIterator}.
 * @return an offset into {@code iter} that points
 *          to the first character in {@code iter} that this
 *          {@code Font} cannot display; or {@code -1} if
 *          this {@code Font} can display all characters in
 *          {@code iter}.
 * @since 1.2
 */
public int canDisplayUpTo(CharacterIterator iter, int start, int limit) {
    Font2D font2d = getFont2D();
    char c = iter.setIndex(start);
    for (int i = start; i < limit; i++, c = iter.next()) {
        if (font2d.canDisplay(c)) {
            continue;
        }
        if (!Character.isHighSurrogate(c)) {
            return i;
        }
        char c2 = iter.next();
        // c2 could be CharacterIterator.DONE which is not a low surrogate.
        if (!Character.isLowSurrogate(c2)) {
            return i;
        }
        if (!font2d.canDisplay(Character.toCodePoint(c, c2))) {
            return i;
        }
        i++;
    }
    return -1;
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:40,代碼來源:Font.java

示例9: expectChar

import java.text.CharacterIterator; //導入方法依賴的package包/類
public static void expectChar(CharacterIterator i, char c) throws Exception {
    final char r = i.current();
    i.next();
    if (r != c) {
        throw new Error("parse error at " + i.getIndex() + ", expected character '" + c + "'");
    }
}
 
開發者ID:arodchen,項目名稱:MaxSim,代碼行數:8,代碼來源:StringUtil.java

示例10: readBinaryValue

import java.text.CharacterIterator; //導入方法依賴的package包/類
public static int readBinaryValue(CharacterIterator i, int maxchars) {
    int accumul = 0;

    if (maxchars >= 1) {
        final char ch = i.current();
        i.next();
        if (ch == '0') {
            accumul <<= 1;
        } else if (ch == '1') {
            accumul = (accumul << 1) | 1;
        }
    }

    return accumul;
}
 
開發者ID:arodchen,項目名稱:MaxSim,代碼行數:16,代碼來源:StringUtil.java

示例11: peekAndEat

import java.text.CharacterIterator; //導入方法依賴的package包/類
public static boolean peekAndEat(CharacterIterator i, String s) {
    final int ind = i.getIndex();
    for (int cntr = 0; cntr < s.length(); cntr++) {
        if (i.current() == s.charAt(cntr)) {
            i.next();
        } else {
            i.setIndex(ind);
            return false;
        }
    }
    return true;
}
 
開發者ID:beehive-lab,項目名稱:Maxine-VM,代碼行數:13,代碼來源:StringUtil.java

示例12: parse

import java.text.CharacterIterator; //導入方法依賴的package包/類
/**
 * Parse a serialized <strong>binary</strong> tree from the given CharacterIterator
 * @param input
 * @return
 * @throws InvalidParameterException
 */
private static BinaryTree parse(CharacterIterator input) throws InvalidParameterException {
	BinaryTree result = new BinaryTree();
	StringBuilder read = new StringBuilder();
	try{
		char c;
		String label = "";
		while((c=next(read, input)) != ' '){
			label += c;
		}
		
		// Take only the base label (e.g., NP-SBJ-1 into NP)
		int dashIndex = label.indexOf("-");
		if(dashIndex != -1){
			label = label.substring(0, dashIndex);
		}
		Label labelObj = Label.get(label);
		if((c=next(read, input)) == '('){ // Another tree
			result.left = parse(input);
			result.right = parse(input);
			labelObj.type = LabelType.NON_TERMINAL;
			result.value = new LabeledWord(labelObj, "");
		} else { // Word
			String word = ""+c;
			while((c=next(read, input)) != ')'){
				word += c;
			}
			labelObj.type = LabelType.TERMINAL;
			result.value = new LabeledWord(labelObj, word);
		}
		input.next();
	} catch (RuntimeException e){
		System.out.println(getReadTree(read, input));
		throw e;
	}
	return result;
}
 
開發者ID:justhalf,項目名稱:weak-semi-crf-naacl2016,代碼行數:43,代碼來源:BinaryTree.java

示例13: utf8Length

import java.text.CharacterIterator; //導入方法依賴的package包/類
/**
 * For the given string, returns the number of UTF-8 bytes
 * required to encode the string.
 * @param string text to encode
 * @return number of UTF-8 bytes required to encode
 */
public static int utf8Length(String string) {
  CharacterIterator iter = new StringCharacterIterator(string);
  char ch = iter.first();
  int size = 0;
  while (ch != CharacterIterator.DONE) {
    if ((ch >= 0xD800) && (ch < 0xDC00)) {
      // surrogate pair?
      char trail = iter.next();
      if ((trail > 0xDBFF) && (trail < 0xE000)) {
        // valid pair
        size += 4;
      } else {
        // invalid pair
        size += 3;
        iter.previous(); // rewind one
      }
    } else if (ch < 0x80) {
      size++;
    } else if (ch < 0x800) {
      size += 2;
    } else {
      // ch < 0x10000, that is, the largest char value
      size += 3;
    }
    ch = iter.next();
  }
  return size;
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:35,代碼來源:Text.java

示例14: highlight

import java.text.CharacterIterator; //導入方法依賴的package包/類
/**
 * Surround the <code>hits</code> in the provided <code>text</code> with an HTML tag. This is used with offsets
 * from the search API to support the highlighting of query terms.
 *
 * @param text of the Tweet to highlight
 * @param hits A List of highlighting offsets (themselves lists of two elements)
 * @return text with highlight HTML added
 */
public String highlight(String text, List<List<Integer>> hits) {
  if (hits == null || hits.isEmpty()) {
    return(text);
  }
  
  StringBuilder sb = new StringBuilder(text.length());
  CharacterIterator iterator = new StringCharacterIterator(text);
  boolean isCounting = true;
  boolean tagOpened = false;
  int currentIndex = 0;
  char currentChar = iterator.first();

  while (currentChar != CharacterIterator.DONE) {
    // TODO: this is slow.
    for (List<Integer> start_end : hits) {
      if (start_end.get(0) == currentIndex) {
        sb.append(tag(false));
        tagOpened = true;
      } else if (start_end.get(1) == currentIndex) {
        sb.append(tag(true));
        tagOpened = false;
      }
    }
    
    if (currentChar == '<') {
      isCounting = false;
    } else if (currentChar == '>' && !isCounting) {
      isCounting = true;
    }

    if (isCounting) {
      currentIndex++;
    }
    sb.append(currentChar);
    currentChar = iterator.next();
  }
  
  if (tagOpened) {
    sb.append(tag(true));
  }
  
  return(sb.toString());
}
 
開發者ID:xieyangxuejun,項目名稱:CommentView,代碼行數:52,代碼來源:HitHighlighter.java

示例15: highlight

import java.text.CharacterIterator; //導入方法依賴的package包/類
/**
 * Surround the <code>hits</code> in the provided <code>text</code> with an HTML tag. This is used with offsets
 * from the search API to support the highlighting of query terms.
 *
 * @param text of the Tweet to highlight
 * @param hits A List of highlighting offsets (themselves lists of two elements)
 * @return text with highlight HTML added
 */
public String highlight(String text, List<List<Integer>> hits) {
    if (hits == null || hits.isEmpty()) {
        return (text);
    }

    StringBuilder sb = new StringBuilder(text.length());
    CharacterIterator iterator = new StringCharacterIterator(text);
    boolean isCounting = true;
    boolean tagOpened = false;
    int currentIndex = 0;
    char currentChar = iterator.first();

    while (currentChar != CharacterIterator.DONE) {
        // TODO: this is slow.
        for (List<Integer> start_end : hits) {
            if (start_end.get(0) == currentIndex) {
                sb.append(tag(false));
                tagOpened = true;
            } else if (start_end.get(1) == currentIndex) {
                sb.append(tag(true));
                tagOpened = false;
            }
        }

        if (currentChar == '<') {
            isCounting = false;
        } else if (currentChar == '>' && !isCounting) {
            isCounting = true;
        }

        if (isCounting) {
            currentIndex++;
        }
        sb.append(currentChar);
        currentChar = iterator.next();
    }

    if (tagOpened) {
        sb.append(tag(true));
    }

    return (sb.toString());
}
 
開發者ID:xieyangxuejun,項目名稱:CommentView,代碼行數:52,代碼來源:HitHighlighter.java


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