List of usage examples for java.text CharacterIterator DONE
char DONE
To view the source code for java.text CharacterIterator DONE.
Click Source Link
From source file:com.thinkbiganalytics.feedmgr.rest.support.SystemNamingService.java
public static String generateSystemName(String name) { //first trim it String systemName = StringUtils.trimToEmpty(name); if (StringUtils.isBlank(systemName)) { return systemName; }/*from ww w . ja v a2 s .co m*/ systemName = systemName.replaceAll(" +", "_"); systemName = systemName.replaceAll("[^\\w_]", ""); int i = 0; StringBuilder s = new StringBuilder(); CharacterIterator itr = new StringCharacterIterator(systemName); for (char c = itr.first(); c != CharacterIterator.DONE; c = itr.next()) { if (Character.isUpperCase(c)) { //if it is upper, not at the start and not at the end check to see if i am surrounded by upper then lower it. if (i > 0 && i != systemName.length() - 1) { char prevChar = systemName.charAt(i - 1); char nextChar = systemName.charAt(i + 1); if (Character.isUpperCase(prevChar) && (Character.isUpperCase(nextChar) || CharUtils.isAsciiNumeric(nextChar) || '_' == nextChar || '-' == nextChar)) { char lowerChar = Character.toLowerCase(systemName.charAt(i)); s.append(lowerChar); } else { s.append(c); } } else if (i > 0 && i == systemName.length() - 1) { char prevChar = systemName.charAt(i - 1); if (Character.isUpperCase(prevChar) && !CharUtils.isAsciiNumeric(systemName.charAt(i))) { char lowerChar = Character.toLowerCase(systemName.charAt(i)); s.append(lowerChar); } else { s.append(c); } } else { s.append(c); } } else { s.append(c); } i++; } systemName = s.toString(); systemName = CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_UNDERSCORE, systemName); systemName = CaseFormat.LOWER_HYPHEN.to(CaseFormat.LOWER_UNDERSCORE, systemName); systemName = StringUtils.replace(systemName, "__", "_"); // Truncate length if exceeds Hive limit systemName = (systemName.length() > 128 ? systemName.substring(0, 127) : systemName); return systemName; }
From source file:Main.java
public static String encode(String unencodedValue) { CharacterIterator charIterator; StringBuilder encodeBuilder;/*from www . j a v a 2s . c o m*/ char currentChar; encodeBuilder = new StringBuilder(); charIterator = new StringCharacterIterator(unencodedValue); while ((currentChar = charIterator.current()) != CharacterIterator.DONE) { switch (currentChar) { case '&': encodeBuilder.append("&"); break; case '<': encodeBuilder.append("<"); break; case '>': encodeBuilder.append(">"); break; default: encodeBuilder.append(currentChar); } charIterator.next(); } return encodeBuilder.toString(); }
From source file:stg.utils.StringUtils.java
/** * Splits the given string for all occurrences a space character. * /*from w ww.jav a 2 s . c om*/ * If the string is null return null. * If the string is empty returns an empty array of size equals zero. * * @param text String to be split * @return String[] */ public static String[] split(String text) { return split(text, ' ', CharacterIterator.DONE); }
From source file:Utils.java
/** * Determine whether the supplied string represents a well-formed fully-qualified Java classname. This utility method enforces * no conventions (e.g., packages are all lowercase) nor checks whether the class is available on the classpath. * //from w w w . j a v a2 s . co m * @param classname * @return true if the string is a fully-qualified class name */ public static boolean isFullyQualifiedClassname(String classname) { if (classname == null) return false; String[] parts = classname.split("[\\.]"); if (parts.length == 0) return false; for (String part : parts) { CharacterIterator iter = new StringCharacterIterator(part); // Check first character (there should at least be one character for each part) ... char c = iter.first(); if (c == CharacterIterator.DONE) return false; if (!Character.isJavaIdentifierStart(c) && !Character.isIdentifierIgnorable(c)) return false; c = iter.next(); // Check the remaining characters, if there are any ... while (c != CharacterIterator.DONE) { if (!Character.isJavaIdentifierPart(c) && !Character.isIdentifierIgnorable(c)) return false; c = iter.next(); } } return true; }
From source file:stg.utils.StringUtils.java
/** * Splits the given string for all occurrences of the separator char. * // w w w. j av a 2 s. co m * If the string is null return null. * If the string is empty returns an empty array of size equals zero. * * @param text String to be split * @param separatorChar the delimiter char * @return String[] */ public static String[] split(String text, Character separatorChar) { return split(text, separatorChar, CharacterIterator.DONE); }
From source file:XmlValueEncoder.java
/** * {@inheritDoc}//from w w w. j a v a 2 s. com * * @see org.jboss.dna.common.text.TextEncoder#encode(java.lang.String) */ public String encode(String text) { if (text == null) return null; StringBuilder sb = new StringBuilder(); CharacterIterator iter = new StringCharacterIterator(text); for (char c = iter.first(); c != CharacterIterator.DONE; c = iter.next()) { switch (c) { case '&': sb.append("&"); break; case '"': sb.append("""); break; case '<': sb.append("<"); break; case '>': sb.append(">"); break; case '\'': sb.append("'"); break; default: sb.append(c); } } return sb.toString(); }
From source file:AttributedStringUtilities.java
/** * Tests two attributed strings for equality. * /*from w ww . java 2 s .c om*/ * @param s1 * string 1 (<code>null</code> permitted). * @param s2 * string 2 (<code>null</code> permitted). * * @return <code>true</code> if <code>s1</code> and <code>s2</code> are * equal or both <code>null</code>, and <code>false</code> * otherwise. */ public static boolean equal(AttributedString s1, AttributedString s2) { if (s1 == null) { return (s2 == null); } if (s2 == null) { return false; } AttributedCharacterIterator it1 = s1.getIterator(); AttributedCharacterIterator it2 = s2.getIterator(); char c1 = it1.first(); char c2 = it2.first(); int start = 0; while (c1 != CharacterIterator.DONE) { int limit1 = it1.getRunLimit(); int limit2 = it2.getRunLimit(); if (limit1 != limit2) { return false; } // if maps aren't equivalent, return false Map m1 = it1.getAttributes(); Map m2 = it2.getAttributes(); if (!m1.equals(m2)) { return false; } // now check characters in the run are the same for (int i = start; i < limit1; i++) { if (c1 != c2) { return false; } c1 = it1.next(); c2 = it2.next(); } start = limit1; } return c2 == CharacterIterator.DONE; }
From source file:Util.java
/** * Returns a string that contains all characters of the given string in * reverse order.//from ww w. jav a 2s .com * * @param str * * @return */ 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); }
From source file:Main.java
public static String escapeStringForXML(String aText) { final StringBuilder result = new StringBuilder(); final StringCharacterIterator iterator = new StringCharacterIterator(aText); char character = iterator.current(); while (character != CharacterIterator.DONE) { if (character == '<') { result.append("<"); } else if (character == '>') { result.append(">"); } else if (character == '\"') { result.append("""); } else if (character == '\'') { result.append("'"); } else if (character == '&') { result.append("&"); } else {//from w w w . ja va2s . c o m //the char is not a special one //add it to the result as is result.append(character); } character = iterator.next(); } return result.toString(); }
From source file:XmlValueEncoder.java
/** * {@inheritDoc}/*from w ww.j a va2 s. c o m*/ * * @see org.jboss.dna.common.text.TextDecoder#decode(java.lang.String) */ public String decode(String encodedText) { if (encodedText == null) return null; StringBuilder sb = new StringBuilder(); CharacterIterator iter = new StringCharacterIterator(encodedText); for (char c = iter.first(); c != CharacterIterator.DONE; c = iter.next()) { if (c == '&') { int index = iter.getIndex(); do { c = iter.next(); } while (c != CharacterIterator.DONE && c != ';'); // We found a closing semicolon if (c == ';') { String s = encodedText.substring(index + 1, iter.getIndex()); if (SPECIAL_ENTITIES.containsKey(s)) { sb.append(SPECIAL_ENTITIES.get(s)); continue; } if (s.length() > 0 && s.charAt(0) == '#') { try { sb.append((char) Short.parseShort(s.substring(1, s.length()))); continue; } catch (NumberFormatException nfe) { // This is possible in malformed encodings, but let it fall through } } } // Malformed encoding, restore state and pass poorly encoded data back c = '&'; iter.setIndex(index); } sb.append(c); } return sb.toString(); }