List of usage examples for java.lang Character isWhitespace
public static boolean isWhitespace(int codePoint)
From source file:eu.eidas.util.Preconditions.java
/** * Ensures that an array reference passed as a parameter to the calling method is neither null, empty nor blank. * * @param reference an array reference//from ww w . ja v a 2 s. c om * @param referenceName the array name which will appear in the exception message * @return the non-null array reference that was validated * @throws IllegalArgumentException if {@code reference} is null or empty */ @Nonnull public static char[] checkNotBlank(char[] reference, @Nonnull String referenceName) throws IllegalArgumentException { checkNotEmpty(reference, referenceName); for (char ch : reference) { if (!Character.isWhitespace(ch) && ch != '\0') { return reference; } } throw new IllegalArgumentException(referenceName + " cannot be blank"); }
From source file:com.nolanlawson.cordova.sqlite.SQLitePlugin.java
private static boolean startsWithCaseInsensitive(String str, String substr) { int i = -1;//from w w w . j a v a2 s .com int len = str.length(); while (++i < len) { char ch = str.charAt(i); if (!Character.isWhitespace(ch)) { break; } } int j = -1; int substrLen = substr.length(); while (++j < substrLen) { if (j + i >= len) { return false; } char ch = str.charAt(j + i); if (Character.toLowerCase(ch) != substr.charAt(j)) { return false; } } return true; }
From source file:com.glaf.core.util.StringTools.java
/** * //from w ww . jav a 2 s . com * * @param in * @return */ public static String cleanWhitespace(String in) { char[] inArray = in.toCharArray(); StringBuilder out = new StringBuilder(inArray.length); boolean lastWasSpace = false; for (int i = 0; i < inArray.length; i++) { char c = inArray[i]; if (Character.isWhitespace(c)) { if (!lastWasSpace) out.append(' '); lastWasSpace = true; } else { out.append(c); lastWasSpace = false; } } return out.toString(); }
From source file:org.eclipse.swt.snippets.Snippet133.java
void printText() { printer.startPage();//from w w w.j a va2s . c o m wordBuffer = new StringBuilder(); x = leftMargin; y = topMargin; index = 0; end = textToPrint.length(); while (index < end) { char c = textToPrint.charAt(index); index++; if (c != 0) { if (c == 0x0a || c == 0x0d) { if (c == 0x0d && index < end && textToPrint.charAt(index) == 0x0a) { index++; // if this is cr-lf, skip the lf } printWordBuffer(); newline(); } else { if (c != '\t') { wordBuffer.append(c); } if (Character.isWhitespace(c)) { printWordBuffer(); if (c == '\t') { x += tabWidth; } } } } } if (y + lineHeight <= bottomMargin) { printer.endPage(); } }
From source file:ca.mcgill.cs.swevo.qualyzer.editors.RTFDocumentProvider2.java
private ParserPair handleGroup(InputStream contentStream, Stack<Map<String, Integer>> state, StringBuilder text, RTFDocument document) throws IOException { int c = contentStream.read(); char ch = NULL_CHAR; ParserPair pair = null;/*from www .j a v a2 s . c om*/ String groupName = null; while (c != -1) { ch = (char) c; if (!Character.isWhitespace(ch)) { break; } else { c = contentStream.read(); } } if (ch == BACKSLASH) { pair = handleControl(contentStream, safeState(state)); c = pair.fChar; groupName = pair.fString; } else { groupName = " "; } if (in(groupName, IGNORE_GROUPS)) { c = skipGroup(contentStream, c); } else { Map<String, Integer> oldState = safeState(state); reset(oldState, text, document); Map<String, Integer> newState = new HashMap<String, Integer>(oldState); newState.put(UNICOUNT, oldState.get(UNICOUNT)); state.push(newState); resetNew(text, newState, document); handleControlCommand(groupName, text, newState, document); } return new ParserPair(c, groupName); }
From source file:jos.parser.Parser.java
private void processProperty(String line, boolean appearance) { boolean ro = false; String getter = null;//from ww w . jav a 2 s. c om line = cleanDeclaration(line); if (line.length() == 0) { return; } int p = line.indexOf(')'); String sub = line.substring(0, p + 1); if (sub.indexOf("readonly") != -1) { ro = true; } int j = sub.indexOf("getter="); if (j != -1) { int k = StringUtils.indexOfAny(sub.substring(j + 1), ",)") + j + 1; // TODO check translation log("j=%d k=%d str=%s", j, k, sub); getter = sub.substring(j + 7, j + 7 + k - (j + 7)); } final StringBuilder type = new StringBuilder(); int i = p + 1; for (; i < line.length(); i++) { char c = line.charAt(i); if (!Character.isWhitespace(c)) { break; } } for (; i < line.length(); i++) { char c = line.charAt(i); if (Character.isWhitespace(c)) { break; } type.append(c); } for (; i < line.length(); i++) { char c = line.charAt(i); if (Character.isWhitespace(c) || c == '*') { continue; } else { break; } } final StringBuilder selector = new StringBuilder(); for (; i < line.length(); i++) { char c = line.charAt(i); if (Character.isWhitespace(c) || c == ';') { break; } selector.append(c); } if (extraAnnotation != null) { gencs.println("\t/**"); gencs.printf("\t * @%s", extraAnnotation); gencs.println(); gencs.println("\t */"); } if (appearance) { gencs.printf("\t@Appearance"); gencs.println(); } //gencs.printf("\t@Export(\"%s\")", selector); //gencs.println(); final String retval = remapType(type.toString()); // gencs.printf("\tpublic %s %s;", retval, selector); // gencs.println(); // gencs.println(); if (getter != null) { gencs.printf("\t@Bind(\"" + getter + "\")"); gencs.println(); } gencs.printf("\t@Export(\"%s\")", selector.toString()); gencs.println(); gencs.printf("\tpublic %s get%s() {", retval, StringUtils.capitalize(selector.toString())); gencs.println(); gencs.printf("\t\tthrow new RuntimeException();"); gencs.println(); gencs.printf("\t}"); gencs.println(); gencs.println(); if (!ro) { gencs.printf("\t@Export(\"set%s:\")", StringUtils.capitalize(selector.toString())); gencs.println(); gencs.printf("\tpublic void set%s(%s value) {", StringUtils.capitalize(selector.toString()), retval); gencs.println(); gencs.printf("\t\tthrow new RuntimeException();"); gencs.println(); gencs.printf("\t}"); gencs.println(); gencs.println(); } }
From source file:com.vsct.dt.hesperides.templating.models.Property.java
/** * Check if it's an email address.//from w w w . j av a 2 s . c o m * * @param str string after name of property * @param len len string * @param arobasePos arobase position * * @return true/false */ private static boolean isNotAnnotation(final String str, final int len, final int arobasePos) { boolean notAnnotation = false; // 1 - Check if before '@' found white space if (arobasePos > 0 && !Character.isWhitespace(str.charAt(arobasePos - 1))) { // Is not annotation notAnnotation = true; } if (arobasePos == len - 1) { // Last char ! notAnnotation = true; } char currentChar; // 2 - Found first first whitespace for (int index = arobasePos + 1; index < len && !notAnnotation; index++) { // Annotation must be [a-zA-Z] currentChar = str.charAt(index); // If not A-Z or a-z break if (!((currentChar > 0x40 && currentChar < 0x5B) || (currentChar > 0x60 && currentChar < 0x7B))) { if (Character.isWhitespace(currentChar)) { break; } notAnnotation = true; } } return notAnnotation; }
From source file:com.meltmedia.cadmium.cli.HistoryCommand.java
/** * Helper method to format comments to standard out. * //w w w . j av a 2 s.c om * @param comment */ private static void printComments(String comment) { int index = 0; int nextIndex = 154; while (index < comment.length()) { nextIndex = nextIndex <= comment.length() ? nextIndex : comment.length(); String commentSegment = comment.substring(index, nextIndex); int lastSpace = commentSegment.lastIndexOf(' '); int lastNewLine = commentSegment.indexOf('\n'); char lastChar = ' '; if (nextIndex < comment.length()) { lastChar = comment.charAt(nextIndex); } if (lastNewLine > 0) { nextIndex = index + lastNewLine; commentSegment = comment.substring(index, nextIndex); } else if (Character.isWhitespace(lastChar)) { } else if (lastSpace > 0) { nextIndex = index + lastSpace; commentSegment = comment.substring(index, nextIndex); } System.out.println(" " + commentSegment); index = nextIndex; if (lastNewLine > 0 || lastSpace > 0) { index++; } nextIndex = index + 154; } }
From source file:com.sun.faces.demotest.cardemo.TestCarDemo.java
protected int extractNumberFromText(String content) { char[] chars = null; chars = content.toCharArray();/*from w ww . j a va2 s. c om*/ String number = null; int i, j; for (i = 0; i < chars.length; i++) { if (Character.isDigit(chars[i])) { for (j = i; j < chars.length; j++) { if (Character.isWhitespace(chars[j])) { break; } } number = content.substring(i, j); return Integer.valueOf(number).intValue(); } } return Integer.MIN_VALUE; }
From source file:de.fau.cs.osr.utils.StringUtils.java
public static String trimLeft(String text) { int from = 0; int length = text.length(); while ((from < length) && (Character.isWhitespace(text.charAt(from)))) ++from;/* www .j a va 2 s . co m*/ if (from > 0) { return text.substring(from, length); } else { return text; } }