java.lang.String#charAt ( )源码实例Demo

下面列出了java.lang.String#charAt ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: Android-utils   文件: NumberUtils.java
/**
 * <p>Utility method for {@link #createNumber(String)}.</p>
 *
 * <p>Returns <code>true</code> if s is <code>null</code>.</p>
 *
 * @param str  the String to check
 * @return if it is all zeros or <code>null</code>
 */
private static boolean isAllZeros(final String str) {
    if (str == null) {
        return true;
    }
    for (int i = str.length() - 1; i >= 0; i--) {
        if (str.charAt(i) != '0') {
            return false;
        }
    }
    return str.length() > 0;
}
 
源代码2 项目: TencentKona-8   文件: Messages.java
/**
 * This method was introduced to fix defect #26964.  For Java 1.0.2
 * on Win NT, the escape sequence \u0020 was not being handled
 * correctly by the Java Properties class when it was the final
 * character of a line.  Instead the trailing blank was dropped
 * and the next line was swallowed as a continuation.  To work
 * around the problem, we introduced our own metasymbol to represent
 * a trailing blank.  Hence:
 *
 * Performs substitution for any metasymbols in the message
 * templates.  So far only %B is needed.  This was introduced
 * to make it more convenient for .properties files to
 * contain message templates with leading or trailing blanks
 * (although %B may actually occur anywhere in a template).
 * Subsequently, checking for '\n' has also been added.  Now,
 * wherever '\n' occurs in a message template, it is replaced
 * with the value of System.getProperty ("line.separator").
 */
private static final void fixMessages (Properties p) {

    Enumeration keys = p.keys ();
    Enumeration elems = p.elements ();
    while (keys.hasMoreElements ()) {
        String key = (String) keys.nextElement ();
        String elem = (String) elems.nextElement ();
        int i = elem.indexOf (LTB);
        boolean changed = false;
        while (i != -1) {
            if (i == 0)
                elem = " " + elem.substring (2);
            else
                elem = elem.substring (0, i) + " " + elem.substring (i+2);
            changed = true;
            i = elem.indexOf (LTB);
        }
        int lsIncr = lineSeparator.length () - 1;
        for (i=0; i<elem.length (); i++) {
            if (elem.charAt (i) == NL) {
                elem = elem.substring (0, i) +
                    lineSeparator + elem.substring (i+1);
                i += lsIncr;
                changed = true;
            }
        }
        if (changed)
            p.put (key, elem);
    }

}
 
源代码3 项目: jdk8u60   文件: Messages.java
/**
 * This method was introduced to fix defect #26964.  For Java 1.0.2
 * on Win NT, the escape sequence \u0020 was not being handled
 * correctly by the Java Properties class when it was the final
 * character of a line.  Instead the trailing blank was dropped
 * and the next line was swallowed as a continuation.  To work
 * around the problem, we introduced our own metasymbol to represent
 * a trailing blank.  Hence:
 *
 * Performs substitution for any metasymbols in the message
 * templates.  So far only %B is needed.  This was introduced
 * to make it more convenient for .properties files to
 * contain message templates with leading or trailing blanks
 * (although %B may actually occur anywhere in a template).
 * Subsequently, checking for '\n' has also been added.  Now,
 * wherever '\n' occurs in a message template, it is replaced
 * with the value of System.getProperty ("line.separator").
 */
private static final void fixMessages (Properties p) {

    Enumeration keys = p.keys ();
    Enumeration elems = p.elements ();
    while (keys.hasMoreElements ()) {
        String key = (String) keys.nextElement ();
        String elem = (String) elems.nextElement ();
        int i = elem.indexOf (LTB);
        boolean changed = false;
        while (i != -1) {
            if (i == 0)
                elem = " " + elem.substring (2);
            else
                elem = elem.substring (0, i) + " " + elem.substring (i+2);
            changed = true;
            i = elem.indexOf (LTB);
        }
        int lsIncr = lineSeparator.length () - 1;
        for (i=0; i<elem.length (); i++) {
            if (elem.charAt (i) == NL) {
                elem = elem.substring (0, i) +
                    lineSeparator + elem.substring (i+1);
                i += lsIncr;
                changed = true;
            }
        }
        if (changed)
            p.put (key, elem);
    }

}
 
源代码4 项目: openjdk-jdk8u   文件: Messages.java
/**
 * This method was introduced to fix defect #26964.  For Java 1.0.2
 * on Win NT, the escape sequence \u0020 was not being handled
 * correctly by the Java Properties class when it was the final
 * character of a line.  Instead the trailing blank was dropped
 * and the next line was swallowed as a continuation.  To work
 * around the problem, we introduced our own metasymbol to represent
 * a trailing blank.  Hence:
 *
 * Performs substitution for any metasymbols in the message
 * templates.  So far only %B is needed.  This was introduced
 * to make it more convenient for .properties files to
 * contain message templates with leading or trailing blanks
 * (although %B may actually occur anywhere in a template).
 * Subsequently, checking for '\n' has also been added.  Now,
 * wherever '\n' occurs in a message template, it is replaced
 * with the value of System.getProperty ("line.separator").
 */
private static final void fixMessages (Properties p) {

    Enumeration keys = p.keys ();
    Enumeration elems = p.elements ();
    while (keys.hasMoreElements ()) {
        String key = (String) keys.nextElement ();
        String elem = (String) elems.nextElement ();
        int i = elem.indexOf (LTB);
        boolean changed = false;
        while (i != -1) {
            if (i == 0)
                elem = " " + elem.substring (2);
            else
                elem = elem.substring (0, i) + " " + elem.substring (i+2);
            changed = true;
            i = elem.indexOf (LTB);
        }
        int lsIncr = lineSeparator.length () - 1;
        for (i=0; i<elem.length (); i++) {
            if (elem.charAt (i) == NL) {
                elem = elem.substring (0, i) +
                    lineSeparator + elem.substring (i+1);
                i += lsIncr;
                changed = true;
            }
        }
        if (changed)
            p.put (key, elem);
    }

}
 
源代码5 项目: openjdk-jdk8u-backup   文件: Messages.java
/**
 * This method was introduced to fix defect #26964.  For Java 1.0.2
 * on Win NT, the escape sequence \u0020 was not being handled
 * correctly by the Java Properties class when it was the final
 * character of a line.  Instead the trailing blank was dropped
 * and the next line was swallowed as a continuation.  To work
 * around the problem, we introduced our own metasymbol to represent
 * a trailing blank.  Hence:
 *
 * Performs substitution for any metasymbols in the message
 * templates.  So far only %B is needed.  This was introduced
 * to make it more convenient for .properties files to
 * contain message templates with leading or trailing blanks
 * (although %B may actually occur anywhere in a template).
 * Subsequently, checking for '\n' has also been added.  Now,
 * wherever '\n' occurs in a message template, it is replaced
 * with the value of System.getProperty ("line.separator").
 */
private static final void fixMessages (Properties p) {

    Enumeration keys = p.keys ();
    Enumeration elems = p.elements ();
    while (keys.hasMoreElements ()) {
        String key = (String) keys.nextElement ();
        String elem = (String) elems.nextElement ();
        int i = elem.indexOf (LTB);
        boolean changed = false;
        while (i != -1) {
            if (i == 0)
                elem = " " + elem.substring (2);
            else
                elem = elem.substring (0, i) + " " + elem.substring (i+2);
            changed = true;
            i = elem.indexOf (LTB);
        }
        int lsIncr = lineSeparator.length () - 1;
        for (i=0; i<elem.length (); i++) {
            if (elem.charAt (i) == NL) {
                elem = elem.substring (0, i) +
                    lineSeparator + elem.substring (i+1);
                i += lsIncr;
                changed = true;
            }
        }
        if (changed)
            p.put (key, elem);
    }

}
 
源代码6 项目: openjdk-jdk9   文件: Messages.java
/**
 * This method was introduced to fix defect #26964.  For Java 1.0.2
 * on Win NT, the escape sequence \u0020 was not being handled
 * correctly by the Java Properties class when it was the final
 * character of a line.  Instead the trailing blank was dropped
 * and the next line was swallowed as a continuation.  To work
 * around the problem, we introduced our own metasymbol to represent
 * a trailing blank.  Hence:
 *
 * Performs substitution for any metasymbols in the message
 * templates.  So far only %B is needed.  This was introduced
 * to make it more convenient for .properties files to
 * contain message templates with leading or trailing blanks
 * (although %B may actually occur anywhere in a template).
 * Subsequently, checking for '\n' has also been added.  Now,
 * wherever '\n' occurs in a message template, it is replaced
 * with the value of System.getProperty ("line.separator").
 */
private static final void fixMessages (Properties p) {

    Enumeration keys = p.keys ();
    Enumeration elems = p.elements ();
    while (keys.hasMoreElements ()) {
        String key = (String) keys.nextElement ();
        String elem = (String) elems.nextElement ();
        int i = elem.indexOf (LTB);
        boolean changed = false;
        while (i != -1) {
            if (i == 0)
                elem = " " + elem.substring (2);
            else
                elem = elem.substring (0, i) + " " + elem.substring (i+2);
            changed = true;
            i = elem.indexOf (LTB);
        }
        int lsIncr = lineSeparator.length () - 1;
        for (i=0; i<elem.length (); i++) {
            if (elem.charAt (i) == NL) {
                elem = elem.substring (0, i) +
                    lineSeparator + elem.substring (i+1);
                i += lsIncr;
                changed = true;
            }
        }
        if (changed)
            p.put (key, elem);
    }

}
 
源代码7 项目: hottub   文件: Messages.java
/**
 * This method was introduced to fix defect #26964.  For Java 1.0.2
 * on Win NT, the escape sequence \u0020 was not being handled
 * correctly by the Java Properties class when it was the final
 * character of a line.  Instead the trailing blank was dropped
 * and the next line was swallowed as a continuation.  To work
 * around the problem, we introduced our own metasymbol to represent
 * a trailing blank.  Hence:
 *
 * Performs substitution for any metasymbols in the message
 * templates.  So far only %B is needed.  This was introduced
 * to make it more convenient for .properties files to
 * contain message templates with leading or trailing blanks
 * (although %B may actually occur anywhere in a template).
 * Subsequently, checking for '\n' has also been added.  Now,
 * wherever '\n' occurs in a message template, it is replaced
 * with the value of System.getProperty ("line.separator").
 */
private static final void fixMessages (Properties p) {

    Enumeration keys = p.keys ();
    Enumeration elems = p.elements ();
    while (keys.hasMoreElements ()) {
        String key = (String) keys.nextElement ();
        String elem = (String) elems.nextElement ();
        int i = elem.indexOf (LTB);
        boolean changed = false;
        while (i != -1) {
            if (i == 0)
                elem = " " + elem.substring (2);
            else
                elem = elem.substring (0, i) + " " + elem.substring (i+2);
            changed = true;
            i = elem.indexOf (LTB);
        }
        int lsIncr = lineSeparator.length () - 1;
        for (i=0; i<elem.length (); i++) {
            if (elem.charAt (i) == NL) {
                elem = elem.substring (0, i) +
                    lineSeparator + elem.substring (i+1);
                i += lsIncr;
                changed = true;
            }
        }
        if (changed)
            p.put (key, elem);
    }

}
 
源代码8 项目: openjdk-8-source   文件: Messages.java
/**
 * This method was introduced to fix defect #26964.  For Java 1.0.2
 * on Win NT, the escape sequence \u0020 was not being handled
 * correctly by the Java Properties class when it was the final
 * character of a line.  Instead the trailing blank was dropped
 * and the next line was swallowed as a continuation.  To work
 * around the problem, we introduced our own metasymbol to represent
 * a trailing blank.  Hence:
 *
 * Performs substitution for any metasymbols in the message
 * templates.  So far only %B is needed.  This was introduced
 * to make it more convenient for .properties files to
 * contain message templates with leading or trailing blanks
 * (although %B may actually occur anywhere in a template).
 * Subsequently, checking for '\n' has also been added.  Now,
 * wherever '\n' occurs in a message template, it is replaced
 * with the value of System.getProperty ("line.separator").
 */
private static final void fixMessages (Properties p) {

    Enumeration keys = p.keys ();
    Enumeration elems = p.elements ();
    while (keys.hasMoreElements ()) {
        String key = (String) keys.nextElement ();
        String elem = (String) elems.nextElement ();
        int i = elem.indexOf (LTB);
        boolean changed = false;
        while (i != -1) {
            if (i == 0)
                elem = " " + elem.substring (2);
            else
                elem = elem.substring (0, i) + " " + elem.substring (i+2);
            changed = true;
            i = elem.indexOf (LTB);
        }
        int lsIncr = lineSeparator.length () - 1;
        for (i=0; i<elem.length (); i++) {
            if (elem.charAt (i) == NL) {
                elem = elem.substring (0, i) +
                    lineSeparator + elem.substring (i+1);
                i += lsIncr;
                changed = true;
            }
        }
        if (changed)
            p.put (key, elem);
    }

}
 
源代码9 项目: openjdk-8   文件: Messages.java
/**
 * This method was introduced to fix defect #26964.  For Java 1.0.2
 * on Win NT, the escape sequence \u0020 was not being handled
 * correctly by the Java Properties class when it was the final
 * character of a line.  Instead the trailing blank was dropped
 * and the next line was swallowed as a continuation.  To work
 * around the problem, we introduced our own metasymbol to represent
 * a trailing blank.  Hence:
 *
 * Performs substitution for any metasymbols in the message
 * templates.  So far only %B is needed.  This was introduced
 * to make it more convenient for .properties files to
 * contain message templates with leading or trailing blanks
 * (although %B may actually occur anywhere in a template).
 * Subsequently, checking for '\n' has also been added.  Now,
 * wherever '\n' occurs in a message template, it is replaced
 * with the value of System.getProperty ("line.separator").
 */
private static final void fixMessages (Properties p) {

    Enumeration keys = p.keys ();
    Enumeration elems = p.elements ();
    while (keys.hasMoreElements ()) {
        String key = (String) keys.nextElement ();
        String elem = (String) elems.nextElement ();
        int i = elem.indexOf (LTB);
        boolean changed = false;
        while (i != -1) {
            if (i == 0)
                elem = " " + elem.substring (2);
            else
                elem = elem.substring (0, i) + " " + elem.substring (i+2);
            changed = true;
            i = elem.indexOf (LTB);
        }
        int lsIncr = lineSeparator.length () - 1;
        for (i=0; i<elem.length (); i++) {
            if (elem.charAt (i) == NL) {
                elem = elem.substring (0, i) +
                    lineSeparator + elem.substring (i+1);
                i += lsIncr;
                changed = true;
            }
        }
        if (changed)
            p.put (key, elem);
    }

}
 
源代码10 项目: clear-todolist   文件: SQLiteUtils.java
public static List<String> lexSqlScript(String sqlScript) {
	ArrayList<String> sl = new ArrayList<String>();
	boolean inString = false, quoteNext = false;
	StringBuilder b = new StringBuilder(100);

	for (int i = 0; i < sqlScript.length(); i++) {
		char c = sqlScript.charAt(i);

		if (c == ';' && !inString && !quoteNext) {
			sl.add(b.toString());
			b = new StringBuilder(100);
			inString = false;
			quoteNext = false;
			continue;
		}

		if (c == '\'' && !quoteNext) {
			inString = !inString;
		}

		quoteNext = c == '\\' && !quoteNext;

		b.append(c);
	}

	if (b.length() > 0) {
		sl.add(b.toString());
	}

	return sl;
}
 
源代码11 项目: mobile-android-survey-app   文件: SQLiteUtils.java
public static List<String> lexSqlScript(String sqlScript) {
	ArrayList<String> sl = new ArrayList<String>();
	boolean inString = false, quoteNext = false;
	StringBuilder b = new StringBuilder(100);

	for (int i = 0; i < sqlScript.length(); i++) {
		char c = sqlScript.charAt(i);

		if (c == ';' && !inString && !quoteNext) {
			sl.add(b.toString());
			b = new StringBuilder(100);
			inString = false;
			quoteNext = false;
			continue;
		}

		if (c == '\'' && !quoteNext) {
			inString = !inString;
		}

		quoteNext = c == '\\' && !quoteNext;

		b.append(c);
	}

	if (b.length() > 0) {
		sl.add(b.toString());
	}

	return sl;
}
 
源代码12 项目: XLog   文件: XLogProcessor.java
String stringLiteral(String value) {
    StringBuilder result = new StringBuilder();
    result.append('"');
    for (int i = 0; i < value.length(); i++) {
        char c = value.charAt(i);
        switch (c) {
            case '"':
                result.append("\\\"");
                break;
            case '\\':
                result.append("\\\\");
                break;
            case '\b':
                result.append("\\b");
                break;
            case '\t':
                result.append("\\t");
                break;
            case '\n':
                result.append("\\n");
                if (i + 1 < value.length()) {
                    result.append("\"\n").append("  ").append("  ").append("+ \"");
                }
                break;
            case '\f':
                result.append("\\f");
                break;
            case '\r':
                result.append("\\r");
                break;
            default:
                if (Character.isISOControl(c)) {
                    new Formatter(result).format("\\u%04x", (int) c);
                } else {
                    result.append(c);
                }
        }
    }
    result.append('"');
    return result.toString();
}
 
源代码13 项目: carbon-apimgt   文件: APITemplateBuilderImpl.java
@Override
public String getConfigStringForDefaultAPITemplate(String defaultVersion) throws APITemplateException {
    StringWriter writer = new StringWriter();

    try {
        VelocityEngine velocityengine = new VelocityEngine();
        if (!"not-defined".equalsIgnoreCase(getVelocityLogger())) {
            velocityengine.setProperty(RuntimeConstants.RUNTIME_LOG_LOGSYSTEM_CLASS,
                    CommonsLogLogChute.class.getName());
            velocityengine.setProperty(VelocityEngine.RESOURCE_LOADER, "classpath");
            velocityengine.setProperty("classpath.resource.loader.class", ClasspathResourceLoader.class.getName());
        }

        velocityengine.setProperty(RuntimeConstants.FILE_RESOURCE_LOADER_PATH, CarbonUtils.getCarbonHome());
        initVelocityEngine(velocityengine);

        ConfigContext configcontext = new APIConfigContext(this.api);
        configcontext = new TransportConfigContext(configcontext, api);
        configcontext = new ResourceConfigContext(configcontext, api);
        configcontext = new TemplateUtilContext(configcontext);

        VelocityContext context = configcontext.getContext();
        context.put("defaultVersion", defaultVersion);
        String fwdApiContext = this.api.getContext();
        if (fwdApiContext != null && fwdApiContext.charAt(0) == '/') {
            fwdApiContext = fwdApiContext.substring(1);
        }
        context.put("fwdApiContext", fwdApiContext);

        // for default version, we remove the {version} param from the apiContext
        String apiContext = this.api.getContextTemplate();
        if(apiContext.contains("{version}")){
            apiContext = apiContext.replace("/{version}","");
            apiContext = apiContext.replace("{version}","");
        }

        context.put("apiContext", apiContext);

        Template t = velocityengine.getTemplate(this.getDefaultAPITemplatePath());

        t.merge(context, writer);
    } catch (Exception e) {
        log.error("Velocity Error", e);
        throw new APITemplateException("Velocity Error", e);
    }
    return writer.toString();
}