/// <summary> /// Appends a substring of the specified string pointer to the <see cref="StringBuilder"/>. /// </summary> /// <param name="sb">The <see cref="StringBuilder"/> to which to append the value.</param> /// <param name="ptr">A pointer to the unmanaged string that contains the substring to append.</param> /// <param name="offset">The offset into the string at which the substring begins.</param> /// <param name="length">The length of the substring.</param> public static void AppendStringPtr(this StringBuilder sb, StringPtr8 ptr, Int32 offset, Int32 length) { Contract.Require(sb, "sb"); if (ptr == StringPtr8.Zero) return; for (int i = offset; i < offset + length; i++) { sb.Append(ptr[i]); } }
public void StringPtr8_HandlesNullTerminatedString() { unsafe { var data = new byte[] { (byte)'H', (byte)'e', (byte)'l', (byte)'l', (byte)'o', 0 }; fixed(byte *pdata = data) { var ptr = new StringPtr8((IntPtr)pdata); TheResultingString(ptr.ToString()) .ShouldBe("Hello"); } } }
public void StringPtr8_HandlesNullTerminatedString() { unsafe { var data = new byte[] { (byte)'H', (byte)'e', (byte)'l', (byte)'l', (byte)'o', 0 }; fixed (byte* pdata = data) { var ptr = new StringPtr8((IntPtr)pdata); TheResultingString(ptr.ToString()) .ShouldBe("Hello"); } } }
/// <summary> /// Appends the specified string pointer to the <see cref="StringBuilder"/>. /// </summary> /// <param name="sb">The <see cref="StringBuilder"/> to which to append the value.</param> /// <param name="ptr">A pointer to the unmanaged string to append.</param> public static void AppendStringPtr(this StringBuilder sb, StringPtr8 ptr) { AppendStringPtr(sb, ptr, 0, ptr.Length); }