List of usage examples for java.text Normalizer normalize
public static String normalize(CharSequence src, Form form)
From source file:com.albert.util.StringUtilCommon.java
/** * Convert string to ascii .it returns ? for * non ascii characters//from w w w . jav a2 s . c o m * @param s * @return ascii format of s */ public static String toAscii(String s) { String s1 = Normalizer.normalize(s, Normalizer.Form.NFKD); String regex = "[\\p{InCombiningDiacriticalMarks}]+"; String s2 = ""; try { s2 = new String(s1.replaceAll(regex, "").getBytes("ascii"), "ascii"); } catch (UnsupportedEncodingException e) { log.error("toAscii failed: " + s, e); return s1; } return s2; }
From source file:org.betaconceptframework.astroboa.engine.jcr.util.CmsRepositoryEntityUtils.java
public String deAccent(String systemName) { String nfdNormalizedString = Normalizer.normalize(systemName, Normalizer.Form.NFD); return CmsConstants.DIACRITICAL_MARKS.matcher(nfdNormalizedString).replaceAll(""); }
From source file:org.esupportail.portlet.filemanager.services.ServersAccessService.java
private static String unAccent(String s) { String temp = Normalizer.normalize(s, Normalizer.Form.NFD); Pattern pattern = Pattern.compile("\\p{InCombiningDiacriticalMarks}+"); return pattern.matcher(temp).replaceAll(""); }
From source file:com.money.manager.ex.common.CategoryListFragment.java
public CategoryExpandableListAdapter getAdapter(Cursor data) { if (data == null) return null; mCategories.clear();/*from ww w .j av a2s. co m*/ mSubCategories.clear(); mPositionToExpand.clear(); // create core and fixed string filter to highlight Core core = new Core(getActivity().getApplicationContext()); String filter = mCurFilter != null ? mCurFilter.replace("%", "") : ""; int key = -1; List<QueryCategorySubCategory> listSubCategories = null; // reset cursor if getting back on the fragment. if (data.getPosition() > 0) { data.moveToPosition(Constants.NOT_SET); } while (data.moveToNext()) { if (key != data.getInt(data.getColumnIndex(QueryCategorySubCategory.CATEGID))) { // check if listCategories > 0 if (mCategories.size() > 0 && listSubCategories != null) { mSubCategories.put(mCategories.get(mCategories.size() - 1), listSubCategories); } // update key key = data.getInt(data.getColumnIndex(QueryCategorySubCategory.CATEGID)); // create instance category Category category = new Category(); category.setId(data.getInt(data.getColumnIndex(QueryCategorySubCategory.CATEGID))); category.setName(core .highlight(filter, data.getString(data.getColumnIndex(QueryCategorySubCategory.CATEGNAME))) .toString()); // add list mCategories.add(category); listSubCategories = new ArrayList<>(); } if (data.getInt(data.getColumnIndex(QueryCategorySubCategory.SUBCATEGID)) != Constants.NOT_SET) { QueryCategorySubCategory subCategory = new QueryCategorySubCategory(getActivity()); // subcategory subCategory.setSubCategId(data.getInt(data.getColumnIndex(QueryCategorySubCategory.SUBCATEGID))); subCategory.setSubcategoryName(core.highlight(filter, data.getString(data.getColumnIndex(QueryCategorySubCategory.SUBCATEGNAME)))); subCategory.setCategId(data.getInt(data.getColumnIndex(QueryCategorySubCategory.CATEGID))); subCategory.setCategName(core.highlight(filter, data.getString(data.getColumnIndex(QueryCategorySubCategory.CATEGNAME)))); // add to hashmap listSubCategories.add(subCategory); // check if expand group if (!TextUtils.isEmpty(filter)) { String normalizedText = Normalizer .normalize(subCategory.getSubcategoryName(), Normalizer.Form.NFD) .replaceAll("\\p{InCombiningDiacriticalMarks}+", "").toLowerCase(); if ((normalizedText.indexOf(filter) >= 0) && (!mPositionToExpand.contains(mCategories.size() - 1))) { mPositionToExpand.add(mCategories.size() - 1); } } } } if (mCategories.size() > 0 && listSubCategories != null) { mSubCategories.put(mCategories.get(mCategories.size() - 1), listSubCategories); } boolean showSelector = mAction.equals(Intent.ACTION_PICK); CategoryExpandableListAdapter adapter = new CategoryExpandableListAdapter(getActivity(), mLayout, mCategories, mSubCategories, showSelector); adapter.setIdChildChecked(mIdGroupChecked, mIdChildChecked); return adapter; }
From source file:org.apache.pdfbox.text.TextPosition.java
/** * Combine the diacritic, for example, convert non-combining diacritic characters to their * combining counterparts./*from ww w .jav a 2s . c o m*/ * * @param str String to normalize * @return Normalized string */ private String combineDiacritic(String str) { // Unicode contains special combining forms of the diacritic characters which we want to use int codePoint = str.codePointAt(0); // convert the characters not defined in the Unicode spec if (DIACRITICS.containsKey(codePoint)) { return DIACRITICS.get(codePoint); } else { return Normalizer.normalize(str, Normalizer.Form.NFKC).trim(); } }
From source file:org.sejda.sambox.text.TextPosition.java
/** * Combine the diacritic, for example, convert non-combining diacritic characters to their combining counterparts. * * @param str String to normalize/* w w w. j av a2 s. c o m*/ * @return Normalized string */ private String combineDiacritic(String str) { // Unicode contains special combining forms of the diacritic characters which we want to use int codePoint = str.codePointAt(0); // convert the characters not defined in the Unicode spec if (DIACRITICS.containsKey(codePoint)) { return DIACRITICS.get(codePoint); } return Normalizer.normalize(str, Normalizer.Form.NFKC).trim(); }
From source file:org.nuxeo.ecm.platform.semanticentities.service.LocalEntityServiceImpl.java
public String normalizeName(String name) { // remove punctuation and normalize whitespaces name = name.replaceAll(SEPARATOR_CHARS_TO_IGNORE, " ").trim(); // strip accents and diacritics name = Normalizer.normalize(name, Normalizer.Form.NFD).replaceAll(CHARS_TO_IGNORE, ""); // make name lookups case insensitive by normalizing case return name.toLowerCase(); }
From source file:nl.inl.util.StringUtil.java
/** * Convert accented letters to their unaccented counterparts. * * @param input/*from w w w . ja v a 2 s.c o m*/ * the string possibly containing accented letters. * @return the unaccented version */ public static String removeAccents(String input) { // Separate characters into base character and diacritics characters String normalized = Normalizer.normalize(input, Normalizer.Form.NFD); // Remove diacritics return PATT_DIACRITICS.matcher(normalized).replaceAll(""); }
From source file:br.com.blackhubos.eventozero.util.Framework.java
/** * Remove acentos e afins./*w w w.j av a 2 s.c o m*/ * * @param arg A string a ser convertida * @return A string processada */ public static String normalize(String arg) { arg = Normalizer.normalize(arg, Normalizer.Form.NFD); arg = arg.replaceAll("[^\\p{ASCII}]", ""); return arg; }
From source file:org.mycore.common.MCRUtils.java
private static String getHash(int iterations, byte[] salt, String text, String algorithm) throws NoSuchAlgorithmException { MessageDigest digest;//from www. j a v a 2 s .co m if (--iterations < 0) { iterations = 0; } byte[] data; try { digest = MessageDigest.getInstance(algorithm); text = Normalizer.normalize(text, Form.NFC); if (salt != null) { digest.update(salt); } data = digest.digest(text.getBytes("UTF-8")); for (int i = 0; i < iterations; i++) { data = digest.digest(data); } } catch (UnsupportedEncodingException e) { throw new MCRException("Could not get " + algorithm + " checksum", e); } return toHexString(data); }