当前位置: 首页>>代码示例>>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;未经允许,请勿转载。