PrevChar() public static method

Decrement an index into a string, allowing for surrogates. Assumes ich is pointing at the START of a character; will move back two if the two characters at ich-1 and ich-2 are a pair.
public static PrevChar ( string st, int ich ) : int
st string
ich int
return int
示例#1
0
 public void TestSurrogates()
 {
     Assert.AreEqual(1, Surrogates.NextChar("ab\xD800\xDC00c", 0));
     Assert.AreEqual(2, Surrogates.NextChar("ab\xD800\xDC00c", 1));
     Assert.AreEqual(4, Surrogates.NextChar("ab\xD800\xDC00c", 2));
     Assert.AreEqual(5, Surrogates.NextChar("ab\xD800\xDC00c", 4));
     Assert.AreEqual(4, Surrogates.NextChar("ab\xD800\xDC00", 2));
     Assert.AreEqual(3, Surrogates.NextChar("ab\xD800", 2), "Badly formed pair at end...don't go too far");
     Assert.AreEqual(3, Surrogates.NextChar("ab\xD800c", 2), "Badly formed pair in middle...don't go too far");
     Assert.AreEqual(0, Surrogates.PrevChar("ab\xD800\xDC00c", 1));
     Assert.AreEqual(1, Surrogates.PrevChar("ab\xD800\xDC00c", 2));
     Assert.AreEqual(2, Surrogates.PrevChar("ab\xD800\xDC00c", 3), "initial ich at a bad position, move back normally to sync");
     Assert.AreEqual(2, Surrogates.PrevChar("ab\xD800\xDC00c", 4), "double move succeeds");
     Assert.AreEqual(4, Surrogates.PrevChar("ab\xD800\xDC00c", 5));
     Assert.AreEqual(3, Surrogates.PrevChar("ab\xD800c", 4), "no double move on bad pair");
     Assert.AreEqual(0, Surrogates.PrevChar("\xD800\xDC00c", 2), "double move succeeds at start (and end)");
     Assert.AreEqual(0, Surrogates.PrevChar("\xDC00c", 1), "no double move on bad trailer at start");
     Assert.AreEqual(0, Surrogates.PrevChar("\xD800c", 1), "no double move on bad leader at start");
 }
示例#2
0
 [TestCase(new[] { '\xD800', 'c' }, 1, Result = 0)]           // no double move on bad leader at start
 public int PrevChar_InvalidChar(char[] st, int ich)
 {
     // NUnit doesn't allow tests with invalid strings in a testcase, so we create the
     // string from the character array when running the test
     return(Surrogates.PrevChar(new string(st), ich));
 }
示例#3
0
 [TestCase("\xD800\xDC00c", 2, Result = 0)]         // double move succeeds at start (and end)
 public int PrevChar(string st, int ich)
 {
     return(Surrogates.PrevChar(st, ich));
 }