Java Code Examples for org.apache.commons.lang3.CharUtils#isAscii()
The following examples show how to use
org.apache.commons.lang3.CharUtils#isAscii() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ADLImporter.java From org.hl7.fhir.core with Apache License 2.0 | 6 votes |
private String generateToken(String atCode, boolean upFirst) { if (!texts.containsKey(atCode)) return atCode; String text = texts.get(atCode).getText(); boolean lastText = false; StringBuilder b = new StringBuilder(); for (char c : text.toCharArray()) { boolean ok = CharUtils.isAscii(c); if (ok) if (b.length() == 0) ok = Character.isAlphabetic(c); else ok = Character.isAlphabetic(c) || Character.isDigit(c); if (!ok) { lastText = false; } else { if (!lastText && (b.length() > 0 || upFirst)) b.append(Character.toUpperCase(c)); else b.append(Character.toLowerCase(c)); lastText = true; } } return b.toString(); }
Example 2
Source File: JavaCompilerUtils.java From tracingplane-java with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** * Replaces characters preceded by underscores with uppercase version, eg: * * 'hello_world' => 'helloWorld' 'hello_World' => 'helloWorld' 'hello__world' => 'hello_World' */ public static String formatCamelCase(String name) { StringBuilder formatted = new StringBuilder(); for (int i = 0; i < name.length(); i++) { char ci = name.charAt(i); if (i < name.length() - 1 && ci == '_' && CharUtils.isAscii(ci)) { char cii = name.charAt(i + 1); if (CharUtils.isAsciiAlphaLower(cii)) { formatted.append(StringUtils.upperCase(String.valueOf(cii))); i++; } } else { formatted.append(name.charAt(i)); } } return formatted.toString(); }
Example 3
Source File: DateTimeFormatTest.java From htmlunit with Apache License 2.0 | 5 votes |
private void test(final String... string) throws Exception { final StringBuilder html = new StringBuilder(HtmlPageTest.STANDARDS_MODE_PREFIX_ + "<html><head>\n" + "<script>\n" + " function test() {\n" + " var date = new Date(Date.UTC(2012, 11, 20, 3, 0, 0));\n" + " try {\n"); for (int i = 0; i < string.length - 1; i++) { html.append(string[i]).append("\n"); } html.append( " alert(" + string[string.length - 1] + ");\n" + " } catch(e) {alert('exception')}\n" + " }\n" + "</script>\n" + "</head><body onload='test()'>\n" + "</body></html>"); try { loadPageWithAlerts2(html.toString()); } catch (final ComparisonFailure e) { final String msg = e.getMessage(); for (int i = 0; i < msg.length(); i++) { final char c = msg.charAt(i); if (CharUtils.isAscii(c)) { System.out.print(c); } else { System.out.print(CharUtils.unicodeEscaped(c)); } } System.out.println(); throw e; } }
Example 4
Source File: StringProUtils.java From spring-boot-start-current with Apache License 2.0 | 5 votes |
public static String nonAsciiToUnicode ( String s ) { StringBuffer sb = new StringBuffer( s.length() ); for ( Character c : s.toCharArray() ) { if ( ! CharUtils.isAscii( c ) ) { sb.append( CharUtils.unicodeEscaped( c ) ); } else { sb.append( c ); } } return sb.toString(); }
Example 5
Source File: InspectFile.java From count-db with MIT License | 5 votes |
private static String replaceNonAscii(String valueToPrint) { StringBuilder result = new StringBuilder(); for (int i = 0; i < valueToPrint.length(); i++) { if (CharUtils.isAscii(valueToPrint.charAt(i))) { result.append(valueToPrint.charAt(i)); } else { result.append("?"); } } return result.toString(); }