Refine search
public static String parsePath(String uri, Map<String, String> patterns) { if (uri == null) { return null; } else if (StringUtils.isBlank(uri)) { return String.valueOf(SLASH); } CharacterIterator ci = new StringCharacterIterator(uri); StringBuilder pathBuffer = new StringBuilder(); char c = ci.first(); if (c == CharacterIterator.DONE) { return String.valueOf(SLASH); } do { if (c == OPEN) { String regexBuffer = cutParameter(ci, patterns); if (regexBuffer == null) { LOGGER.warn("Operation path \"" + uri + "\" contains syntax error."); return null; } pathBuffer.append(regexBuffer); } else { int length = pathBuffer.length(); if (!(c == SLASH && (length != 0 && pathBuffer.charAt(length - 1) == SLASH))) { pathBuffer.append(c); } } } while ((c = ci.next()) != CharacterIterator.DONE); return pathBuffer.toString(); }
private static boolean needsEscape(String value) { if (value.length() > 0 && value.charAt(0) == '\"') return false; final StringCharacterIterator iterator = new StringCharacterIterator(value); for (char ch = iterator.current(); ch != CharacterIterator.DONE; ch = iterator.next()) { if (!Character.isJavaIdentifierPart(ch) && ch != '-') { return true; } } return false; }
public static List<String> parseDelimitedList(String s) { List<String> result = new ArrayList<String>(); if (StringUtils.isNotEmpty(s)) { StringCharacterIterator iterator = new StringCharacterIterator(s); char c = iterator.first(); StringBuilder strb = new StringBuilder(); boolean insideExpression = false; while (c != StringCharacterIterator.DONE) { if (c == '{' || c == '$') { insideExpression = true; } else if (c == '}') { insideExpression = false; } else if (c == ',' && !insideExpression) { result.add(strb.toString().trim()); strb.delete(0, strb.length()); } if (c != ',' || (insideExpression)) { strb.append(c); } c = iterator.next(); } if (strb.length() > 0) { result.add(strb.toString().trim()); } } return result; }
import java.text.*; final CharacterIterator it = new StringCharacterIterator(s); for(char c = it.first(); c != CharacterIterator.DONE; c = it.next()) { // process c ... }
CharacterIterator iter = new StringCharacterIterator(string); char ch = iter.first(); int size = 0; while (ch != CharacterIterator.DONE) { if ((ch >= 0xD800) && (ch < 0xDC00)) { char trail = iter.next(); if ((trail > 0xDBFF) && (trail < 0xE000)) { iter.previous(); // rewind one
private static String removeLeadingSlashes(final String text) { if (text.isEmpty()) { return text; } final CharacterIterator it = new StringCharacterIterator(text); Character c = it.first(); while (c.equals('/')) { c = it.next(); } return text.substring(it.getIndex()); }
private NativeBreakIterator(long address, int type) { this.address = address; this.type = type; this.charIterator = new StringCharacterIterator(""); }
private int countChar(char searchChar, String inTargetString) { StringCharacterIterator iter = new StringCharacterIterator(inTargetString); int i = 0; if (iter.first() == searchChar) i++; while (iter.getIndex() < iter.getEndIndex()) { if (iter.next() == searchChar) { i++; } } return i; }
private static int indexOfEntityEnd(String htmlText, int start) { CharacterIterator sci = new StringCharacterIterator(htmlText, start); char c; do { c = sci.next(); if (c == ';') { return sci.getIndex(); } if (!Character.isLetterOrDigit(c)) { return -1; } } while (c != CharacterIterator.DONE); return -1; }
CharacterIterator it = new StringCharacterIterator("Hello, World"); char c; while ((c = it.next()) != CharacterIterator.DONE) { System.err.println("Char: " + c); }
CharacterIterator it = new StringCharacterIterator("abcd"); // Iterate over the characters in the forward direction for (char ch=it.first(); ch != CharacterIterator.DONE; ch=it.next()) // Iterate over the characters in the backward direction for (char ch=it.last(); ch != CharacterIterator.DONE; ch=it.previous())
/** check for any regular expression metacharacters between the index point (inclusive,exclusive) */ public static boolean noMetaChars(String string, int fromIndex, int endIndex) { StringCharacterIterator iter = new StringCharacterIterator(string, fromIndex, endIndex, fromIndex) ; char ch ; while ( ( ch = iter.next() ) != StringCharacterIterator.DONE ) { for ( char mc : metaChars ) { if ( mc == ch ) return false ; } } return true ; }
import java.text.CharacterIterator; import java.text.StringCharacterIterator; public class CI { private static final String text = "Hello"; public static void main(String[] args) { CharacterIterator it = new StringCharacterIterator(text); for (char ch = it.last(); ch != CharacterIterator.DONE; ch = it .previous()) { System.out.print(ch); } } }
private static String removeTrailingSlashes(final String text) { if (text.isEmpty()) { return text; } final CharacterIterator it = new StringCharacterIterator(text); Character c = it.last(); while (c.equals('/')) { c = it.previous(); } return text.substring(0, it.getIndex() + 1); }
public ExpressionLexer(AviatorEvaluatorInstance instance, String expression) { this.iterator = new StringCharacterIterator(expression); this.expression = expression; this.symbolTable = new SymbolTable(); this.peek = this.iterator.current(); this.instance = instance; this.mathContext = this.instance.getOptionValue(Options.MATH_CONTEXT).mathContext; this.parseFloatIntoDecimal = this.instance.getOptionValue(Options.ALWAYS_PARSE_FLOATING_POINT_NUMBER_INTO_DECIMAL).bool; }
private Vector getTokens( String text ) { if ( text == null ) return null; Vector tokens = new Vector(); StringCharacterIterator sci = new StringCharacterIterator( text ); while ( sci.current() != EOF ) { String token = nextToken( sci ); if ( token != null ) { tokens.add( token ); } //Log.getLogWriter().finest( "index:" + sci.getIndex() + " TOKEN:" + token ); } return tokens; } private StringBuffer token = new StringBuffer(100);
private void matchDelimiter( StringCharacterIterator sci, StringBuffer token ) { char c = sci.current(); switch( c ) { case PLUS : char cnext= sci.next(); switch( cnext) { case EQUALS : token.append( c ); token.append( cnext ); sci.next(); break; default : sci.previous(); matchValue( sci, token ); } break; default : token.append( c ); sci.next(); } } // this is called when a token starts with QUOTE
boolean hasMoreChars() { return( mIter.current() != mIter.DONE ); }