本文整理汇总了Java中java.text.CharacterIterator.first方法的典型用法代码示例。如果您正苦于以下问题:Java CharacterIterator.first方法的具体用法?Java CharacterIterator.first怎么用?Java CharacterIterator.first使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.text.CharacterIterator
的用法示例。
在下文中一共展示了CharacterIterator.first方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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();
}
示例2: 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;
}
示例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;
}
示例4: 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;
}
示例5: getFlagIdCodeSequence
import java.text.CharacterIterator; //导入方法依赖的package包/类
private static int[] getFlagIdCodeSequence(String id, int base) {
int[] buf = new int[id.length() + 2];
int pos = 0;
buf[pos++] = base;
CharacterIterator it = new StringCharacterIterator(id);
for (char ch = it.first(); ch != CharacterIterator.DONE; ch = it.next()) {
if ((ch >= '0' && ch <= '9') || (ch >= 'a' && ch <= 'z')) {
buf[pos++] = 0xE0000 + ch;
} else if (ch >= 'A' && ch <= 'Z') {
buf[pos++] = 0xE0020 + ch;
}
}
buf[pos++] = 0xE007F;
int[] codePoints = new int[pos];
for (int i = 0; i < pos; i++) {
codePoints[i] = buf[i];
}
return codePoints;
}
示例6: setText
import java.text.CharacterIterator; //导入方法依赖的package包/类
/**
* Calculate break positions eagerly parallel to reading text.
*/
public void setText(CharacterIterator ci) {
int begin = ci.getBeginIndex();
text = new char[ci.getEndIndex() - begin];
int[] breaks0 = new int[text.length + 1];
int brIx = 0;
breaks0[brIx++] = begin;
int charIx = 0;
boolean inWs = false;
for (char c = ci.first(); c != CharacterIterator.DONE; c = ci.next()) {
text[charIx] = c;
boolean ws = Character.isWhitespace(c);
if (inWs && !ws) {
breaks0[brIx++] = charIx + begin;
}
inWs = ws;
charIx++;
}
if (text.length > 0) {
breaks0[brIx++] = text.length + begin;
}
System.arraycopy(breaks0, 0, breaks = new int[brIx], 0, brIx);
}
示例7: 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);
}
示例8: uncolour
import java.text.CharacterIterator; //导入方法依赖的package包/类
/**
* Replaces all of the {@link MessageUtil#BUKKIT_COLOUR_CODE}'s with
* {@link MessageUtil#ALT_COLOUR_CODE}. This method is usually invoked
* when wanting to output a user-friendly string to a configuration file.
*
* @param s string to be uncoloured.
* @return uncoloured string.
*/
public static String uncolour(String s) {
if (s == null || s.isEmpty()) {
return null;
}
StringBuilder builder = new StringBuilder(s.length());
CharacterIterator it = new StringCharacterIterator(s);
for (char c = it.first(); c != CharacterIterator.DONE; c = it.next()) {
switch (c) {
case BUKKIT_COLOUR_CODE:
builder.append(ALT_COLOUR_CODE);
break;
default:
builder.append(c);
break;
}
}
return builder.toString();
}
示例9: 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;
}
示例10: string
import java.text.CharacterIterator; //导入方法依赖的package包/类
private void string(Object obj) {
add('"');
CharacterIterator it = new StringCharacterIterator(obj.toString());
for (char c = it.first(); c != CharacterIterator.DONE; c = it.next()) {
if (c == '"')
add("\\\"");
else if (c == '\\')
add("\\\\");
else if (c == '/')
add("\\/");
else if (c == '\b')
add("\\b");
else if (c == '\f')
add("\\f");
else if (c == '\n')
add("\\n");
else if (c == '\r')
add("\\r");
else if (c == '\t')
add("\\t");
else if (Character.isISOControl(c)) {
unicode(c);
} else {
add(c);
}
}
add('"');
}
示例11: first
import java.text.CharacterIterator; //导入方法依赖的package包/类
/**
* Sets the current iteration position to the beginning of the text.
* (i.e., the CharacterIterator's starting offset).
* @return The offset of the beginning of the text.
*/
@Override
public int first() {
CharacterIterator t = getText();
t.first();
return t.getIndex();
}
示例12: StandardGlyphVector
import java.text.CharacterIterator; //导入方法依赖的package包/类
public StandardGlyphVector(Font font, CharacterIterator iter, FontRenderContext frc) {
int offset = iter.getBeginIndex();
char[] text = new char [iter.getEndIndex() - offset];
for(char c = iter.first();
c != CharacterIterator.DONE;
c = iter.next()) {
text[iter.getIndex() - offset] = c;
}
init(font, text, 0, text.length, frc, UNINITIALIZED_FLAGS);
}
示例13: escapeText
import java.text.CharacterIterator; //导入方法依赖的package包/类
/**
* Implements JSON string escaping as specified <a href="http://www.ietf.org/rfc/rfc4627.txt">here</a>.
* <ul>
* <li>The following characters are escaped by prefixing them with a '\' : \b,\f,\n,\r,\t,\,"</li>
* <li>Other control characters in the range 0x0000-0x001F are escaped using the \\uXXXX notation</li>
* <li>UTF-16 surrogate pairs are encoded using the \\uXXXX\\uXXXX notation</li>
* <li>any other character is printed as-is</li>
* </ul>
*/
static String escapeText(String input) {
StringBuilder builder = new StringBuilder(input.length());
CharacterIterator iter = new StringCharacterIterator(input);
for(char c = iter.first(); c != CharacterIterator.DONE; c = iter.next()) {
switch(c) {
case '\b':
builder.append("\\b");
break;
case '\f':
builder.append("\\f");
break;
case '\n':
builder.append("\\n");
break;
case '\r':
builder.append("\\r");
break;
case '\t':
builder.append("\\t");
break;
case '\\':
builder.append("\\\\");
break;
case '"':
builder.append("\\\"");
break;
default:
// Check for other control characters
if(c >= 0x0000 && c <= 0x001F) {
appendEscapedUnicode(builder, c);
} else if(Character.isHighSurrogate(c)) {
// Encode the surrogate pair using 2 six-character sequence (\\uXXXX\\uXXXX)
appendEscapedUnicode(builder, c);
c = iter.next();
if(c == CharacterIterator.DONE) throw new IllegalArgumentException("invalid unicode string: unexpected high surrogate pair value without corresponding low value.");
appendEscapedUnicode(builder, c);
} else {
// Anything else can be printed as-is
builder.append(c);
}
break;
}
}
return builder.toString();
}
示例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());
}