当前位置: 首页>>代码示例>>Java>>正文


Java StringCharacterIterator类代码示例

本文整理汇总了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();
}
 
开发者ID:lxxlxx888,项目名称:Reer,代码行数:26,代码来源:StartScriptTemplateBindingFactory.java

示例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;
}
 
开发者ID:funtl,项目名称:framework,代码行数:19,代码来源:JSONValidator.java

示例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;
}
 
开发者ID:funtl,项目名称:framework,代码行数:19,代码来源:JSONValidator.java

示例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('"');
}
 
开发者ID:arccode,项目名称:wechat-pay-sdk,代码行数:21,代码来源:JSONWriter.java

示例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;
}
 
开发者ID:arccode,项目名称:wechat-pay-sdk,代码行数:19,代码来源:JSONValidator.java

示例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;
}
 
开发者ID:arccode,项目名称:wechat-pay-sdk,代码行数:19,代码来源:JSONValidator.java

示例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;
}
 
开发者ID:kreativekorp,项目名称:vexillo,代码行数:20,代码来源:SFDExporter.java

示例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("&lt;");
    } else if (ch == '>') {
      b.append("&gt;");
    } else if (ch == '&') {
      b.append("&amp;");
    } else if (ch == '\"') {
      b.append("&quot;");
    } else {
      b.append(ch);
    }
    ch = it.next();
  }
  return b.toString();
}
 
开发者ID:logistimo,项目名称:logistimo-web-service,代码行数:24,代码来源:StringUtil.java

示例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);
        }
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:24,代码来源:BreakIteratorTest.java

示例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();
}
 
开发者ID:ImABradley,项目名称:Peach,代码行数:30,代码来源:MessageUtil.java

示例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;
}
 
开发者ID:wendal,项目名称:alipay-sdk,代码行数:19,代码来源:JSONValidator.java

示例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;
}
 
开发者ID:wendal,项目名称:alipay-sdk,代码行数:19,代码来源:JSONValidator.java

示例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();
}
 
开发者ID:shizicheng,项目名称:spring_mvc_template,代码行数:27,代码来源:Common.java

示例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 ) ;	
}
 
开发者ID:thangbn,项目名称:Direct-File-Downloader,代码行数:21,代码来源:StringUtil.java

示例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++;
}
 
开发者ID:BGI-flexlab,项目名称:SOAPgaea,代码行数:25,代码来源:Gpr.java


注:本文中的java.text.StringCharacterIterator类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。