/// <summary> /// Interprets stored bytes as UTF8 bytes, returning the /// resulting string /// </summary> public string Utf8ToString() { CharsRef @ref = new CharsRef(Length); UnicodeUtil.UTF8toUTF16(Bytes, Offset, Length, @ref); return(@ref.ToString()); }
public virtual void TestAppendChars() { char[] chars = new char[] { 'a', 'b', 'c', 'd' }; CharsRef c = new CharsRef(chars, 1, 3); // bcd c.Append(new char[] { 'e' }, 0, 1); Assert.AreEqual("bcde", c.ToString()); }
public virtual void TestCopyCharsRef() { char[] chars = new char[] { 'a', 'b', 'c', 'd' }; CharsRef c = new CharsRef(chars, 1, 3); // bcd char[] otherchars = new char[] { 'b', 'c', 'd', 'e' }; c.CopyChars(new CharsRef(otherchars, 0, 4)); Assert.AreEqual("bcde", c.ToString()); }
public virtual void TestCopy() { int numIters = AtLeast(10); for (int i = 0; i < numIters; i++) { CharsRef @ref = new CharsRef(); char[] charArray = TestUtil.RandomRealisticUnicodeString(Random, 1, 100).ToCharArray(); int offset = Random.Next(charArray.Length); int length = charArray.Length - offset; string str = new string(charArray, offset, length); @ref.CopyChars(charArray, offset, length); Assert.AreEqual(str, @ref.ToString()); } }
public virtual void TestUTF8UTF16CharsRef() { int num = AtLeast(3989); for (int i = 0; i < num; i++) { string unicode = TestUtil.RandomRealisticUnicodeString(Random); BytesRef @ref = new BytesRef(unicode); char[] arr = new char[1 + Random.Next(100)]; int offset = Random.Next(arr.Length); int len = Random.Next(arr.Length - offset); CharsRef cRef = new CharsRef(arr, offset, len); UnicodeUtil.UTF8toUTF16(@ref, cRef); Assert.AreEqual(cRef.ToString(), unicode); } }
public virtual void TestAppend() { CharsRef @ref = new CharsRef(); StringBuilder builder = new StringBuilder(); int numStrings = AtLeast(10); for (int i = 0; i < numStrings; i++) { char[] charArray = TestUtil.RandomRealisticUnicodeString(Random, 1, 100).ToCharArray(); int offset = Random.Next(charArray.Length); int length = charArray.Length - offset; builder.Append(charArray, offset, length); @ref.Append(charArray, offset, length); } Assert.AreEqual(builder.ToString(), @ref.ToString()); }