List of usage examples for java.lang Character isSpaceChar
public static boolean isSpaceChar(int codePoint)
From source file:ru.xxlabaza.popa.pack.LineBreaker.java
private int getFirstNotSpaceCharacterIndex(char[] chars, int currentIndex) { for (int index = currentIndex; index < chars.length; index++) { if (!Character.isSpaceChar(chars[index])) { return index; }/*from w ww .j a v a 2s . c o m*/ } return -1; }
From source file:org.talend.repository.json.util.JSONUtil.java
public static boolean validateLabelForNameSpace(String label) { if (label == null) { return false; }//from w w w. ja v a2 s . c o m if (label.toLowerCase().startsWith(JSON_FILE)) { return false; } if (label.contains(".")) { //$NON-NLS-1$ return false; } if (!("".equals(label)) && !("".equals(label.trim()))) { //$NON-NLS-1$ //$NON-NLS-2$ char firstChar = label.charAt(0); if (!Character.isLetter(firstChar)) { return false; } char[] array = label.toCharArray(); for (char element : array) { if (Character.isSpaceChar(element) || Character.isWhitespace(element)) { return false; } } } return true; }
From source file:com.conwet.xjsp.json.JSONUtil.java
public static boolean isSpace(char ch) { return Character.isSpaceChar(ch) || (ch == '\n') || (ch == '\r'); }
From source file:NaturalOrderComparator.java
public int compare(Object o1, Object o2) { String a = o1.toString();/*from ww w .j a v a 2s. co m*/ String b = o2.toString(); int ia = 0, ib = 0; int nza = 0, nzb = 0; char ca, cb; int result; while (true) { // only count the number of zeroes leading the last number compared nza = nzb = 0; ca = charAt(a, ia); cb = charAt(b, ib); // skip over leading spaces or zeros while (Character.isSpaceChar(ca) || ca == '0') { if (ca == '0') { nza++; } else { // only count consecutive zeroes nza = 0; } ca = charAt(a, ++ia); } while (Character.isSpaceChar(cb) || cb == '0') { if (cb == '0') { nzb++; } else { // only count consecutive zeroes nzb = 0; } cb = charAt(b, ++ib); } // process run of digits if (Character.isDigit(ca) && Character.isDigit(cb)) { if ((result = compareRight(a.substring(ia), b.substring(ib))) != 0) { return result; } } if (ca == 0 && cb == 0) { // The strings compare the same. Perhaps the caller // will want to call strcmp to break the tie. return nza - nzb; } if (ca < cb) { return -1; } else if (ca > cb) { return +1; } ++ia; ++ib; } }
From source file:br.com.renatoccosta.regexrenamer.element.FilterElement.java
@Override public String convert(String src) { StringBuilder sb = new StringBuilder(); char[] caracs = src.toCharArray(); switch (mode) { case LETTERS: for (int i = 0; i < caracs.length; i++) { char c = caracs[i]; if (!Character.isLetter(c)) { sb.append(c);//from w ww . j ava 2 s. c o m } } return sb.toString(); case NUMBERS: for (int i = 0; i < caracs.length; i++) { char c = caracs[i]; if (!Character.isDigit(c)) { sb.append(c); } } return sb.toString(); case SYMBOLS: for (int i = 0; i < caracs.length; i++) { char c = caracs[i]; if (Character.isLetterOrDigit(c) || Character.isSpaceChar(c)) { sb.append(c); } } return sb.toString(); case WHITE_SPACE: return StringUtils.deleteWhitespace(src); } return src; }
From source file:org.vietspider.server.handler.cms.metas.FilterContentHandler.java
public String handle(final HttpRequest request, final HttpResponse response, final HttpContext context, String... params) throws Exception { String pattern = params[1];/* w ww . j av a2s.c o m*/ int idx = pattern.indexOf('='); if (idx < 0 || idx >= pattern.length() - 1) { throw new IndexOutOfBoundsException("Incorrect parammeter"); } String filter = URLDecoder.decode(pattern.substring(idx + 1), "UTF-8"); MetaList metas = new MetaList(); metas.setAction("FILTER"); metas.setCurrentPage(Integer.parseInt(params[0])); File file = UtilFile.getFile("system/plugin/filter", NameConverter.encode(filter)); if (file.exists() && file.length() > 0) { String text = new String(RWData.getInstance().load(file), Application.CHARSET); int start = 0; while (start < text.length()) { char c = text.charAt(start); if (Character.isLetterOrDigit(c)) break; start++; } int end = text.length() - 1; while (end > 0) { char c = text.charAt(end); if (Character.isLetterOrDigit(c)) break; end--; } StringBuilder builder = new StringBuilder("\""); for (int i = start; i <= end; i++) { char c = text.charAt(i); if (c == ',') { builder.append("\" AND \""); } else if (c == '\n') { builder.append("\" OR \""); } else if (Character.isLetterOrDigit(c)) { builder.append(c); } else if (Character.isSpaceChar(c) || Character.isWhitespace(c)) { builder.append(' '); } } builder.append("\""); // System.out.println(" thay co filter "+ builder); ArticleSearchQuery query = new ArticleSearchQuery(); query.setPattern(builder.toString()); if (Application.LICENSE != Install.PERSONAL) { query.setHighlightStart("no"); ArticleIndexStorage.getInstance().search(metas, query); } } metas.setTitle(filter); metas.setUrl("?text=" + pattern.substring(idx + 1)); return write(request, response, context, metas, params); }
From source file:com.j_o.android.imdb_client.ui.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mediaList = new ArrayList<Media>(); mediaGrid = (GridView) findViewById(R.id.media_grid_view); editTxMediaSearch = (EditText) findViewById(R.id.edit_search_media); // Input filter that not allow special characters. InputFilter filter = new InputFilter() { @Override//from w w w . ja v a 2 s . c o m public CharSequence filter(CharSequence source, int start, int end, Spanned dest, int dstart, int dend) { if (source instanceof SpannableStringBuilder) { SpannableStringBuilder sourceAsSpannableBuilder = (SpannableStringBuilder) source; for (int i = end - 1; i >= start; i--) { char currentChar = source.charAt(i); if (!Character.isLetterOrDigit(currentChar) && !Character.isSpaceChar(currentChar)) { sourceAsSpannableBuilder.delete(i, i + 1); } } return source; } else { StringBuilder filteredStringBuilder = new StringBuilder(); for (int i = 0; i < end; i++) { char currentChar = source.charAt(i); if (Character.isLetterOrDigit(currentChar) || Character.isSpaceChar(currentChar)) { filteredStringBuilder.append(currentChar); } } return filteredStringBuilder.toString(); } } }; editTxMediaSearch.setFilters(new InputFilter[] { filter }); editTxMediaSearch.setOnEditorActionListener(new TextView.OnEditorActionListener() { @Override public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { if (actionId == EditorInfo.IME_ACTION_SEARCH) { new AskForMediaAsyncTaks().execute(editTxMediaSearch.getText().toString()); InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(editTxMediaSearch.getWindowToken(), 0); return true; } return false; } }); }
From source file:com.bukanir.android.utils.Utils.java
public static String toTitleCase(String input) { StringBuilder titleCase = new StringBuilder(); boolean nextTitleCase = true; for (char c : input.toCharArray()) { if (Character.isSpaceChar(c)) { nextTitleCase = true;/*from w w w. j a va 2 s. c o m*/ } else if (nextTitleCase) { c = Character.toTitleCase(c); nextTitleCase = false; } titleCase.append(c); } return titleCase.toString(); }
From source file:com.github.jferard.pgloaderutils.sniffer.csv.HeaderRowAnalyzer.java
private int advanceCurFieldStartIndex(String curExpectedField, String line, int curFieldDelimiterBlockIndex, int nextFieldFirstLetterIndex) throws IOException { final char maybeDelimiter = line.charAt(curFieldDelimiterBlockIndex); int nextFieldStartIndex; // just a delimiter if (nextFieldFirstLetterIndex == curFieldDelimiterBlockIndex + 1) { if (Character.isLetterOrDigit(maybeDelimiter)) throw new IOException("Bad delimiter after field of field:" + curExpectedField + " (" + line + ")"); this.delimiter = maybeDelimiter; nextFieldStartIndex = nextFieldFirstLetterIndex; } else {//from w w w . j a v a2s . c o m // trim int i = curFieldDelimiterBlockIndex; while (Character.isSpaceChar(line.charAt(i))) i++; int j = nextFieldFirstLetterIndex - 1; while (Character.isSpaceChar(line.charAt(j))) j--; if (j > i) { // only space, tabs, ... chars if (Character.isLetterOrDigit(maybeDelimiter)) throw new IOException( "Bad delimiter after field of field:" + curExpectedField + " (" + line + ")"); this.delimiterCounter.put(maybeDelimiter); nextFieldStartIndex = nextFieldFirstLetterIndex; } else if (i < j) { this.delimiterCounter.put(line.charAt(i)); this.quoteCounter.put(line.charAt(j)); nextFieldStartIndex = j; } else { this.delimiterCounter.put(line.charAt(i)); nextFieldStartIndex = nextFieldFirstLetterIndex; } } return nextFieldStartIndex; }
From source file:org.pentaho.di.core.util.StringEvaluator.java
private void challengeConversions(String value) { List<StringEvaluationResult> all = new ArrayList<StringEvaluationResult>(evaluationResults); ValueMetaInterface stringMetaClone = null; for (StringEvaluationResult cmm : all) { if (cmm.getConversionMeta().isBoolean()) { // Boolean conversion never fails. // If it's a Y, N, true, false it's a boolean otherwise it ain't. ////from ww w . jav a 2 s .c o m String string; if (tryTrimming) { string = Const.trim(value); } else { string = value; } if (StringUtils.isEmpty(value)) { cmm.incrementNrNull(); } else if (!("Y".equalsIgnoreCase(string) || "N".equalsIgnoreCase(string) || "TRUE".equalsIgnoreCase(string) || "FALSE".equalsIgnoreCase(string))) { evaluationResults.remove(cmm); } else { cmm.incrementSuccesses(); } } else if (cmm.getConversionMeta().isDate()) { String dateFormat = cmm.getConversionMeta().getConversionMask(); if (!DateDetector.isValidDateFormatToStringDate(dateFormat, value, "en_US")) { evaluationResults.remove(cmm); } else { try { Object object = DateDetector.getDateFromStringByFormat(value, dateFormat); cmm.incrementSuccesses(); if (cmm.getMin() == null || cmm.getConversionMeta().compare(cmm.getMin(), object) > 0) { cmm.setMin(object); } if (cmm.getMax() == null || cmm.getConversionMeta().compare(cmm.getMax(), object) < 0) { cmm.setMax(object); } } catch (ParseException e) { evaluationResults.remove(cmm); } catch (KettleValueException e) { evaluationResults.remove(cmm); } } } else { try { if (cmm.getConversionMeta().isNumeric()) { boolean stop = false; int nrDots = 0; int nrCommas = 0; int pos = 0; for (char c : value.toCharArray()) { boolean currencySymbolMatch = !String.valueOf(c) .equals(cmm.getConversionMeta().getCurrencySymbol()) && c != '(' && c != ')'; if (!Character.isDigit(c) && c != '.' && c != ',' && !Character.isSpaceChar(c) && currencySymbolMatch && (pos > 0 && (c == '+' || c == '-')) // allow + & - at the 1st position ) { evaluationResults.remove(cmm); stop = true; break; } // If the value contains a decimal or grouping symbol or some sort, it's not an integer // if ((c == '.' && cmm.getConversionMeta().isInteger()) || (c == ',' && cmm.getConversionMeta().isInteger())) { evaluationResults.remove(cmm); stop = true; break; } if (c == '.') { nrDots++; } if (c == ',') { nrCommas++; } pos++; } if (nrDots > 1 && nrCommas > 1) { evaluationResults.remove(cmm); stop = true; } if (stop) { continue; } } if (stringMetaClone == null) { // avoid cloning each time stringMetaClone = stringMeta.clone(); } stringMetaClone.setConversionMetadata(cmm.getConversionMeta()); stringMetaClone.setTrimType(cmm.getConversionMeta().getTrimType()); Object object = stringMetaClone.convertDataUsingConversionMetaData(value); // Still here? Evaluate the data... // Keep track of null values, min, max, etc. // if (cmm.getConversionMeta().isNull(object)) { cmm.incrementNrNull(); } else { cmm.incrementSuccesses(); } if (cmm.getMin() == null || cmm.getConversionMeta().compare(cmm.getMin(), object) > 0) { cmm.setMin(object); } if (cmm.getMax() == null || cmm.getConversionMeta().compare(cmm.getMax(), object) < 0) { cmm.setMax(object); } } catch (KettleValueException e) { // This one doesn't work, remove it from the list! // evaluationResults.remove(cmm); } } } }