List of usage examples for java.lang Character isWhitespace
public static boolean isWhitespace(int codePoint)
From source file:com.screenslicer.common.CommonUtil.java
public static int nextTextBreak(String str, int start) { if (CommonUtil.isEmpty(str) || start >= str.length()) { return str == null ? -1 : str.length(); }//from ww w. ja v a 2 s . com int next = start; for (; next + 1 < str.length() && (str.charAt(next) != '.' || !Character.isWhitespace(str.charAt(next + 1))) && str.charAt(next) != '\n' && str.charAt(next) != '\r' && str.charAt(next) != '\f'; next++) ; return (str.charAt(next) == '\n' || str.charAt(next) == '\r' || str.charAt(next) == '\f') ? next : next + 1; }
From source file:com.btoddb.chronicle.catchers.RestCatcherImpl.java
public boolean isJsonArray(InputStream inStream) { if (null == inStream) { return false; }/*from w w w .ja v a 2 s. c om*/ int count = 100; inStream.mark(count); int ch; try { do { ch = inStream.read(); } while ('[' != ch && '{' != ch && Character.isWhitespace((char) ch) && -1 != ch && --count > 0); inStream.reset(); if (0 == count) { Utils.logAndThrow(logger, "unrecognizable JSON, or too much whitespace before JSON doc starts"); } return '[' == ch; } catch (IOException e) { Utils.logAndThrow(logger, "exception while looking for JSON in InputStream", e); } return false; }
From source file:com.subgraph.vega.ui.httpviewer.entity.HttpEntityViewer.java
private boolean isBodyAscii(String body) { if (body == null || body.isEmpty()) return false; final int total = (body.length() > 500) ? (500) : (body.length()); int printable = 0; for (int i = 0; i < total; i++) { char c = body.charAt(i); if ((c >= 0x20 && c <= 0x7F) || Character.isWhitespace(c)) printable += 1;/* w w w . j av a 2 s. c o m*/ } return ((printable * 100) / total > 90); }
From source file:eu.lunisolar.magma.doc.FileProcessor.java
private int numberOfPrefixSpaces(String line) { if (line.length() == 0) { return Integer.MAX_VALUE; }//from w ww . j a v a2 s . co m int i = 0; while (i < line.length() && Character.isWhitespace(line.charAt(i))) { i++; } return i; }
From source file:com.github.xbn.text.StringUtil.java
/** <p>Eliminate whitespace from the left side of a str_obj.</p> /*from w w w .j a v a 2 s . co m*/ <p>The idea for this and {@code rtrim(str_toPad)} is from <br/> <code><a href="http://stackoverflow.com/questions/15567010/what-is-a-good-alternative-of-ltrim-and-rtrim-in-java">http://stackoverflow.com/questions/15567010/what-is-a-good-alternative-of-ltrim-and-rtrim-in-java</a></code> <br/>and <br/> <code><a href="http://www.fromdev.com/2009/07/playing-with-java-str_obj-trim-basics.html">http://www.fromdev.com/2009/07/playing-with-java-str_obj-trim-basics.html</a></code> <br/>(viewed 11/18/2013)</p> * @param str_toPad May not be {@code null}. * @see #rtrim(Object) rtrim(o) */ public static String ltrim(Object str_toPad) { String s = null; try { s = str_toPad.toString(); } catch (RuntimeException rx) { throw CrashIfObject.nullOrReturnCause(str_toPad, "str_toPad", null, rx); } int i = 0; while (i < s.length() && Character.isWhitespace(s.charAt(i))) { i++; } return s.substring(i); }
From source file:crow.util.Util.java
/** * ?//from w w w .ja va 2s . c o m * <ul> * <li>Util.isEmpty(null) = true</li> * <li>Util.isEmpty("") = true</li> * <li>Util.isEmpty(" ") = true</li> * <li>Util.isEmpty("abc") = false</li> * </ul> * * @param value * * @return true/false */ public static boolean isEmpty(String value) { int strLen; if (value == null || (strLen = value.length()) == 0) { return true; } for (int i = 0; i < strLen; i++) { if ((Character.isWhitespace(value.charAt(i)) == false)) { return false; } } return true; }
From source file:io.jsonwebtoken.impl.DefaultJwtParser.java
@Override public boolean isSigned(String jwt) { if (jwt == null) { return false; }/*from w w w . j ava 2 s . co m*/ int delimiterCount = 0; for (int i = 0; i < jwt.length(); i++) { char c = jwt.charAt(i); if (delimiterCount == 2) { return !Character.isWhitespace(c) && c != SEPARATOR_CHAR; } if (c == SEPARATOR_CHAR) { delimiterCount++; } } return false; }
From source file:net.pandoragames.far.ui.swing.component.UndoHistory.java
/** * Adds an UndoableEdit object (undo) to the list of undoable modifications. * @param anEdit to be added to the undo history *//* www . j a va2 s. c om*/ public boolean addEdit(UndoableEdit anEdit) { cutBranch(); if (logger.isTraceEnabled()) { logger.trace("ADD:" + stringValue(anEdit)); } UNDOTYPE undoType = UNDOTYPE.OTHER; if (anEdit instanceof AbstractDocument.DefaultDocumentEvent) { AbstractDocument.DefaultDocumentEvent event = (AbstractDocument.DefaultDocumentEvent) anEdit; if (event.getType() == DocumentEvent.EventType.REMOVE) { undoType = UNDOTYPE.REMOVE; } else if (event.getType() == DocumentEvent.EventType.INSERT) { String change = stringValue(anEdit); if ((change.length() == 1) && (Character.isWhitespace(change.charAt(0)))) { undoType = UNDOTYPE.WHITESPACE; } else { undoType = UNDOTYPE.INSERT; } } else if (event.getType() == DocumentEvent.EventType.CHANGE) { undoType = UNDOTYPE.CHANGE; } } if (UNDOTYPE.OTHER.equals(undoType)) { addIt(anEdit, undoType); } else if (lastWrittenUndo.equals(undoType)) { // an UndoRun has already been created undoList.get(index - 1).addEdit(anEdit); } else { addIt(anEdit, undoType); } lastWrittenUndo = undoType; transientRecords = 0; validateDOActions(); validateShotActions(); return false; }
From source file:ca.simplegames.micro.utils.StringUtils.java
/** * Trim <i>all</i> whitespace from the given String: * leading, trailing, and inbetween characters. * * @param str the String to check/*from w ww . j av a 2 s.co m*/ * @return the trimmed String * @see java.lang.Character#isWhitespace */ public static String trimAllWhitespace(String str) { if (!hasLength(str)) { return str; } StringBuffer buf = new StringBuffer(str); int index = 0; while (buf.length() > index) { if (Character.isWhitespace(buf.charAt(index))) { buf.deleteCharAt(index); } else { index++; } } return buf.toString(); }
From source file:org.apache.uima.ruta.resource.TreeWordList.java
/** * Add a new String into the TreeWordList * /* w ww .jav a2 s. c om*/ * @param s * The String to add */ public void addWord(String s) { // Create Nodes from all chars of the strings besides the last one TextNode pointer = root; for (Character each : s.toCharArray()) { if (dictRemoveWS && Character.isWhitespace(each)) { continue; } TextNode childNode = pointer.getChildNode(each); if (childNode == null) { childNode = new TextNode(each, false); pointer.addChild(childNode); } pointer = childNode; } pointer.setWordEnd(s.length() > 0); }