public static byte[] MixedPrepare(byte[] src) { String s = Encoding.UTF8.GetString(src);; 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); // ICU4N: Checked 2nd parameter int i = FindStringIndex(special_prefixes, prefixString); String suffixString = s.Substring(index + 1, s.Length - (index + 1)); // ICU4N: Corrected 2nd parameter if (i > -1 && !suffixString.Equals("")) { throw new StringPrepParseException("Suffix following a special index", StringPrepErrorType.InvalidCharFound); } UCharacterIterator prefix = UCharacterIterator.GetInstance(prefixString); UCharacterIterator suffix = UCharacterIterator.GetInstance(suffixString); @out.Append(prep.nfsmxp.Prepare(prefix, StringPrepOptions.Default)); @out.Append(AT_SIGN); // add the delimiter @out.Append(prep.nfsmxs.Prepare(suffix, StringPrepOptions.Default)); } else { UCharacterIterator iter = UCharacterIterator.GetInstance(s); @out.Append(prep.nfsmxp.Prepare(iter, StringPrepOptions.Default)); } return(Encoding.UTF8.GetBytes(@out.ToString())); }
public static StringBuffer ConvertIDNToASCII(string src, IDNA2003Options options) { 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.", StringPrepErrorType.DomainNameTooLongError); } return(result); }
public static StringBuffer ConvertIDNToUnicode(String src, IDNA2003Options options) { 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.", StringPrepErrorType.ZeroLengthLabel); } 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.", StringPrepErrorType.DomainNameTooLongError); } return(result); }
public static StringBuffer ConvertIDNToASCII(String src, IDNA2003Options options) { 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); } return(result); }
public void TestJitterbug1952() { //test previous code point char[] src = new char[] { '\uDC00', '\uD800', '\uDC01', '\uD802', '\uDC02', '\uDC03' }; UCharacterIterator iter = UCharacterIterator.GetInstance(src); iter.Index = 1; int ch; // this should never go into a infinite loop // if it does then we have a problem while ((ch = iter.PreviousCodePoint()) != UCharacterIterator.DONE) { if (ch != 0xDc00) { Errln("iter.PreviousCodePoint() failed"); } } iter.Index = (5); while ((ch = iter.NextCodePoint()) != UCharacterIterator.DONE) { if (ch != 0xDC03) { Errln("iter.NextCodePoint() failed"); } } }
public static StringBuffer ConvertIDNToUnicode(String src, IDNA2003Options options) { 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.", StringPrepErrorType.ZeroLengthLabel); } UCharacterIterator iter = UCharacterIterator.GetInstance(label); result.Append(ConvertToUnicode(iter, options)); if (sepIndex == srcArr.Length) { break; } // increment the sepIndex to skip past the separator sepIndex++; oldSepIndex = sepIndex; result.Append((char)FULL_STOP); } return(result); }
private static byte[] Prepare(byte[] src, StringPrep strprep) { String s = Encoding.UTF8.GetString(src); UCharacterIterator iter = UCharacterIterator.GetInstance(s); StringBuffer @out = strprep.Prepare(iter, StringPrepOptions.Default); return(Encoding.UTF8.GetBytes(@out.ToString())); }
public StringBuffer Prepare(String src, StringPrepOptions options) { int ch; String mapOut = Map(src, options); UCharacterIterator iter = UCharacterIterator.GetInstance(mapOut); UCharacterDirection direction = UCharacterDirectionExtensions.CharDirectionCount, firstCharDir = UCharacterDirectionExtensions.CharDirectionCount; int rtlPos = -1, ltrPos = -1; bool rightToLeft = false, leftToRight = false; while ((ch = iter.NextCodePoint()) != UCharacterIterator.Done) { if (transform.prohibitedSet.Contains(ch) == true && ch != 0x0020) { throw new StringPrepParseException("A prohibited code point was found in the input", StringPrepErrorType.ProhibitedError, iter.GetText(), iter.Index); } direction = UChar.GetDirection(ch); if (firstCharDir == UCharacterDirectionExtensions.CharDirectionCount) { firstCharDir = direction; } if (direction == UCharacterDirection.LeftToRight) { leftToRight = true; ltrPos = iter.Index - 1; } if (direction == UCharacterDirection.RightToLeft || direction == UCharacterDirection.RightToLeftArabic) { rightToLeft = true; rtlPos = iter.Index - 1; } } // satisfy 2 if (leftToRight == true && rightToLeft == true) { throw new StringPrepParseException("The input does not conform to the rules for BiDi code points.", StringPrepErrorType.CheckBiDiError, iter.GetText(), (rtlPos > ltrPos) ? rtlPos : ltrPos); } //satisfy 3 if (rightToLeft == true && !((firstCharDir == UCharacterDirection.RightToLeft || firstCharDir == UCharacterDirection.RightToLeftArabic) && (direction == UCharacterDirection.RightToLeft || direction == UCharacterDirection.RightToLeftArabic)) ) { throw new StringPrepParseException("The input does not conform to the rules for BiDi code points.", StringPrepErrorType.CheckBiDiError, iter.GetText(), (rtlPos > ltrPos) ? rtlPos : ltrPos); } return(new StringBuffer(mapOut)); }
public void TestClone() { UCharacterIterator iterator = UCharacterIterator.GetInstance("testing"); UCharacterIterator cloned = (UCharacterIterator)iterator.Clone(); int completed = 0; while (completed != UCharacterIterator.DONE) { completed = iterator.Next(); if (completed != cloned.Next()) { Errln("Cloned operation failed"); } } }
private String Map(String src, StringPrepOptions options) { // map bool 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", StringPrepErrorType.UnassignedError); } } return(caseMapOut); }
public static StringBuffer Encode(StringBuffer input, char[] case_flags) { int[] @in = new int[input.Length]; int inLen = 0; int ch; StringBuffer result = new StringBuffer(); UCharacterIterator iter = UCharacterIterator.GetInstance(input); while ((ch = iter.NextCodePoint()) != UCharacterIterator.Done) { @in[inLen++] = ch; } int[] outLen = new int[1]; outLen[0] = input.Length * 4; char[] output = new char[outLen[0]]; int rc = punycode_success; for (; ;) { rc = Encode(inLen, @in, case_flags, outLen, output); if (rc == punycode_big_output) { outLen[0] = outLen[0] * 4; output = new char[outLen[0]]; // continue to convert continue; } break; } if (rc == punycode_success) { return(result.Append(output, 0, outLen[0])); } GetException(rc); return(result); }
public static StringBuffer ConvertToUnicode(StringBuffer src, IDNA2003Options options) { UCharacterIterator iter = UCharacterIterator.GetInstance(src); return(ConvertToUnicode(iter, options)); }
private void DoTestCompare(String s1, String s2, bool isEqual) { if (!IDNAReference.IsReady) { Logln("Transliterator is not available on this environment. Skipping doTestCompare."); return; } try { int retVal = IDNAReference.Compare(s1, s2, IDNA2003Options.Default); if (isEqual == true && retVal != 0) { Errln("Did not get the expected result for s1: " + Prettify(s1) + " s2: " + Prettify(s2)); } retVal = IDNAReference.Compare(new StringBuffer(s1), new StringBuffer(s2), IDNA2003Options.Default); if (isEqual == true && retVal != 0) { Errln("Did not get the expected result for s1: " + Prettify(s1) + " s2: " + Prettify(s2)); } retVal = IDNAReference.Compare(UCharacterIterator.GetInstance(s1), UCharacterIterator.GetInstance(s2), IDNA2003Options.Default); if (isEqual == true && retVal != 0) { Errln("Did not get the expected result for s1: " + Prettify(s1) + " s2: " + Prettify(s2)); } } catch (Exception e) { e.PrintStackTrace(); Errln("Unexpected exception thrown by IDNAReference.compare"); } try { int retVal = IDNAReference.Compare(s1, s2, IDNA2003Options.AllowUnassigned); if (isEqual == true && retVal != 0) { Errln("Did not get the expected result for s1: " + Prettify(s1) + " s2: " + Prettify(s2)); } retVal = IDNAReference.Compare(new StringBuffer(s1), new StringBuffer(s2), IDNA2003Options.AllowUnassigned); if (isEqual == true && retVal != 0) { Errln("Did not get the expected result for s1: " + Prettify(s1) + " s2: " + Prettify(s2)); } retVal = IDNAReference.Compare(UCharacterIterator.GetInstance(s1), UCharacterIterator.GetInstance(s2), IDNA2003Options.AllowUnassigned); if (isEqual == true && retVal != 0) { Errln("Did not get the expected result for s1: " + Prettify(s1) + " s2: " + Prettify(s2)); } } catch (Exception e) { Errln("Unexpected exception thrown by IDNAReference.compare"); } }
public void TestIterationUChar32() { String text = "\u0061\u0062\ud841\udc02\u20ac\ud7ff\ud842\udc06\ud801\udc00\u0061"; int c; int i; { UCharacterIterator iter = UCharacterIterator.GetInstance(text); String iterText = iter.GetText(); if (!iterText.Equals(text)) { Errln("iter.getText() failed"); } iter.Index = (1); if (iter.CurrentCodePoint != UTF16.CharAt(text, 1)) { Errln("Iterator didn't start out in the right place."); } iter.SetToStart(); c = iter.CurrentCodePoint; i = 0; i = iter.MoveCodePointIndex(1); c = iter.CurrentCodePoint; if (c != UTF16.CharAt(text, 1) || i != 1) { Errln("moveCodePointIndex(1) didn't work correctly expected " + Hex(c) + " got " + Hex(UTF16.CharAt(text, 1)) + " i= " + i); } i = iter.MoveCodePointIndex(2); c = iter.CurrentCodePoint; if (c != UTF16.CharAt(text, 4) || i != 4) { Errln("moveCodePointIndex(2) didn't work correctly expected " + Hex(c) + " got " + Hex(UTF16.CharAt(text, 4)) + " i= " + i); } i = iter.MoveCodePointIndex(-2); c = iter.CurrentCodePoint; if (c != UTF16.CharAt(text, 1) || i != 1) { Errln("moveCodePointIndex(-2) didn't work correctly expected " + Hex(c) + " got " + Hex(UTF16.CharAt(text, 1)) + " i= " + i); } iter.SetToLimit(); i = iter.MoveCodePointIndex(-2); c = iter.CurrentCodePoint; if (c != UTF16.CharAt(text, (text.Length - 3)) || i != (text.Length - 3)) { Errln("moveCodePointIndex(-2) didn't work correctly expected " + Hex(c) + " got " + Hex(UTF16.CharAt(text, (text.Length - 3))) + " i= " + i); } iter.SetToStart(); c = iter.CurrentCodePoint; i = 0; //testing first32PostInc, nextCodePointPostInc, setTostart i = 0; iter.SetToStart(); c = iter.Next(); if (c != UTF16.CharAt(text, i)) { Errln("first32PostInc failed. Expected->" + Hex(UTF16.CharAt(text, i)) + " Got-> " + Hex(c)); } if (iter.Index != UTF16.GetCharCount(c) + i) { Errln("getIndex() after first32PostInc() failed"); } iter.SetToStart(); i = 0; if (iter.Index != 0) { Errln("setToStart failed"); } Logln("Testing forward iteration..."); do { if (c != UCharacterIterator.DONE) { c = iter.NextCodePoint(); } if (c != UTF16.CharAt(text, i)) { Errln("Character mismatch at position " + i + ", iterator has " + Hex(c) + ", string has " + Hex(UTF16.CharAt(text, i))); } i += UTF16.GetCharCount(c); if (iter.Index != i) { Errln("getIndex() aftr nextCodePointPostInc() isn't working right"); } c = iter.CurrentCodePoint; if (c != UCharacterIterator.DONE && c != UTF16.CharAt(text, i)) { Errln("current() after nextCodePointPostInc() isn't working right"); } } while (c != UCharacterIterator.DONE); c = iter.NextCodePoint(); if (c != UCharacterIterator.DONE) { Errln("nextCodePointPostInc() didn't return DONE at the beginning"); } } }
public static StringBuffer ConvertToUnicode(UCharacterIterator src, IDNA2003Options options) { bool[] caseFlags = null; // the source contains all ascii codepoints bool srcIsASCII = true; // assume the source contains all LDH codepoints //bool srcIsLDH = true; //get the options //bool useSTD3ASCIIRules = ((options & USE_STD3_RULES) != 0); //int failPos = -1; int ch; int saveIndex = src.Index; // step 1: find out if all the codepoints in src are ASCII while ((ch = src.Next()) != UCharacterIterator.DONE) { if (ch > 0x7F) { srcIsASCII = false; }/*else if((srcIsLDH = isLDHChar(ch))==false){ * failPos = src.getIndex(); * }*/ } StringBuffer processOut; if (srcIsASCII == false) { try { // step 2: process the string src.Index = saveIndex; processOut = namePrep.Prepare(src, (StringPrepOptions)options); } catch (StringPrepParseException ex) { return(new StringBuffer(src.GetText())); } } else { //just point to source processOut = new StringBuffer(src.GetText()); } // TODO: // The RFC states that // <quote> // ToUnicode never fails. If any step fails, then the original input // is returned immediately in that step. // </quote> //step 3: verify ACE Prefix if (StartsWithPrefix(processOut)) { StringBuffer decodeOut = null; //step 4: Remove the ACE Prefix string temp = processOut.ToString(ACE_PREFIX.Length, processOut.Length - ACE_PREFIX.Length); //step 5: Decode using punycode try { decodeOut = new StringBuffer(Punycode.Decode(temp, caseFlags).ToString()); } catch (StringPrepParseException e) { decodeOut = null; } //step 6:Apply toASCII if (decodeOut != null) { StringBuffer toASCIIOut = ConvertToASCII(UCharacterIterator.GetInstance(decodeOut), options); //step 7: verify if (CompareCaseInsensitiveASCII(processOut, toASCIIOut) != 0) { // throw new StringPrepParseException("The verification step prescribed by the RFC 3491 failed", // StringPrepParseException.VERIFICATION_ERROR); decodeOut = null; } } //step 8: return output of step 5 if (decodeOut != null) { return(decodeOut); } } // }else{ // // verify that STD3 ASCII rules are satisfied // if(useSTD3ASCIIRules == true){ // if( srcIsLDH == false /* source contains some non-LDH characters */ // || processOut.charAt(0) == HYPHEN // || processOut.charAt(processOut.Length-1) == HYPHEN){ // // if(srcIsLDH==false){ // throw new StringPrepParseException("The input does not conform to the STD 3 ASCII rules", // StringPrepParseException.STD3_ASCII_RULES_ERROR,processOut.toString(), // (failPos>0) ? (failPos-1) : failPos); // }else if(processOut.charAt(0) == HYPHEN){ // throw new StringPrepParseException("The input does not conform to the STD 3 ASCII rules", // StringPrepParseException.STD3_ASCII_RULES_ERROR, // processOut.toString(),0); // // }else{ // throw new StringPrepParseException("The input does not conform to the STD 3 ASCII rules", // StringPrepParseException.STD3_ASCII_RULES_ERROR, // processOut.toString(), // processOut.Length); // // } // } // } // // just return the source // return new StringBuffer(src.getText()); // } return(new StringBuffer(src.GetText())); }
public void TestSetText(/* char* par */) { RuleBasedCollator en_us = (RuleBasedCollator)Collator.GetInstance(new CultureInfo("en-US")); CollationElementIterator iter1 = en_us.GetCollationElementIterator(test1); CollationElementIterator iter2 = en_us.GetCollationElementIterator(test2); // Run through the second iterator just to exercise it int c = iter2.Next(); int i = 0; while (++i < 10 && c != CollationElementIterator.NULLORDER) { try { c = iter2.Next(); } catch (Exception e) { Errln("iter2.Next() returned an error."); break; } } // Now set it to point to the same string as the first iterator try { iter2.SetText(test1); } catch (Exception e) { Errln("call to iter2->setText(test1) failed."); return; } assertEqual(iter1, iter2); iter1.Reset(); //now use the overloaded setText(ChracterIterator&, UErrorCode) function to set the text CharacterIterator chariter = new StringCharacterIterator(test1); try { iter2.SetText(chariter); } catch (Exception e) { Errln("call to iter2->setText(chariter(test1)) failed."); return; } assertEqual(iter1, iter2); iter1.Reset(); //now use the overloaded setText(ChracterIterator&, UErrorCode) function to set the text UCharacterIterator uchariter = UCharacterIterator.GetInstance(test1); try { iter2.SetText(uchariter); } catch (Exception e) { Errln("call to iter2->setText(uchariter(test1)) failed."); return; } assertEqual(iter1, iter2); }
public void TestNamePrepConformance() { try { NamePrepTransform namePrep = NamePrepTransform.GetInstance(); if (!namePrep.IsReady) { Logln("Transliterator is not available on this environment."); return; } for (int i = 0; i < TestData.conformanceTestCases.Length; i++) { TestData.ConformanceTestCase testCase = TestData.conformanceTestCases[i]; UCharacterIterator iter = UCharacterIterator.GetInstance(testCase.input); try { StringBuffer output = namePrep.Prepare(iter, NamePrepTransform.NONE); if (testCase.output != null && output != null && !testCase.output.Equals(output.ToString())) { Errln("Did not get the expected output. Expected: " + Prettify(testCase.output) + " Got: " + Prettify(output)); } if (testCase.expected != null && !unassignedException.Equals(testCase.expected)) { Errln("Did not get the expected exception. The operation succeeded!"); } } catch (StringPrepParseException ex) { if (testCase.expected == null || !ex.Equals(testCase.expected)) { Errln("Did not get the expected exception for source: " + testCase.input + " Got: " + ex.ToString()); } } try { iter.SetToStart(); StringBuffer output = namePrep.Prepare(iter, NamePrepTransform.ALLOW_UNASSIGNED); if (testCase.output != null && output != null && !testCase.output.Equals(output.ToString())) { Errln("Did not get the expected output. Expected: " + Prettify(testCase.output) + " Got: " + Prettify(output)); } if (testCase.expected != null && !unassignedException.Equals(testCase.expected)) { Errln("Did not get the expected exception. The operation succeeded!"); } } catch (StringPrepParseException ex) { if (testCase.expected == null || !ex.Equals(testCase.expected)) { Errln("Did not get the expected exception for source: " + testCase.input + " Got: " + ex.ToString()); } } } } catch (TypeInitializationException e) { Warnln("Could not load NamePrepTransformData"); } catch (TypeLoadException ex) { Warnln("Could not load NamePrepTransform data"); } }
public void TestPreviousNext() { // src and expect strings char[] src = { UTF16.GetLeadSurrogate(0x2f999), UTF16.GetTrailSurrogate(0x2f999), UTF16.GetLeadSurrogate(0x1d15f), UTF16.GetTrailSurrogate(0x1d15f), (char)0xc4, (char)0x1ed0 }; // iterators UCharacterIterator iter1 = UCharacterIterator.GetInstance(new ReplaceableString(new String(src))); UCharacterIterator iter2 = UCharacterIterator.GetInstance(src /*char array*/); UCharacterIterator iter3 = UCharacterIterator.GetInstance(new StringCharacterIterator(new String(src))); UCharacterIterator iter4 = UCharacterIterator.GetInstance(new StringBuffer(new String(src))); previousNext(iter1); previousNext(iter2); previousNext(iter3); previousNext(iter4); getText(iter1, new String(src)); getText(iter2, new String(src)); getText(iter3, new String(src)); /* getCharacterIterator */ CharacterIterator citer1 = iter1.GetCharacterIterator(); CharacterIterator citer2 = iter2.GetCharacterIterator(); CharacterIterator citer3 = iter3.GetCharacterIterator(); if (citer1.First() != iter1.Current) { Errln("getCharacterIterator for iter1 failed"); } if (citer2.First() != iter2.Current) { Errln("getCharacterIterator for iter2 failed"); } if (citer3.First() != iter3.Current) { Errln("getCharacterIterator for iter3 failed"); } /* Test clone() && moveIndex()*/ try { UCharacterIterator clone1 = (UCharacterIterator)iter1.Clone(); UCharacterIterator clone2 = (UCharacterIterator)iter2.Clone(); UCharacterIterator clone3 = (UCharacterIterator)iter3.Clone(); if (clone1.MoveIndex(3) != iter1.MoveIndex(3)) { Errln("moveIndex for iter1 failed"); } if (clone2.MoveIndex(3) != iter2.MoveIndex(3)) { Errln("moveIndex for iter2 failed"); } if (clone3.MoveIndex(3) != iter3.MoveIndex(3)) { Errln("moveIndex for iter1 failed"); } } catch (Exception e) { Errln("could not clone the iterator"); } }
public void TestIteration() { UCharacterIterator iterator = UCharacterIterator.GetInstance( ITERATION_STRING_); UCharacterIterator iterator2 = UCharacterIterator.GetInstance( ITERATION_STRING_); iterator.SetToStart(); if (iterator.Current != ITERATION_STRING_[0]) { Errln("Iterator failed retrieving first character"); } iterator.SetToLimit(); if (iterator.Previous() != ITERATION_STRING_[ ITERATION_STRING_.Length - 1]) { Errln("Iterator failed retrieving last character"); } if (iterator.Length != ITERATION_STRING_.Length) { Errln("Iterator failed determining begin and end index"); } iterator2.Index = 0; iterator.Index = 0; int ch = 0; while (ch != UCharacterIterator.DONE) { int index = iterator2.Index; ch = iterator2.NextCodePoint(); if (index != ITERATION_SUPPLEMENTARY_INDEX) { if (ch != iterator.Next() && ch != UCharacterIterator.DONE) { Errln("Error mismatch in next() and nextCodePoint()"); } } else { if (UTF16.GetLeadSurrogate(ch) != iterator.Next() || UTF16.GetTrailSurrogate(ch) != iterator.Next()) { Errln("Error mismatch in next and nextCodePoint for " + "supplementary characters"); } } } iterator.Index = ITERATION_STRING_.Length; iterator2.Index = ITERATION_STRING_.Length; while (ch != UCharacterIterator.DONE) { int index = iterator2.Index; ch = iterator2.PreviousCodePoint(); if (index != ITERATION_SUPPLEMENTARY_INDEX) { if (ch != iterator.Previous() && ch != UCharacterIterator.DONE) { Errln("Error mismatch in previous() and " + "previousCodePoint()"); } } else { if (UTF16.GetLeadSurrogate(ch) != iterator.Previous() || UTF16.GetTrailSurrogate(ch) != iterator.Previous()) { Errln("Error mismatch in previous and " + "previousCodePoint for supplementary characters"); } } } }
public void TestUCharacterIteratorWrapper() { String source = "asdfasdfjoiuyoiuy2341235679886765"; UCharacterIterator it = UCharacterIterator.GetInstance(source); CharacterIterator wrap_ci = it.GetCharacterIterator(); CharacterIterator ci = new StringCharacterIterator(source); wrap_ci.SetIndex(10); ci.SetIndex(10); String moves = "0+0+0--0-0-+++0--+++++++0--------++++0000----0-"; int c1, c2; char m; int movesIndex = 0; while (movesIndex < moves.Length) { m = moves[movesIndex++]; if (m == '-') { c1 = wrap_ci.Previous(); c2 = ci.Previous(); } else if (m == '0') { c1 = wrap_ci.Current; c2 = ci.Current; } else {// m=='+' c1 = wrap_ci.Next(); c2 = ci.Next(); } // compare results if (c1 != c2) { // copy the moves until the current (m) move, and terminate String history = moves.Substring(0, movesIndex - 0); // ICU4N: Checked 2nd parameter Errln("error: mismatch in Normalizer iteration at " + history + ": " + "got c1= " + Hex(c1) + " != expected c2= " + Hex(c2)); break; } // compare indexes if (wrap_ci.Index != ci.Index) { // copy the moves until the current (m) move, and terminate String history = moves.Substring(0, movesIndex - 0); // ICU4N: Checked 2nd parameter Errln("error: index mismatch in Normalizer iteration at " + history + " : " + "Normalizer index " + wrap_ci.Index + " expected " + ci.Index); break; } } if (ci.First() != wrap_ci.First()) { Errln("CharacterIteratorWrapper.First() failed. expected: " + ci.First() + " got: " + wrap_ci.First()); } if (ci.Last() != wrap_ci.Last()) { Errln("CharacterIteratorWrapper.Last() failed expected: " + ci.Last() + " got: " + wrap_ci.Last()); } if (ci.BeginIndex != wrap_ci.BeginIndex) { Errln("CharacterIteratorWrapper.BeginIndex failed expected: " + ci.BeginIndex + " got: " + wrap_ci.BeginIndex); } if (ci.EndIndex != wrap_ci.EndIndex) { Errln("CharacterIteratorWrapper.EndIndex failed expected: " + ci.EndIndex + " got: " + wrap_ci.EndIndex); } try { CharacterIterator cloneWCI = (CharacterIterator)wrap_ci.Clone(); if (wrap_ci.Index != cloneWCI.Index) { Errln("CharacterIteratorWrapper.Clone() failed expected: " + wrap_ci.Index + " got: " + cloneWCI.Index); } } catch (Exception e) { Errln("CharacterIterator.Clone() failed"); } }
/// <summary> /// Reset the filter from the delegate. /// </summary> private void ResetState() { text = UCharacterIterator.GetInstance((CharacterIterator)@delegate.Text.Clone()); }
private void DoTestIDNToASCII(String src, String expected, IDNA2003Options options, Object expectedException) { if (!IDNAReference.IsReady) { Logln("Transliterator is not available on this environment. Skipping doTestIDNToASCII."); return; } StringBuffer inBuf = new StringBuffer(src); UCharacterIterator inIter = UCharacterIterator.GetInstance(src); try { StringBuffer @out = IDNAReference.ConvertIDNToASCII(src, options); if (expected != null && @out != null && [email protected]().Equals(expected)) { Errln("convertToIDNAReferenceASCII did not return expected result with options : " + options + " Expected: " + expected + " Got: " + @out); } if (expectedException != null && !unassignedException.Equals(expectedException)) { Errln("convertToIDNAReferenceASCII did not get the expected exception. The operation succeeded!"); } } catch (StringPrepParseException ex) { if (expectedException == null || !ex.Equals(expectedException)) { Errln("convertToIDNAReferenceASCII did not get the expected exception for source: " + src + " Got: " + ex.ToString()); } } try { StringBuffer @out = IDNAReference.ConvertIDNtoASCII(inBuf, options); if (expected != null && @out != null && [email protected]().Equals(expected)) { Errln("convertToIDNAReferenceASCII did not return expected result with options : " + options + " Expected: " + expected + " Got: " + @out); } if (expectedException != null && !unassignedException.Equals(expectedException)) { Errln("convertToIDNAReferenceSCII did not get the expected exception. The operation succeeded!"); } } catch (StringPrepParseException ex) { if (expectedException == null || !ex.Equals(expectedException)) { Errln("convertToIDNAReferenceSCII did not get the expected exception for source: " + src + " Got: " + ex.ToString()); } } try { StringBuffer @out = IDNAReference.ConvertIDNtoASCII(inIter, options); if (expected != null && @out != null && [email protected]().Equals(expected)) { Errln("convertIDNToASCII did not return expected result with options : " + options + " Expected: " + expected + " Got: " + @out); } if (expectedException != null && !unassignedException.Equals(expectedException)) { Errln("convertIDNToASCII did not get the expected exception. The operation succeeded!"); } } catch (StringPrepParseException ex) { if (expectedException == null || !ex.Equals(expectedException)) { Errln("convertIDNToASCII did not get the expected exception for source: " + src + " Got: " + ex.ToString()); } } }