Java Code Examples for com.ibm.icu.text.StringPrepParseException

The following examples show how to use com.ibm.icu.text.StringPrepParseException. These examples are extracted from open source projects. 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 Project: fitnotifications   Source File: IDNA2003.java    License: Apache License 2.0 5 votes vote down vote up
public static StringBuffer convertIDNToASCII(String src,int options)
        throws StringPrepParseException{

    char[] srcArr = src.toCharArray();
    StringBuffer result = new StringBuffer();
    int sepIndex=0;
    int oldSepIndex=0;
    for(;;){
        sepIndex = getSeparatorIndex(srcArr,sepIndex,srcArr.length);
        String label = new String(srcArr,oldSepIndex,sepIndex-oldSepIndex);
        //make sure this is not a root label separator.
        if(!(label.length()==0 && sepIndex==srcArr.length)){
            UCharacterIterator iter = UCharacterIterator.getInstance(label);
            result.append(convertToASCII(iter,options));
        }
        if(sepIndex==srcArr.length){
            break;
        }
        
        // increment the sepIndex to skip past the separator
        sepIndex++;
        oldSepIndex = sepIndex;
        result.append((char)FULL_STOP);
    }
    if(result.length() > MAX_DOMAIN_NAME_LENGTH){
        throw new StringPrepParseException("The output exceed the max allowed length.", StringPrepParseException.DOMAIN_NAME_TOO_LONG_ERROR);
    }
    return result;
}
 
Example 2
Source Project: fitnotifications   Source File: IDNA2003.java    License: Apache License 2.0 5 votes vote down vote up
public static StringBuffer convertIDNToUnicode(String src, int options)
        throws StringPrepParseException{
    
    char[] srcArr = src.toCharArray();
    StringBuffer result = new StringBuffer();
    int sepIndex=0;
    int oldSepIndex=0;
    for(;;){
        sepIndex = getSeparatorIndex(srcArr,sepIndex,srcArr.length);
        String label = new String(srcArr,oldSepIndex,sepIndex-oldSepIndex);
        if(label.length()==0 && sepIndex!=srcArr.length ){
            throw new StringPrepParseException("Found zero length lable after NamePrep.",StringPrepParseException.ZERO_LENGTH_LABEL);
        }
        UCharacterIterator iter = UCharacterIterator.getInstance(label);
        result.append(convertToUnicode(iter,options));
        if(sepIndex==srcArr.length){
            break;
        }
        // Unlike the ToASCII operation we don't normalize the label separators
        result.append(srcArr[sepIndex]);
        // increment the sepIndex to skip past the separator
        sepIndex++;
        oldSepIndex =sepIndex;
    }
    if(result.length() > MAX_DOMAIN_NAME_LENGTH){
        throw new StringPrepParseException("The output exceed the max allowed length.", StringPrepParseException.DOMAIN_NAME_TOO_LONG_ERROR);
    }
    return result;
}
 
Example 3
Source Project: trekarta   Source File: IDNA2003.java    License: GNU General Public License v3.0 5 votes vote down vote up
public static StringBuffer convertIDNToASCII(String src,int options)
        throws StringPrepParseException{

    char[] srcArr = src.toCharArray();
    StringBuffer result = new StringBuffer();
    int sepIndex=0;
    int oldSepIndex=0;
    for(;;){
        sepIndex = getSeparatorIndex(srcArr,sepIndex,srcArr.length);
        String label = new String(srcArr,oldSepIndex,sepIndex-oldSepIndex);
        //make sure this is not a root label separator.
        if(!(label.length()==0 && sepIndex==srcArr.length)){
            UCharacterIterator iter = UCharacterIterator.getInstance(label);
            result.append(convertToASCII(iter,options));
        }
        if(sepIndex==srcArr.length){
            break;
        }
        
        // increment the sepIndex to skip past the separator
        sepIndex++;
        oldSepIndex = sepIndex;
        result.append((char)FULL_STOP);
    }
    if(result.length() > MAX_DOMAIN_NAME_LENGTH){
        throw new StringPrepParseException("The output exceed the max allowed length.", StringPrepParseException.DOMAIN_NAME_TOO_LONG_ERROR);
    }
    return result;
}
 
Example 4
Source Project: trekarta   Source File: IDNA2003.java    License: GNU General Public License v3.0 5 votes vote down vote up
public static StringBuffer convertIDNToUnicode(String src, int options)
        throws StringPrepParseException{
    
    char[] srcArr = src.toCharArray();
    StringBuffer result = new StringBuffer();
    int sepIndex=0;
    int oldSepIndex=0;
    for(;;){
        sepIndex = getSeparatorIndex(srcArr,sepIndex,srcArr.length);
        String label = new String(srcArr,oldSepIndex,sepIndex-oldSepIndex);
        if(label.length()==0 && sepIndex!=srcArr.length ){
            throw new StringPrepParseException("Found zero length lable after NamePrep.",StringPrepParseException.ZERO_LENGTH_LABEL);
        }
        UCharacterIterator iter = UCharacterIterator.getInstance(label);
        result.append(convertToUnicode(iter,options));
        if(sepIndex==srcArr.length){
            break;
        }
        // Unlike the ToASCII operation we don't normalize the label separators
        result.append(srcArr[sepIndex]);
        // increment the sepIndex to skip past the separator
        sepIndex++;
        oldSepIndex =sepIndex;
    }
    if(result.length() > MAX_DOMAIN_NAME_LENGTH){
        throw new StringPrepParseException("The output exceed the max allowed length.", StringPrepParseException.DOMAIN_NAME_TOO_LONG_ERROR);
    }
    return result;
}
 
Example 5
Source Project: jxmpp   Source File: Icu4jXmppStringprep.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public String localprep(String string) throws XmppStringprepException {
	try {
		return NODEPREP.prepare(string, StringPrep.DEFAULT);
	} catch (StringPrepParseException e) {
		throw new XmppStringprepException(string, e);
	}
}
 
Example 6
Source Project: jxmpp   Source File: Icu4jXmppStringprep.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public String domainprep(String string) throws XmppStringprepException {
	try {
		return DOMAINPREP.prepare(string, StringPrep.DEFAULT);
	} catch (StringPrepParseException e) {
		throw new XmppStringprepException(string, e);
	}
}
 
Example 7
Source Project: jxmpp   Source File: Icu4jXmppStringprep.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public String resourceprep(String string) throws XmppStringprepException {
	try {
		return RESOURCEPREP.prepare(string, StringPrep.DEFAULT);
	} catch (StringPrepParseException e) {
		throw new XmppStringprepException(string, e);
	}
}
 
Example 8
Source Project: fitnotifications   Source File: IDNA2003.java    License: Apache License 2.0 4 votes vote down vote up
public static int compare(String s1, String s2, int options) throws StringPrepParseException{
    StringBuffer s1Out = convertIDNToASCII(s1, options);
    StringBuffer s2Out = convertIDNToASCII(s2, options);
    return compareCaseInsensitiveASCII(s1Out,s2Out);
}
 
Example 9
Source Project: trekarta   Source File: IDNA2003.java    License: GNU General Public License v3.0 4 votes vote down vote up
public static int compare(String s1, String s2, int options) throws StringPrepParseException{
    StringBuffer s1Out = convertIDNToASCII(s1, options);
    StringBuffer s2Out = convertIDNToASCII(s2, options);
    return compareCaseInsensitiveASCII(s1Out,s2Out);
}