use of android.icu.text.StringPrepParseException in project j2objc by google.
the class NFS4StringPrep method mixed_prepare.
public static byte[] mixed_prepare(byte[] src) throws IOException, StringPrepParseException, UnsupportedEncodingException {
String s = new String(src, "UTF-8");
int index = s.indexOf(AT_SIGN);
StringBuffer out = new StringBuffer();
if (index > -1) {
/* special prefixes must not be followed by suffixes! */
String prefixString = s.substring(0, index);
int i = findStringIndex(special_prefixes, prefixString);
String suffixString = s.substring(index + 1, s.length());
if (i > -1 && !suffixString.equals("")) {
throw new StringPrepParseException("Suffix following a special index", StringPrepParseException.INVALID_CHAR_FOUND);
}
UCharacterIterator prefix = UCharacterIterator.getInstance(prefixString);
UCharacterIterator suffix = UCharacterIterator.getInstance(suffixString);
out.append(prep.nfsmxp.prepare(prefix, StringPrep.DEFAULT));
// add the delimiter
out.append(AT_SIGN);
out.append(prep.nfsmxs.prepare(suffix, StringPrep.DEFAULT));
} else {
UCharacterIterator iter = UCharacterIterator.getInstance(s);
out.append(prep.nfsmxp.prepare(iter, StringPrep.DEFAULT));
}
return out.toString().getBytes("UTF-8");
}
use of android.icu.text.StringPrepParseException in project j2objc by google.
the class TestIDNA method doTestIDNToUnicode.
private void doTestIDNToUnicode(String src, String expected, int options, Object expectedException) throws Exception {
StringBuffer inBuf = new StringBuffer(src);
UCharacterIterator inIter = UCharacterIterator.getInstance(src);
try {
StringBuffer out = IDNA.convertIDNToUnicode(src, options);
if (expected != null && out != null && !out.toString().equals(expected)) {
errln("convertToUnicode did not return expected result with options : " + options + " Expected: " + prettify(expected) + " Got: " + prettify(out));
}
if (expectedException != null && !unassignedException.equals(expectedException)) {
errln("convertToUnicode did not get the expected exception. The operation succeeded!");
}
} catch (StringPrepParseException ex) {
if (expectedException == null || !expectedException.equals(ex)) {
errln("convertToUnicode did not get the expected exception for source: " + src + " Got: " + ex.toString());
}
}
try {
StringBuffer out = IDNA.convertIDNToUnicode(inBuf, options);
if (expected != null && out != null && !out.toString().equals(expected)) {
errln("convertToUnicode did not return expected result with options : " + options + " Expected: " + prettify(expected) + " Got: " + out);
}
if (expectedException != null && !unassignedException.equals(expectedException)) {
errln("convertToUnicode did not get the expected exception. The operation succeeded!");
}
} catch (StringPrepParseException ex) {
if (expectedException == null || !expectedException.equals(ex)) {
errln("convertToUnicode did not get the expected exception for source: " + src + " Got: " + ex.toString());
}
}
try {
StringBuffer out = IDNA.convertIDNToUnicode(inIter, options);
if (expected != null && out != null && !out.toString().equals(expected)) {
errln("convertToUnicode did not return expected result with options : " + options + " Expected: " + prettify(expected) + " Got: " + prettify(out));
}
if (expectedException != null && !unassignedException.equals(expectedException)) {
errln("Did not get the expected exception. The operation succeeded!");
}
} catch (StringPrepParseException ex) {
if (expectedException == null || !expectedException.equals(ex)) {
errln("Did not get the expected exception for source: " + src + " Got: " + ex.toString());
}
}
}
use of android.icu.text.StringPrepParseException in project j2objc by google.
the class TestIDNA method doTestToUnicode.
private void doTestToUnicode(String src, String expected, int options, Object expectedException) throws Exception {
StringBuffer inBuf = new StringBuffer(src);
UCharacterIterator inIter = UCharacterIterator.getInstance(src);
try {
StringBuffer out = IDNA.convertToUnicode(src, options);
if (expected != null && out != null && !out.toString().equals(expected)) {
errln("convertToUnicode did not return expected result with options : " + options + " Expected: " + prettify(expected) + " Got: " + prettify(out));
}
if (expectedException != null && !unassignedException.equals(expectedException)) {
errln("convertToUnicode did not get the expected exception. The operation succeeded!");
}
} catch (StringPrepParseException ex) {
if (expectedException == null || !ex.equals(expectedException)) {
errln("convertToUnicode did not get the expected exception for source: " + prettify(src) + " Got: " + ex.toString());
}
}
try {
StringBuffer out = IDNA.convertToUnicode(inBuf, options);
if (expected != null && out != null && !out.toString().equals(expected)) {
errln("convertToUnicode did not return expected result with options : " + options + " Expected: " + prettify(expected) + " Got: " + out);
}
if (expectedException != null && !unassignedException.equals(expectedException)) {
errln("convertToUnicode did not get the expected exception. The operation succeeded!");
}
} catch (StringPrepParseException ex) {
if (expectedException == null || !ex.equals(expectedException)) {
errln("convertToUnicode did not get the expected exception for source: " + prettify(src) + " Got: " + ex.toString());
}
}
try {
StringBuffer out = IDNA.convertToUnicode(inIter, options);
if (expected != null && out != null && !out.toString().equals(expected)) {
errln("convertToUnicode did not return expected result with options : " + options + " Expected: " + prettify(expected) + " Got: " + prettify(out));
}
if (expectedException != null && !unassignedException.equals(expectedException)) {
errln("Did not get the expected exception. The operation succeeded!");
}
} catch (StringPrepParseException ex) {
if (expectedException == null || !ex.equals(expectedException)) {
errln("Did not get the expected exception for source: " + prettify(src) + " Got: " + ex.toString());
}
}
}
use of android.icu.text.StringPrepParseException in project j2objc by google.
the class NamePrepTransform method map.
private String map(String src, int options) throws StringPrepParseException {
// map
boolean allowUnassigned = ((options & ALLOW_UNASSIGNED) > 0);
// disable test
String caseMapOut = mapTransform.transliterate(src);
UCharacterIterator iter = UCharacterIterator.getInstance(caseMapOut);
int ch;
while ((ch = iter.nextCodePoint()) != UCharacterIterator.DONE) {
if (transform.unassignedSet.contains(ch) == true && allowUnassigned == false) {
throw new StringPrepParseException("An unassigned code point was found in the input", StringPrepParseException.UNASSIGNED_ERROR);
}
}
return caseMapOut;
}
Aggregations