java.text.Normalizer Java Examples

The following examples show how to use java.text.Normalizer. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: HttpUtils.java    From drftpd with GNU General Public License v2.0 6 votes vote down vote up
public static String htmlToString(String input) {
    String str = input.replaceAll("\n", "");
    str = StringEscapeUtils.unescapeHtml4(str);
    str = Normalizer.normalize(str, Normalizer.Form.NFD);
    str = str.replaceAll("\\P{InBasic_Latin}", "");
    while (str.contains("<")) {
        int startPos = str.indexOf("<");
        int endPos = str.indexOf(">", startPos);
        if (endPos > startPos) {
            String beforeTag = str.substring(0, startPos);
            String afterTag = str.substring(endPos + 1);
            str = beforeTag + afterTag;
        }
    }
    return str;
}
 
Example #2
Source File: NormalizeUnicodeUDF.java    From incubator-hivemall with Apache License 2.0 6 votes vote down vote up
@Nullable
public String evaluate(@Nullable String str, @Nullable String form) {
    if (str == null) {
        return null;
    }
    if (form == null) {
        return Normalizer.normalize(str, Normalizer.Form.NFC);
    } else if ("NFC".equals(form)) {
        return Normalizer.normalize(str, Normalizer.Form.NFC);
    } else if ("NFD".equals(form)) {
        return Normalizer.normalize(str, Normalizer.Form.NFD);
    } else if ("NFKC".equals(form)) {
        return Normalizer.normalize(str, Normalizer.Form.NFKC);
    } else if ("NFKD".equals(form)) {
        return Normalizer.normalize(str, Normalizer.Form.NFKD);
    } else {
        return Normalizer.normalize(str, Normalizer.Form.NFC);
    }
}
 
Example #3
Source File: ParsedIRI.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private String pctEncodingNormalization(String path) {
	if (path == null || path.length() == 0 || path.indexOf('%') < 0) {
		return path; // no pct encodings
	}
	String[] encodings = listPctEncodings(path);
	StringBuilder sb = new StringBuilder(path);
	int pos = 0;
	for (String encoding : encodings) {
		int idx = sb.indexOf(encoding, pos);
		String decoded = normalizePctEncoding(encoding);
		sb.replace(idx, idx + encoding.length(), decoded);
		pos += decoded.length();
	}
	return Normalizer.normalize(sb, Normalizer.Form.NFC);

}
 
Example #4
Source File: NormalizerBase.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Test if a string is in a given normalization form.
 * This is semantically equivalent to source.equals(normalize(source, mode)).
 *
 * Unlike quickCheck(), this function returns a definitive result,
 * never a "maybe".
 * For NFD, NFKD, and FCD, both functions work exactly the same.
 * For NFC and NFKC where quickCheck may return "maybe", this function will
 * perform further tests to arrive at a true/false result.
 * @param str       the input string to be checked to see if it is normalized
 * @param form      the normalization form
 * @param options   the optional features to be enabled.
 */
public static boolean isNormalized(String str, Normalizer.Form form, int options) {
    switch (form) {
    case NFC:
        return (NFC.quickCheck(str.toCharArray(),0,str.length(),false,NormalizerImpl.getNX(options))==YES);
    case NFD:
        return (NFD.quickCheck(str.toCharArray(),0,str.length(),false,NormalizerImpl.getNX(options))==YES);
    case NFKC:
        return (NFKC.quickCheck(str.toCharArray(),0,str.length(),false,NormalizerImpl.getNX(options))==YES);
    case NFKD:
        return (NFKD.quickCheck(str.toCharArray(),0,str.length(),false,NormalizerImpl.getNX(options))==YES);
    }

    throw new IllegalArgumentException("Unexpected normalization form: " +
                                       form);
}
 
Example #5
Source File: NormalizerBase.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Test if a string is in a given normalization form.
 * This is semantically equivalent to source.equals(normalize(source, mode)).
 *
 * Unlike quickCheck(), this function returns a definitive result,
 * never a "maybe".
 * For NFD, NFKD, and FCD, both functions work exactly the same.
 * For NFC and NFKC where quickCheck may return "maybe", this function will
 * perform further tests to arrive at a true/false result.
 * @param str       the input string to be checked to see if it is normalized
 * @param form      the normalization form
 * @param options   the optional features to be enabled.
 */
public static boolean isNormalized(String str, Normalizer.Form form, int options) {
    switch (form) {
    case NFC:
        return (NFC.quickCheck(str.toCharArray(),0,str.length(),false,NormalizerImpl.getNX(options))==YES);
    case NFD:
        return (NFD.quickCheck(str.toCharArray(),0,str.length(),false,NormalizerImpl.getNX(options))==YES);
    case NFKC:
        return (NFKC.quickCheck(str.toCharArray(),0,str.length(),false,NormalizerImpl.getNX(options))==YES);
    case NFKD:
        return (NFKD.quickCheck(str.toCharArray(),0,str.length(),false,NormalizerImpl.getNX(options))==YES);
    }

    throw new IllegalArgumentException("Unexpected normalization form: " +
                                       form);
}
 
Example #6
Source File: MCRUtils.java    From mycore with GNU General Public License v3.0 6 votes vote down vote up
private static String getHash(int iterations, byte[] salt, String text, String algorithm)
    throws NoSuchAlgorithmException {
    MessageDigest digest;
    if (--iterations < 0) {
        iterations = 0;
    }
    byte[] data;
    digest = MessageDigest.getInstance(algorithm);
    text = Normalizer.normalize(text, Form.NFC);
    if (salt != null) {
        digest.update(salt);
    }
    data = digest.digest(text.getBytes(StandardCharsets.UTF_8));
    for (int i = 0; i < iterations; i++) {
        data = digest.digest(data);
    }
    return toHexString(data);
}
 
Example #7
Source File: NormalizerBase.java    From jdk8u_jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Test if a string is in a given normalization form.
 * This is semantically equivalent to source.equals(normalize(source, mode)).
 *
 * Unlike quickCheck(), this function returns a definitive result,
 * never a "maybe".
 * For NFD, NFKD, and FCD, both functions work exactly the same.
 * For NFC and NFKC where quickCheck may return "maybe", this function will
 * perform further tests to arrive at a true/false result.
 * @param str       the input string to be checked to see if it is normalized
 * @param form      the normalization form
 * @param options   the optional features to be enabled.
 */
public static boolean isNormalized(String str, Normalizer.Form form, int options) {
    switch (form) {
    case NFC:
        return (NFC.quickCheck(str.toCharArray(),0,str.length(),false,NormalizerImpl.getNX(options))==YES);
    case NFD:
        return (NFD.quickCheck(str.toCharArray(),0,str.length(),false,NormalizerImpl.getNX(options))==YES);
    case NFKC:
        return (NFKC.quickCheck(str.toCharArray(),0,str.length(),false,NormalizerImpl.getNX(options))==YES);
    case NFKD:
        return (NFKD.quickCheck(str.toCharArray(),0,str.length(),false,NormalizerImpl.getNX(options))==YES);
    }

    throw new IllegalArgumentException("Unexpected normalization form: " +
                                       form);
}
 
Example #8
Source File: TutorialCommand.java    From KaellyBot with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void request(Message message, Matcher m, Language lg) {
    String normalName = Normalizer.normalize(m.group(1).trim(), Normalizer.Form.NFD)
            .replaceAll("\\p{InCombiningDiacriticalMarks}+", "").toLowerCase();
    String editedName = removeUselessWords(normalName);
    BestMatcher matcher = new BestMatcher(normalName);

    try {
        matcher.evaluateAll(getListTutoFrom(getSearchURL(editedName), message));

        if (matcher.isUnique())// We have found it !
            message.getChannel().flatMap(chan -> chan
                    .createMessage(Translator.getLabel(lg, "tutorial.request") + " " +
                            Constants.dofusPourLesNoobURL + matcher.getBest().getUrl()))
                    .subscribe();
        else if (! matcher.isEmpty())  // Too much tutos
            tooMuchTutos.throwException(message, this, lg, matcher.getBests());
        else // empty
            notFoundTuto.throwException(message, this, lg);
    } catch(IOException e){
        ExceptionManager.manageIOException(e, message, this, lg, notFoundTuto);
    }
}
 
Example #9
Source File: StringUtil.java    From Kepler with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Filter input.
 *
 * @param input the input
 * @param filerNewline if new lines (ENTER) should be filtered
 * @return the string
 */
public static String filterInput(String input, boolean filerNewline) {
    input = input.replace((char)1, ' ');
    input = input.replace((char)2, ' ');
    input = input.replace((char)9, ' ');
    input = input.replace((char)10, ' ');
    input = input.replace((char)12, ' ');

    if (filerNewline) {
        input = input.replace((char)13, ' ');
    }

    if (GameConfiguration.getInstance().getBoolean("normalise.input.strings")) {
        input = Normalizer.normalize(input, Normalizer.Form.NFD);
    }
    
    return input;
}
 
Example #10
Source File: DefaultEncryptionProtocol.java    From armadillo with Apache License 2.0 5 votes vote down vote up
private byte[] keyDerivationFunction(String contentKey, byte[] fingerprint, byte[] contentSalt, byte[] preferenceSalt, @Nullable char[] password) {
    Bytes ikm = Bytes.from(fingerprint, contentSalt, Bytes.from(contentKey, Normalizer.Form.NFKD).array());

    if (password != null) {
        byte[] stretched;
        if ((stretched = derivedPasswordCache.get(contentSalt, password)) == null) {
            stretched = defaultConfig.keyStretchingFunction.stretch(contentSalt, password, STRETCHED_PASSWORD_LENGTH_BYTES);
            derivedPasswordCache.put(contentSalt, password, stretched);
        }
        ikm = ikm.append(stretched);
    }

    return HKDF.fromHmacSha512().extractAndExpand(preferenceSalt, ikm.array(), Bytes.from("DefaultEncryptionProtocol").array(), keyLengthBit / 8);
}
 
Example #11
Source File: ProductInstanceBinaryResource.java    From eplmp with Eclipse Public License 1.0 5 votes vote down vote up
private String uploadAFileToPathData(String workspaceId, Part formPart, String configurationItemId, String serialNumber, int pathDataId, int iteration)
        throws EntityNotFoundException, EntityAlreadyExistsException, AccessRightException, NotAllowedException, CreationException, UserNotActiveException, StorageException, IOException, WorkspaceNotEnabledException {

    String fileName = Normalizer.normalize(formPart.getSubmittedFileName(), Normalizer.Form.NFC);
    // Init the binary resource with a null length
    BinaryResource binaryResource = productInstanceManagerLocal.saveFileInPathData(workspaceId, configurationItemId, serialNumber, pathDataId, iteration, fileName, 0);
    OutputStream outputStream = storageManager.getBinaryResourceOutputStream(binaryResource);
    long length = BinaryResourceUpload.uploadBinary(outputStream, formPart);
    productInstanceManagerLocal.saveFileInPathData(workspaceId, configurationItemId, serialNumber, pathDataId, iteration, fileName, (int) length);
    return fileName;
}
 
Example #12
Source File: BytesConstructorTests.java    From bytes-java with Apache License 2.0 5 votes vote down vote up
private void checkString(String string, Charset charset) {
    Bytes b = Bytes.from(string, charset);
    assertArrayEquals(string.getBytes(charset), b.array());
    assertEquals(new String(string.getBytes(charset), charset), b.encodeCharset(charset));

    if (charset != StandardCharsets.UTF_8) {
        Bytes bUtf8 = Bytes.from(string);
        assertArrayEquals(string.getBytes(StandardCharsets.UTF_8), bUtf8.array());
        assertEquals(new String(string.getBytes(StandardCharsets.UTF_8), StandardCharsets.UTF_8), bUtf8.encodeUtf8());
    } else {
        Bytes bNormalized = Bytes.from(string, Normalizer.Form.NFKD);
        assertArrayEquals(Normalizer.normalize(string, Normalizer.Form.NFKD).getBytes(charset), bNormalized.array());
    }
}
 
Example #13
Source File: NetStringUtil.java    From cronet with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Attempts to convert text in a given character set to a Unicode string,
 * and normalize it.  Returns null on failure.
 * @param text ByteBuffer containing the character array to convert.
 * @param charsetName Character set it's in encoded in.
 * @return: Unicode string on success, null on failure.
 */
@CalledByNative
private static String convertToUnicodeAndNormalize(
        ByteBuffer text,
        String charsetName) {
    String unicodeString = convertToUnicode(text, charsetName);
    if (unicodeString == null) return null;
    return Normalizer.normalize(unicodeString, Normalizer.Form.NFC);
}
 
Example #14
Source File: JabArchivesRipper.java    From ripme with MIT License 5 votes vote down vote up
protected String getSlug(String input) {
    // Get a URL/file-safe version of a string
    String nowhitespace = WHITESPACE.matcher(input).replaceAll("-");
    String normalized = Normalizer.normalize(nowhitespace, Form.NFD);
    String slug = NONLATIN.matcher(normalized).replaceAll("");
    return slug.toLowerCase(Locale.ENGLISH);
}
 
Example #15
Source File: BIP38PrivateKey.java    From green_android with GNU General Public License v3.0 5 votes vote down vote up
public ECKey decrypt(String passphrase) throws BadPassphraseException {
    String normalizedPassphrase = Normalizer.normalize(passphrase, Normalizer.Form.NFC);
    ECKey key = ecMultiply ? decryptEC(normalizedPassphrase) : decryptNoEC(normalizedPassphrase);
    Sha256Hash hash = Sha256Hash.twiceOf(key.toAddress(params).toString().getBytes(Charsets.US_ASCII));
    byte[] actualAddressHash = Arrays.copyOfRange(hash.getBytes(), 0, 4);
    if (!Arrays.equals(actualAddressHash, addressHash))
        throw new BadPassphraseException();
    return key;
}
 
Example #16
Source File: DslMethodsGen.java    From doov with Apache License 2.0 5 votes vote down vote up
private static String formatMethod(String readable) {
    String slug = readable
            .replace(".", " ")
            .replace(" and ", " ")
            .replace(" the ", " ")
            .replace(" à ", " ")
            .replace(" d'", " ")
            .replace(" a ", " ")
            .replace(" l'", " ")
            .replace(" du ", " ")
            .replace(" au ", " ")
            .replace(" en ", " ")
            .replace(" de ", " ")
            .replace(" un ", " ")
            .replace(" la ", " ")
            .replace(" le ", " ")
            .replace(" une ", " ")
            .replace(" aux ", " ")
            .replace(" des ", " ")
            .replace(" pour ", " ")
            .replace(" avec ", " ")
            .replaceAll("( )+", " ");
    String underscore = WHITESPACE.matcher(slug).replaceAll("_");
    String normalized = Normalizer.normalize(underscore, Normalizer.Form.NFD);
    String latin = NONLATIN.matcher(normalized).replaceAll("").toLowerCase(Locale.ENGLISH);
    return CaseFormat.LOWER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL, latin);
}
 
Example #17
Source File: DocumentBinaryResource.java    From eplmp with Eclipse Public License 1.0 5 votes vote down vote up
private String uploadAFile(Part formPart, DocumentIterationKey docPK)
        throws EntityNotFoundException, EntityAlreadyExistsException, AccessRightException, NotAllowedException, CreationException, UserNotActiveException, StorageException, IOException, WorkspaceNotEnabledException {

    String fileName = Normalizer.normalize(formPart.getSubmittedFileName(), Normalizer.Form.NFC);
    // Init the binary resource with a null length
    BinaryResource binaryResource = documentService.saveFileInDocument(docPK, fileName, 0);
    OutputStream outputStream = storageManager.getBinaryResourceOutputStream(binaryResource);
    long length = BinaryResourceUpload.uploadBinary(outputStream, formPart);
    documentService.saveFileInDocument(docPK, fileName, length);
    return fileName;
}
 
Example #18
Source File: StringUtils.java    From icure-backend with GNU General Public License v2.0 5 votes vote down vote up
public static String removeDiacriticalMarks(String key) {
	try {
		if (Normalizer.class.getMethod("normalize", CharSequence.class, Normalizer.Form.class) != null) {
			return Normalizer.normalize(key.replaceAll("ø","o").replaceAll("æ","ae").replaceAll("Æ","AE").replaceAll("Œ","oe").replaceAll("œ","oe"), Normalizer.Form.NFD)
					.replaceAll("\\p{InCombiningDiacriticalMarks}", "");
		}
	} catch (NoSuchMethodException ignored) {
	}

	//Fallback
	return key.replaceAll("[\u00E8\u00E9\u00EA\u00EB]", "e")
			.replaceAll("[\u00FB\u00F9\u00FC]", "u")
			.replaceAll("[\u00E7]", "c")
			.replaceAll("[\u00EF\u00EE\u00EC]", "i")
			.replaceAll("[\u00E0\u00E2\u00E4]", "a")
			.replaceAll("[\u00F6\u00F2\u00F4]", "o")
			.replaceAll("[\u00C8\u00C9\u00CA\u00CB]", "E")
			.replaceAll("[\u00DB\u00D9\u00DC]", "U")
			.replaceAll("[\u00CF\u00CE\u00CC]", "I")
			.replaceAll("[\u00C0\u00C2\u00C4]", "A")
			.replaceAll("[\u00D4\u00D6\u00D2]", "O")
			.replaceAll("ø","o")
			.replaceAll("æ","ae")
			.replaceAll("Æ","AE")
		.replaceAll("Œ","oe")
		.replaceAll("œ","oe");
}
 
Example #19
Source File: SlugUtils.java    From halo with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Slugify string.
 *
 * @param input input string must not be blank
 * @return slug string
 */
@NonNull
@Deprecated
public static String slugify(@NonNull String input) {
    Assert.hasText(input, "Input string must not be blank");

    String withoutWhitespace = WHITESPACE.matcher(input).replaceAll("-");
    String normalized = Normalizer.normalize(withoutWhitespace, Normalizer.Form.NFKD);
    String slug = NON_LATIN.matcher(normalized).replaceAll("");
    return slug.toLowerCase(Locale.ENGLISH);
}
 
Example #20
Source File: WordListMapNormalization.java    From BlockchainWallet-Crypto with GNU General Public License v3.0 5 votes vote down vote up
WordListMapNormalization(final WordList wordList) {
    for (int i = 0; i < 1 << 11; i++) {
        final String word = wordList.getWord(i);
        final String normalized = Normalizer.normalize(word, Normalizer.Form.NFKD);
        normalizedMap.put(word, normalized);
        normalizedMap.put(normalized, normalized);
        normalizedMap.put(Normalizer.normalize(word, Normalizer.Form.NFC), normalized);
    }
}
 
Example #21
Source File: NormalizerBase.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Normalizes a <code>String</code> using the given normalization form.
 *
 * @param str      the input string to be normalized.
 * @param form     the normalization form
 * @param options   the optional features to be enabled.
 */
public static String normalize(String str, Normalizer.Form form, int options) {
    int len = str.length();
    boolean asciiOnly = true;
    if (len < 80) {
        for (int i = 0; i < len; i++) {
            if (str.charAt(i) > 127) {
                asciiOnly = false;
                break;
            }
        }
    } else {
        char[] a = str.toCharArray();
        for (int i = 0; i < len; i++) {
            if (a[i] > 127) {
                asciiOnly = false;
                break;
            }
        }
    }

    switch (form) {
    case NFC :
        return asciiOnly ? str : NFC.normalize(str, options);
    case NFD :
        return asciiOnly ? str : NFD.normalize(str, options);
    case NFKC :
        return asciiOnly ? str : NFKC.normalize(str, options);
    case NFKD :
        return asciiOnly ? str : NFKD.normalize(str, options);
    }

    throw new IllegalArgumentException("Unexpected normalization form: " +
                                       form);
}
 
Example #22
Source File: NormalizerBase.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Normalizes a <code>String</code> using the given normalization form.
 *
 * @param str      the input string to be normalized.
 * @param form     the normalization form
 * @param options   the optional features to be enabled.
 */
public static String normalize(String str, Normalizer.Form form, int options) {
    int len = str.length();
    boolean asciiOnly = true;
    if (len < 80) {
        for (int i = 0; i < len; i++) {
            if (str.charAt(i) > 127) {
                asciiOnly = false;
                break;
            }
        }
    } else {
        char[] a = str.toCharArray();
        for (int i = 0; i < len; i++) {
            if (a[i] > 127) {
                asciiOnly = false;
                break;
            }
        }
    }

    switch (form) {
    case NFC :
        return asciiOnly ? str : NFC.normalize(str, options);
    case NFD :
        return asciiOnly ? str : NFD.normalize(str, options);
    case NFKC :
        return asciiOnly ? str : NFKC.normalize(str, options);
    case NFKD :
        return asciiOnly ? str : NFKD.normalize(str, options);
    }

    throw new IllegalArgumentException("Unexpected normalization form: " +
                                       form);
}
 
Example #23
Source File: NormalizerBase.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Normalizes a <code>String</code> using the given normalization form.
 *
 * @param str      the input string to be normalized.
 * @param form     the normalization form
 * @param options   the optional features to be enabled.
 */
public static String normalize(String str, Normalizer.Form form, int options) {
    int len = str.length();
    boolean asciiOnly = true;
    if (len < 80) {
        for (int i = 0; i < len; i++) {
            if (str.charAt(i) > 127) {
                asciiOnly = false;
                break;
            }
        }
    } else {
        char[] a = str.toCharArray();
        for (int i = 0; i < len; i++) {
            if (a[i] > 127) {
                asciiOnly = false;
                break;
            }
        }
    }

    switch (form) {
    case NFC :
        return asciiOnly ? str : NFC.normalize(str, options);
    case NFD :
        return asciiOnly ? str : NFD.normalize(str, options);
    case NFKC :
        return asciiOnly ? str : NFKC.normalize(str, options);
    case NFKD :
        return asciiOnly ? str : NFKD.normalize(str, options);
    }

    throw new IllegalArgumentException("Unexpected normalization form: " +
                                       form);
}
 
Example #24
Source File: ReScuePattern.java    From ReScue with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Attempts to compose input by combining the first character
 * with the first combining mark following it. Returns a String
 * that is the composition of the leading character with its first
 * combining mark followed by the remaining combining marks. Returns
 * null if the first two characters cannot be further composed.
 */
private String composeOneStep(String input) {
    int len = countChars(input, 0, 2);
    String firstTwoCharacters = input.substring(0, len);
    String result = Normalizer.normalize(firstTwoCharacters, Normalizer.Form.NFC);

    if (result.equals(firstTwoCharacters))
        return null;
    else {
        String remainder = input.substring(len);
        return result + remainder;
    }
}
 
Example #25
Source File: ReScuePattern.java    From ReScue with GNU General Public License v2.0 5 votes vote down vote up
/**
 * The pattern is converted to normalizedD form and then a pure group
 * is constructed to match canonical equivalences of the characters.
 */
private void normalize() {
    boolean inCharClass = false;
    int lastCodePoint = -1;

    // Convert pattern into normalizedD form
    normalizedPattern = Normalizer.normalize(pattern, Normalizer.Form.NFD);
    patternLength = normalizedPattern.length();

    // Modify pattern to match canonical equivalences
    StringBuilder newPattern = new StringBuilder(patternLength);
    for(int i=0; i<patternLength; ) {
        int c = normalizedPattern.codePointAt(i);
        StringBuilder sequenceBuffer;
        if ((Character.getType(c) == Character.NON_SPACING_MARK)
            && (lastCodePoint != -1)) {
            sequenceBuffer = new StringBuilder();
            sequenceBuffer.appendCodePoint(lastCodePoint);
            sequenceBuffer.appendCodePoint(c);
            while(Character.getType(c) == Character.NON_SPACING_MARK) {
                i += Character.charCount(c);
                if (i >= patternLength)
                    break;
                c = normalizedPattern.codePointAt(i);
                sequenceBuffer.appendCodePoint(c);
            }
            String ea = produceEquivalentAlternation(
                                           sequenceBuffer.toString());
            newPattern.setLength(newPattern.length()-Character.charCount(lastCodePoint));
            newPattern.append("(?:").append(ea).append(")");
        } else if (c == '[' && lastCodePoint != '\\') {
            i = normalizeCharClass(newPattern, i);
        } else {
            newPattern.appendCodePoint(c);
        }
        lastCodePoint = c;
        i += Character.charCount(c);
    }
    normalizedPattern = newPattern.toString();
}
 
Example #26
Source File: RegularFileObject.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean isNameCompatible(String cn, JavaFileObject.Kind kind) {
    cn.getClass();
    // null check
    if (kind == Kind.OTHER && getKind() != kind) {
        return false;
    }
    String n = cn + kind.extension;
    if (name.equals(n)) {
        return true;
    }
    if (isMacOS && Normalizer.isNormalized(name, Normalizer.Form.NFD)
        && Normalizer.isNormalized(n, Normalizer.Form.NFC)) {
        // On Mac OS X it is quite possible to file name and class
        // name normalized in a different way - in that case we have to normalize file name
        // to the Normal Form Compised (NFC)
        String normName = Normalizer.normalize(name, Normalizer.Form.NFC);
        if (normName.equals(n)) {
            this.name = normName;
            return true;
        }
    }

        if (name.equalsIgnoreCase(n)) {
        try {
            // allow for Windows
            return file.getCanonicalFile().getName().equals(n);
        } catch (IOException e) {
        }
    }
    return false;
}
 
Example #27
Source File: PinHasher.java    From mollyim-android with GNU General Public License v3.0 5 votes vote down vote up
public static byte[] normalize(String pin) {
  pin = pin.trim();

  if (PinString.allNumeric(pin)) {
    pin = PinString.toArabic(pin);
  }

  pin = Normalizer.normalize(pin, Normalizer.Form.NFKD);

  return pin.getBytes(StandardCharsets.UTF_8);
}
 
Example #28
Source File: Bip39.java    From guarda-android-wallets with GNU General Public License v3.0 5 votes vote down vote up
@SuppressWarnings("NewApi")
private MasterSeed(byte[] bip39RawEntropy, String bip39Passphrase, byte[] bip32MasterSeed) {
   _bip39RawEntropy = bip39RawEntropy;
   _bip39Passphrase = Normalizer.normalize(bip39Passphrase, Normalizer.Form.NFKD);
   _bip32MasterSeed = bip32MasterSeed;
   _wordListType = ENGLISH_WORD_LIST_TYPE;
}
 
Example #29
Source File: BestMatcher.java    From KaellyBot with GNU General Public License v3.0 5 votes vote down vote up
public BestMatcher(String base){
    this.base = Normalizer.normalize(base.trim(), Normalizer.Form.NFD)
            .replaceAll("\\p{InCombiningDiacriticalMarks}+", "")
            .toLowerCase();
    this.pattern = this.base.split("\\s+");
    bestMatches = new ArrayList<>();
    bestPoint = 0;
}
 
Example #30
Source File: RegularFileObject.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean isNameCompatible(String cn, JavaFileObject.Kind kind) {
    cn.getClass();
    // null check
    if (kind == Kind.OTHER && getKind() != kind) {
        return false;
    }
    String n = cn + kind.extension;
    if (name.equals(n)) {
        return true;
    }
    if (isMacOS && Normalizer.isNormalized(name, Normalizer.Form.NFD)
        && Normalizer.isNormalized(n, Normalizer.Form.NFC)) {
        // On Mac OS X it is quite possible to file name and class
        // name normalized in a different way - in that case we have to normalize file name
        // to the Normal Form Compised (NFC)
        String normName = Normalizer.normalize(name, Normalizer.Form.NFC);
        if (normName.equals(n)) {
            this.name = normName;
            return true;
        }
    }

        if (name.equalsIgnoreCase(n)) {
        try {
            // allow for Windows
            return file.getCanonicalFile().getName().equals(n);
        } catch (IOException e) {
        }
    }
    return false;
}