本文整理汇总了Java中java.text.StringCharacterIterator类的典型用法代码示例。如果您正苦于以下问题:Java StringCharacterIterator类的具体用法?Java StringCharacterIterator怎么用?Java StringCharacterIterator使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
StringCharacterIterator类属于java.text包,在下文中一共展示了StringCharacterIterator类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: escapeWindowsJvmOpt
import java.text.StringCharacterIterator; //导入依赖的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: valid
import java.text.StringCharacterIterator; //导入依赖的package包/类
private boolean valid(String input) {
if ("".equals(input)) return true;
boolean ret = true;
it = new StringCharacterIterator(input);
c = it.first();
col = 1;
if (!value()) {
ret = error("value", 1);
} else {
skipWhiteSpace();
if (c != CharacterIterator.DONE) {
ret = error("end", col);
}
}
return ret;
}
示例3: literal
import java.text.StringCharacterIterator; //导入依赖的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: string
import java.text.StringCharacterIterator; //导入依赖的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('"');
}
示例5: valid
import java.text.StringCharacterIterator; //导入依赖的package包/类
private boolean valid(String input) {
if ("".equals(input)) return true;
boolean ret = true;
it = new StringCharacterIterator(input);
c = it.first();
col = 1;
if (!value()) {
ret = error("value", 1);
} else {
skipWhiteSpace();
if (c != CharacterIterator.DONE) {
ret = error("end", col);
}
}
return ret;
}
示例6: literal
import java.text.StringCharacterIterator; //导入依赖的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;
}
示例7: getFlagIdCodeSequence
import java.text.StringCharacterIterator; //导入依赖的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;
}
示例8: escapeForHTML
import java.text.StringCharacterIterator; //导入依赖的package包/类
public static String escapeForHTML(String s, char c) {
if (s == null || s.isEmpty()) {
return s;
}
StringBuilder b = new StringBuilder();
StringCharacterIterator it = new StringCharacterIterator(s);
char ch = it.current();
while (ch != CharacterIterator.DONE) {
if (ch == '<') {
b.append("<");
} else if (ch == '>') {
b.append(">");
} else if (ch == '&') {
b.append("&");
} else if (ch == '\"') {
b.append(""");
} else {
b.append(ch);
}
ch = it.next();
}
return b.toString();
}
示例9: TestBug4153072
import java.text.StringCharacterIterator; //导入依赖的package包/类
public void TestBug4153072() {
BreakIterator iter = BreakIterator.getWordInstance();
String str = "...Hello, World!...";
int begin = 3;
int end = str.length() - 3;
boolean gotException = false;
boolean dummy;
iter.setText(new StringCharacterIterator(str, begin, end, begin));
for (int index = -1; index < begin + 1; ++index) {
try {
dummy = iter.isBoundary(index);
if (index < begin)
errln("Didn't get exception with offset = " + index +
" and begin index = " + begin);
}
catch (IllegalArgumentException e) {
if (index >= begin)
errln("Got exception with offset = " + index +
" and begin index = " + begin);
}
}
}
示例10: uncolour
import java.text.StringCharacterIterator; //导入依赖的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();
}
示例11: valid
import java.text.StringCharacterIterator; //导入依赖的package包/类
private boolean valid(String input) {
if ("".equals(input)) return true;
boolean ret = true;
it = new StringCharacterIterator(input);
c = it.first();
col = 1;
if (!value()) {
ret = error("value", 1);
} else {
skipWhiteSpace();
if (c != CharacterIterator.DONE) {
ret = error("end", col);
}
}
return ret;
}
示例12: literal
import java.text.StringCharacterIterator; //导入依赖的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;
}
示例13: addSlashes
import java.text.StringCharacterIterator; //导入依赖的package包/类
/**
* addslashes() 函数在指定的预定义字符前添加反斜杠。 做转义处理后,写入数据库就不会因敏感字符('之类)导致sql有问题。
* 此处的转义处理内容是:在字符串中的单引号、双引号、反斜杠之前,都附加上反斜杠
*/
public static String addSlashes(String text) {
if (text == null || text.equals("")) {
return "";
}
StringBuffer sb = new StringBuffer(text.length() * 2);
StringCharacterIterator iterator = new StringCharacterIterator(text);
char character = iterator.current();
while (character != StringCharacterIterator.DONE) {
// DONE,字符型,当迭代器已到达文本末尾或开始处时返回的常量。
switch (character) {
case '\'': /* 单引号 */
case '"': /* 双引号 */
case '\\': /* 单斜杠 */
sb.append("\\"); /* 单斜杠 */
default:
sb.append(character);
break;
}
character = iterator.next();
}
return sb.toString();
}
示例14: reverse
import java.text.StringCharacterIterator; //导入依赖的package包/类
/**
* Returns a string that contains all characters of the given string in
* reverse order.
*/
public String reverse( String str )
{
if ( str == null )
return null ;
char[] newStr = new char[str.length()] ;
StringCharacterIterator iterator = new StringCharacterIterator(str) ;
int i = 0 ;
for(char ch = iterator.last(); ch != CharacterIterator.DONE; ch = iterator.previous())
{
newStr[i] = ch ;
i++ ;
}
return new String( newStr ) ;
}
示例15: StringTokenizer
import java.text.StringCharacterIterator; //导入依赖的package包/类
StringTokenizer(String value, char delim) {
string = value;
// Loop on the characters counting the separators and remembering
// their positions
StringCharacterIterator sci = new StringCharacterIterator(string);
char c = sci.first();
while (c != CharacterIterator.DONE) {
if (c == delim) {
// Remember its position
separatorPosition[tokens] = sci.getIndex();
tokens++;
// Resize the position array if needed
if (tokens >= separatorPosition.length) {
int[] copy = new int[separatorPosition.length * 10];
System.arraycopy(separatorPosition, 0, copy, 0, separatorPosition.length);
separatorPosition = copy;
}
}
c = sci.next();
}
// Add one token: tokens = separatorCount + 1
tokens++;
}