List of usage examples for java.text StringCharacterIterator StringCharacterIterator
public StringCharacterIterator(String text)
From source file:XmlCharacters.java
/** * Determine if the supplied name is a valid XML NCName. * /*w ww. j a v a 2 s . c o m*/ * @param name the string being checked * @return true if the supplied name is indeed a valid XML NCName, or false otherwise */ public static boolean isValidNcName(String name) { if (name == null || name.length() == 0) return false; CharacterIterator iter = new StringCharacterIterator(name); char c = iter.first(); if (!isValidNcNameStart(c)) return false; while (c != CharacterIterator.DONE) { if (!isValidNcName(c)) return false; c = iter.next(); } return true; }
From source file:org.semanticscience.narf.structures.parts.Sequence.java
/** * Create the set of nucleotides from a nucleic acid sequence string. A * mapping is constructed of the residue position of the nucleotides to the * nucleotides. The method enables the sequence to commence at an arbitrary * sequence position.//w w w. jav a 2s . c o m * * @param aSequence * sequence string * @param aStartingPosition * the residue position of the first nucleotide * @return a mapping of the nucleotide residue positions to their respective * nucleotide residue position * @throws InvalidSequenceException * if any of the characters in the sequence string is not a * valid residue identifier * @throws InvalidResidueException * if the created nucleotide contains a residue exception * @since 1.6 */ SortedMap<Integer, Nucleotide> makeNucleotides(String aSequence, int aStartingPosition) throws InvalidSequenceException, InvalidResidueException { //first make the sequence all upper case aSequence = aSequence.toUpperCase(); if ((aSequence == null) || (aSequence.length() == 0)) { throw new InvalidSequenceException("The provided sequence has no characters."); } if (!this.checkStringSequence(aSequence)) { throw new InvalidSequenceException( "The inputted sequence has a invalid sequence character.\n" + aSequence + "\n"); } SortedMap<Integer, Nucleotide> returnMe = new TreeMap<Integer, Nucleotide>(); int currentPosition = aStartingPosition; CharacterIterator it = new StringCharacterIterator(aSequence); for (char ch = it.first(); ch != CharacterIterator.DONE; ch = it.next()) { returnMe.put(currentPosition, new Nucleotide(currentPosition, String.valueOf(ch))); currentPosition++; } return returnMe; }
From source file:org.talend.dataprep.schema.xls.XlsUtils.java
/** * return the column number from a cell reference (AA242) * * @param lastCell/*from ww w .jav a2s . co m*/ * @return */ public static int getColumnNumberFromCellRef(String lastCell) { StringBuilder letters = new StringBuilder(); // get all letters to remove row number StringCharacterIterator iter = new StringCharacterIterator(lastCell); for (char c = iter.first(); c != StringCharacterIterator.DONE; c = iter.next()) { if (!NumberUtils.isNumber(String.valueOf(c))) { letters.append(c); } } // use poi api to calculate column number from an excell column format return CellReference.convertColStringToIndex(letters.toString()); }
From source file:stg.utils.RandomStringGenerator.java
/** * Generates the random string as per the format. * /*from ww w . ja v a 2 s .c o m*/ * @return String */ public String generate() { CharacterIterator iter = new StringCharacterIterator(format); char c = iter.first(); StringBuilder sb = new StringBuilder(); List<Character> tempLowerCaseCharsList = cloneList(lowerCaseCharsList); List<Character> tempUpperCaseCharsList = cloneList(upperCaseCharsList); List<Character> tempNumericCharsList = cloneList(numericCharsList); List<Character> tempSpecialCharsList = cloneList(specialCharsList); boolean constantStarted = false; while (c != CharacterIterator.DONE) { switch (c) { case ESCAPE: c = iter.next(); if (c == CharacterIterator.DONE) { throw new IllegalArgumentException( "Invalid format, escape character found without any associated character that was to be escaped."); } sb.append(c); break; case LOWER_CASE: if (!constantStarted) { switch (option) { case NON_UNIQUE: sb.append(RandomStringUtils.random(1, toCharArray(lowerCaseCharsList))); break; case UNIQUE_CASE_SENSITIVE: sb.append(generateUniqueCharacter(c, tempLowerCaseCharsList)); break; default: String str = generateUniqueCharacter(c, tempLowerCaseCharsList); sb.append(str); if (!tempUpperCaseCharsList.contains(Character.valueOf(str.toUpperCase().charAt(0)))) { System.out.println(tempLowerCaseCharsList + " \t " + str); } if (!tempUpperCaseCharsList.remove(Character.valueOf(str.toUpperCase().charAt(0)))) { //remove it from the upper case char set. System.out.println("Problem unable to remove " + tempUpperCaseCharsList + "\t" + str); } break; } } else { sb.append(c); } break; case UPPER_CASE: if (!constantStarted) { switch (option) { case NON_UNIQUE: sb.append(RandomStringUtils.random(1, toCharArray(upperCaseCharsList))); break; case UNIQUE_CASE_SENSITIVE: sb.append(generateUniqueCharacter(c, tempUpperCaseCharsList)); break; default: String str = generateUniqueCharacter(c, tempUpperCaseCharsList); sb.append(str); if (!tempLowerCaseCharsList.contains(Character.valueOf(str.toLowerCase().charAt(0)))) { System.out.println(tempLowerCaseCharsList + " \t " + str); } if (!tempLowerCaseCharsList.remove(Character.valueOf(str.toLowerCase().charAt(0)))) { System.out.println("Problem unable to remove " + tempLowerCaseCharsList + "\t" + str); } break; } } else { sb.append(c); } break; case NUMBER: if (!constantStarted) { switch (option) { case NON_UNIQUE: sb.append(RandomStringUtils.random(1, toCharArray(numericCharsList))); break; default: sb.append(generateUniqueCharacter(c, tempNumericCharsList)); break; } } else { sb.append(c); } break; case SPECIAL: if (!constantStarted) { switch (option) { case NON_UNIQUE: sb.append(RandomStringUtils.random(1, toCharArray(specialCharsList))); break; default: sb.append(generateUniqueCharacter(c, tempSpecialCharsList)); break; } } else { sb.append(c); } break; case START_CONSTANT: if (constantStarted) { throw new IllegalArgumentException("Special { character found without an escape character"); } if (!constantStarted) constantStarted = true; break; case END_CONSTANT: if (!constantStarted) throw new IllegalArgumentException("Special } character found without an escape character"); if (constantStarted) constantStarted = false; break; default: sb.append(c); } c = iter.next(); } return sb.toString(); }
From source file:stg.utils.StringUtils.java
/** * Private method that performs split and returns the tokens in the form of List. * /*from w w w . j av a 2 s . c o m*/ * @param text String to be tokenized. * @param separatorChar used as a delimiter. * @param escapeChar used to escape delimiter. * @return List. */ private static List<String> psplit(String text, char separatorChar, char escapeChar) { if (text == null) { return new ArrayList<String>(); } if (separatorChar == escapeChar) { throw new IllegalArgumentException("Separator Char and Escape Char must be different."); } StringCharacterIterator iter = new StringCharacterIterator(text); char c = iter.first(); ArrayList<String> list = new ArrayList<String>(); StringBuilder sb = new StringBuilder(); while (c != CharacterIterator.DONE) { if (c == escapeChar) { c = iter.next(); if (c != CharacterIterator.DONE) { sb.append(c); } else { throw new IllegalArgumentException( "Escape Character found without the character to be ignored."); } } else if (c == separatorChar) { list.add(sb.toString()); sb.delete(0, sb.length()); } else { sb.append(c); } c = iter.next(); } if (sb.length() > -1) { list.add(sb.toString()); } return list; }
From source file:com.websystique.springmvc.youtube_api.Function.java
public String replace_all(String token) { StringBuilder s = new StringBuilder(token.length()); CharacterIterator it = new StringCharacterIterator(token); for (char ch = it.first(); ch != CharacterIterator.DONE; ch = it.next()) { switch (ch) { case '?': s.append("?####"); break; case '.': s.append(".####"); break; case ';': s.append(";####"); break; default://from w w w. j a v a 2 s.co m s.append(ch); break; } } token = s.toString(); return token; }
From source file:com.itude.mobile.android.util.StringUtil.java
/** * Strip a {@link String} by removing HTML elements * //from w ww . j ava 2 s . c o m * @param textToStrip {@link String} to strip * @return stripped {@link String} */ public static String stripHTMLTags(String textToStrip) { StringBuffer returnText = new StringBuffer(textToStrip.length()); CharacterIterator iterator = new StringCharacterIterator(textToStrip); boolean finished = true; boolean started = false; for (char ch = iterator.first(); ch != CharacterIterator.DONE; ch = iterator.next()) { if (ch == '<') { started = true; } else if (ch == '>') { started = false; finished = true; } else if (finished && !started) { returnText.append(ch); } } return returnText.toString().trim(); }
From source file:edu.harvard.i2b2.analysis.security.HighEncryption.java
public static String leftPad(String stringToPad, int size, String padder) { if (padder.length() == 0) { return stringToPad; }// ww w . j a v a2s . c om StringBuffer strb = new StringBuffer(size); StringCharacterIterator sci = new StringCharacterIterator(padder); while (strb.length() < (size - stringToPad.length())) { for (char ch = sci.first(); ch != CharacterIterator.DONE; ch = sci.next()) { if (strb.length() < size - stringToPad.length()) { strb.insert(strb.length(), String.valueOf(ch)); } } } return strb.append(stringToPad).toString(); }
From source file:org.rhq.enterprise.gui.legacy.action.resource.common.monitor.visibility.IndicatorChartsAction.java
/** * Find characters having special meaning <em>inside</em> HTML tags and URLs. * <p/>/*ww w. j a v a 2 s .co m*/ * <p/> * The special characters are : <ul> <li>< <li>> <li>" <li>' <li>\ <li>& <li>| <li>? </ul> * <p/> * <p/> */ private static int indexOfSpecialChars(String aTagFragment) { final StringCharacterIterator iterator = new StringCharacterIterator(aTagFragment); int i = 0; for (char character = iterator.current(); character != CharacterIterator.DONE; character = iterator .next(), i++) { switch (character) { case '<': case '>': case '\"': case '\'': case '\\': case '&': case '|': case '?': return i; default: break; } } return -1; }
From source file:stg.utils.StringUtils.java
/** * Private method to extract the tokens as list. * @param text//from w ww .j av a2 s. co m * @param separatorCharStart * @param separatorCharEnd * @param escapeChar * @param includeSeparators * @return list of strings */ private static List<String> pExtract(String text, final char separatorCharStart, final char separatorCharEnd, final char escapeChar, final boolean includeSeparators) { if (text == null) { return new ArrayList<String>(); } if (separatorCharStart == separatorCharEnd) { return psplit(text, separatorCharStart, escapeChar); } boolean escapeAndSeparatorCharAreSame = (separatorCharStart == escapeChar); StringCharacterIterator iter = new StringCharacterIterator(text); char c = iter.first(); ArrayList<String> list = new ArrayList<String>(); StringBuilder sb = new StringBuilder(); boolean toBeAppended = false; while (c != CharacterIterator.DONE) { if (c == escapeChar && !escapeAndSeparatorCharAreSame) { c = iter.next(); if (c == CharacterIterator.DONE) { throw new IllegalArgumentException( "Escape Character found without the character to be ignored."); } } else if (c == separatorCharEnd) { if (toBeAppended) { if (includeSeparators) { sb.append(c); } list.add(sb.toString()); sb.delete(0, sb.length()); toBeAppended = false; } } else if (c == separatorCharStart) { c = iter.next(); if (c == CharacterIterator.DONE) { throw new IllegalArgumentException( "Separator Character Start found without any enclosing text."); } toBeAppended = true; if (c == separatorCharStart && escapeAndSeparatorCharAreSame) { toBeAppended = false; c = iter.next(); } if (toBeAppended && includeSeparators) { sb.append(separatorCharStart); } } if (toBeAppended) { sb.append(c); } c = iter.next(); } return list; }