當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。