List of usage examples for java.lang Character isWhitespace
public static boolean isWhitespace(int codePoint)
From source file:de.jcup.egradle.sdk.builder.action.javadoc.ReplaceJavaDocPartsAction.java
License:asdf
String replaceJavaDocTagInCurls(String description, String javaDocId, ContentReplacer replacer) { StringBuilder sb = new StringBuilder(); JavaDocState state = JavaDocState.UNKNOWN; /* scan for first { found" */ /*/*from w w w . j ava 2s .c o m*/ * check if next is wanted javadoc, otherwise leafe state /* when in * state - collect info until state }" */ StringBuilder content = new StringBuilder(); StringBuilder contentUnchanged = new StringBuilder(); for (char c : description.toCharArray()) { if (c == '{') { if (state == JavaDocState.CURLY_BRACKET_OPENED) { sb.append(contentUnchanged); } content = new StringBuilder(); contentUnchanged = new StringBuilder(); state = JavaDocState.CURLY_BRACKET_OPENED; contentUnchanged.append(c); continue; } else if (c == '}') { contentUnchanged.append(c); if (state == JavaDocState.JAVADOC_TAG_FOUND) { String replaced = replacer.replace(content.toString().trim()); sb.append(replaced); } else { sb.append(contentUnchanged); } content = new StringBuilder(); contentUnchanged = new StringBuilder(); state = JavaDocState.CURLY_BRACKET_CLOSED; continue; } if (state == JavaDocState.CURLY_BRACKET_OPENED) { contentUnchanged.append(c); if (content.length() == 0) { if (!Character.isWhitespace(c)) { // no leading whitespaces // after { content.append(c); } } else { content.append(c); } } else if (state == JavaDocState.JAVADOC_TAG_FOUND) { contentUnchanged.append(c); if (Character.isWhitespace(c)) { if (content.length() == 0) { /* forget leading whitespaces */ continue; } } content.append(c); } if (state == JavaDocState.CURLY_BRACKET_OPENED) { if (content.toString().equals(javaDocId)) { state = JavaDocState.JAVADOC_TAG_FOUND; content = new StringBuilder(); } } if (state == JavaDocState.UNKNOWN || state == JavaDocState.CURLY_BRACKET_CLOSED) { sb.append(c); } } if (state == JavaDocState.CURLY_BRACKET_OPENED) { /* * when last curly bracket was opened but not closed, we use * complete content */ sb.append(contentUnchanged); } String result = sb.toString(); return result; }
From source file:de.fau.cs.osr.utils.StringUtils.java
public static String trim(String text) { int from = 0; int length = text.length(); while ((from < length) && (Character.isWhitespace(text.charAt(from)))) ++from;//from w w w. java 2s . c om while ((from < length) && (Character.isWhitespace(text.charAt(length - 1)))) --length; if (from > 0 || length < text.length()) { return text.substring(from, length); } else { return text; } }
From source file:org.paxml.tag.sql.SqlTag.java
public static boolean isQuery(String sql) { final String select = "select"; if (StringUtils.isBlank(sql) || sql.length() <= select.length()) { return false; }//from w w w .j a v a 2 s . com return Character.isWhitespace(sql.charAt(select.length())) && sql.toLowerCase().startsWith(select); }
From source file:de.viaboxx.nlstools.formats.BundleWriter.java
public static Properties createProperties(String locale, MBBundle bundle, boolean merged, boolean debugMode, Task task) {//from w w w .ja v a 2s. c o m Iterator<MBEntry> entries = bundle.getEntries().iterator(); Properties p = new Properties(); while (entries.hasNext()) { MBEntry eachEntry = entries.next(); String key = eachEntry.getKey(); MBText langText = eachEntry.getText(locale); if (langText == null && merged && !StringUtils.isEmpty(locale)) { List<Locale> locales = LocaleUtils.localeLookupList(LocaleUtils.toLocale(locale)); // start with i=1 because locales.get(0) has already been tried - it is the 'locale' itself. for (int i = 1; i < locales.size(); i++) { // try to find from parent. begin with next specific Locale each = locales.get(i); langText = eachEntry.getText(each.toString()); if (langText != null) break; } if (langText == null) langText = eachEntry.getText(""); } if (langText != null) { String value; // in debug mode the keys are also displayed as labels if (!debugMode) { value = langText.getValue(); } else { value = key; } // Continue text at line breaks followed by whitespaces (indentations due to code formatter etc.) int indentIndex; while (value != null && (indentIndex = value.indexOf("\n ")) > -1) { int lastBlankIndex = indentIndex + 1; while (lastBlankIndex + 1 < value.length() && Character.isWhitespace(value.charAt(lastBlankIndex + 1))) { lastBlankIndex++; } value = value.substring(0, indentIndex) + ' ' + value.substring(lastBlankIndex + 1); } task.log("'" + key + "' ==> '" + value + "'", Project.MSG_DEBUG); if (key != null && value != null) { p.setProperty(key, value); } } } return p; }
From source file:de.fhg.iais.cortex.search.IndexerImpl.java
private static String stripHtmlAndPrune(final String input, final int maxlength) { String label = StringUtils.trimToEmpty(input.replaceAll("\\<.*?>", "")); final int securesize = maxlength * 2; if (label.length() > securesize) { //to avoid useless computation in next step label = label.substring(0, securesize); }// ww w. j a v a2s . c o m char[] chars = label.toCharArray(); for (int i = 0; i < chars.length; i++) { char c = chars[i]; if (Character.isWhitespace(c) && (' ' != c)) { chars[i] = ' '; } } label = new String(chars).replaceAll(" {2,}", " "); final int finalsize = label.length(); if (finalsize >= maxlength) { if (maxlength > 12) { return label.substring(0, maxlength - 3) + "..."; } else { return label.substring(0, maxlength); } } else { return label; } }
From source file:com.sjdf.platform.xss.StringUtils.java
/** * <p>/* w ww . jav a 2 s .c o m*/ * Checks if a CharSequence is whitespace, empty ("") or null. * </p> * <p/> * <pre> * StringUtils.isBlank(null) = true * StringUtils.isBlank("") = true * StringUtils.isBlank(" ") = true * StringUtils.isBlank("bob") = false * StringUtils.isBlank(" bob ") = false * </pre> * * @param cs the CharSequence to check, may be null * @return {@code true} if the CharSequence is null, empty or whitespace * @since 3.0 Changed signature from isBlank(String) to * isBlank(CharSequence) */ public static boolean isBlank(CharSequence cs) { int strLen; if (cs == null || (strLen = cs.length()) == 0) { return true; } for (int i = 0; i < strLen; i++) { if (!Character.isWhitespace(cs.charAt(i))) { return false; } } return true; }
From source file:com.puppycrawl.tools.checkstyle.checks.javadoc.JavadocStyleCheck.java
/** * Finds the index of the first non-whitespace character ignoring the * Javadoc comment start and end strings (/** and */) as well as any * leading asterisk./*from w ww .j a v a2 s.c o m*/ * @param line the Javadoc comment line of text to scan. * @return the int index relative to 0 for the start of text * or -1 if not found. */ private static int findTextStart(String line) { int textStart = -1; for (int i = 0; i < line.length();) { if (!Character.isWhitespace(line.charAt(i))) { if (line.regionMatches(i, "/**", 0, "/**".length())) { i += 2; } else if (line.regionMatches(i, "*/", 0, 2)) { i++; } else if (line.charAt(i) != '*') { textStart = i; break; } } i++; } return textStart; }
From source file:com.loopeer.codereader.api.HttpJsonLoggingInterceptor.java
/** * Returns true if the body in question probably contains human readable text. Uses a small sample * of code points to detect unicode control characters commonly used in binary file signatures. */// w w w . j a v a2s. com static boolean isPlaintext(Buffer buffer) { try { Buffer prefix = new Buffer(); long byteCount = buffer.size() < 64 ? buffer.size() : 64; buffer.copyTo(prefix, 0, byteCount); for (int i = 0; i < 16; i++) { if (prefix.exhausted()) { break; } int codePoint = prefix.readUtf8CodePoint(); if (Character.isISOControl(codePoint) && !Character.isWhitespace(codePoint)) { return false; } } return true; } catch (EOFException e) { return false; // Truncated UTF-8 sequence. } }
From source file:com.shishu.utility.string.StringUtil.java
/** * ?<code>null</code>?<code>""</code>? * //from w ww .j av a 2 s. c o m * <pre> * StringUtil.isBlank(null) = true * StringUtil.isBlank("") = true * StringUtil.isBlank(" ") = true * StringUtil.isBlank("bob") = false * StringUtil.isBlank(" bob ") = false * </pre> * * @param str ? * @return , <code>true</code> * @create 2009-1-6 ?01:49:48 yanghb * @history */ public static boolean isBlank(String str) { int length; if ((str == null) || ((length = str.length()) == 0)) { return true; } for (int i = 0; i < length; i++) { if (!Character.isWhitespace(str.charAt(i))) { return false; } } return true; }
From source file:BasicEditor3.java
void printText(String text) { PrintDialog dialog = new PrintDialog(shell); PrinterData printerData = dialog.open(); if (printerData == null) return;/* w ww. j av a 2 s. c o m*/ Printer printer = new Printer(printerData); if (!printer.startJob("text")) return; GC gc = new GC(printer); margins = PrintMargin.getPrintMargin(printer, 1.0); x = margins.left; y = margins.top; StringBuffer buffer = new StringBuffer(); Font font = new Font(printer, "Arial", 12, SWT.NORMAL); gc.setFont(font); lineHeight = gc.getFontMetrics().getHeight(); printer.startPage(); // prints page number at the bottom margin. String page = "- " + pageNumber + " -"; gc.drawString(page, (margins.right - margins.left - gc.textExtent(page).x) / 2 + margins.left, margins.bottom + gc.textExtent(page).y); for (int index = 0; index < text.length();) { char c = text.charAt(index); switch (c) { case '\r': if (index < text.length() - 1 && text.charAt(index + 1) == '\n') { printNewLine(printer, gc, buffer.toString()); buffer.setLength(0); index += 2; } break; case '\t': case ' ': if (gc.textExtent(buffer.toString() + ' ').x > margins.right - margins.left) { printNewLine(printer, gc, buffer.toString()); buffer.setLength(0); } buffer.append(c); if (index < text.length() - 1 && (!Character.isWhitespace(text.charAt(index + 1)))) { // Looks up one word to see whether the line should wraps here. String word = readWord(text, index + 1); if (gc.textExtent(buffer.toString() + word).x > margins.right - margins.left) { printNewLine(printer, gc, buffer.toString()); buffer.setLength(0); } } index += 1; break; default: buffer.append(c); index += 1; } } if (buffer.length() > 0) printNewLine(printer, gc, buffer.toString()); if (y + lineHeight <= margins.bottom) printer.endPage(); printer.endJob(); gc.dispose(); font.dispose(); printer.dispose(); }