Пример #1
0
 private static bool NormalizeAndCheckString(
 string charString,
 int start,
 int length,
 Normalization form)
 {
     int i = start;
     var norm = new NormalizerInput(
        charString,
        start,
        length,
        form);
     var ch = 0;
     int endIndex = start + length;
     while ((ch = norm.ReadChar()) >= 0) {
       int c = charString[i];
       if ((c & 0x1ffc00) == 0xd800 && i + 1 < endIndex &&
       charString[i + 1] >= 0xdc00 && charString[i + 1] <= 0xdfff) {
     // Get the Unicode code point for the surrogate pair
     c = 0x10000 + ((c - 0xd800) << 10) + (charString[i + 1] - 0xdc00);
     ++i;
       } else if ((c & 0x1ff800) == 0xd800) {
     // unpaired surrogate
     return false;
       }
       ++i;
       if (c != ch) {
     return false;
       }
     }
     return i == endIndex;
 }
Пример #2
0
 /// <include file='../../docs.xml'
 /// path='docs/doc[@name="M:PeterO.Text.Normalizer.#ctor(System.String,PeterO.Text.Normalization)"]/*'/>
 public Normalizer(string str, Normalization form)
 {
     this.nci = new NormalizerInput(str, form);
 }
Пример #3
0
     private static bool NormalizeAndCheck(
 int[] charArray,
 int start,
 int length,
 Normalization form)
     {
         var i = 0;
         int ch;
         var input = new NormalizerInput(
         new PartialArrayCharacterInput(charArray, start, length),
         form);
         while ((ch = input.ReadChar()) >= 0) {
             if (i >= length) {
                 return false;
             }
             if (ch != charArray[start + i]) {
                 return false;
             }
             ++i;
         }
         return i == length;
     }
Пример #4
0
 public void TestRead()
 {
     var nci = new NormalizerInput("test");
       try {
     nci.Read(null, 0, 0);
     Assert.Fail("Should have failed");
       } catch (ArgumentNullException) {
     new Object();
     } catch (Exception ex) {
     Assert.Fail(ex.ToString());
     throw new InvalidOperationException(String.Empty, ex);
       }
       try {
     nci.Read(new int[] { 't' }, -1, 1);
     Assert.Fail("Should have failed");
       } catch (ArgumentException) {
     new Object();
     } catch (Exception ex) {
     Assert.Fail(ex.ToString());
     throw new InvalidOperationException(String.Empty, ex);
       }
       try {
     nci.Read(new int[] { 't' }, 5, 1);
     Assert.Fail("Should have failed");
       } catch (ArgumentException) {
     new Object();
     } catch (Exception ex) {
     Assert.Fail(ex.ToString());
     throw new InvalidOperationException(String.Empty, ex);
       }
       try {
     nci.Read(new int[] { 't' }, 0, -1);
     Assert.Fail("Should have failed");
       } catch (ArgumentException) {
     new Object();
     } catch (Exception ex) {
     Assert.Fail(ex.ToString());
     throw new InvalidOperationException(String.Empty, ex);
       }
       try {
     nci.Read(new int[] { 't' }, 0, 5);
     Assert.Fail("Should have failed");
       } catch (ArgumentException) {
     new Object();
     } catch (Exception ex) {
     Assert.Fail(ex.ToString());
     throw new InvalidOperationException(String.Empty, ex);
       }
       try {
     nci.Read(new int[] { 't', 't' }, 1, 2);
     Assert.Fail("Should have failed");
       } catch (ArgumentException) {
     new Object();
     } catch (Exception ex) {
     Assert.Fail(ex.ToString());
     throw new InvalidOperationException(String.Empty, ex);
       }
       Assert.AreEqual(1, nci.Read(new int[] { 't', 't' }, 1, 1));
 }