本文整理汇总了C#中System.Runtime.InteropServices.StringBuffer.Append方法的典型用法代码示例。如果您正苦于以下问题:C# StringBuffer.Append方法的具体用法?C# StringBuffer.Append怎么用?C# StringBuffer.Append使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Runtime.InteropServices.StringBuffer
的用法示例。
在下文中一共展示了StringBuffer.Append方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CustomFormat
static void CustomFormat(StringBuffer buffer, Blah blah, StringView format)
{
if (format == "yes")
buffer.Append("World!");
else
buffer.Append("(Goodbye)");
}
示例2: ReduceLength
public void ReduceLength()
{
using (var buffer = new StringBuffer())
{
buffer.Append("Food");
Assert.Equal((uint)5, buffer.CharCapacity);
buffer.Length = 3;
Assert.Equal("Foo", buffer.ToString());
// Shouldn't reduce capacity when dropping length
Assert.Equal((uint)5, buffer.CharCapacity);
}
}
示例3: CreateFromString
public unsafe void CreateFromString()
{
string testString = "Test";
using (var buffer = new StringBuffer())
{
buffer.Append(testString);
Assert.Equal((uint)testString.Length, buffer.Length);
Assert.Equal((uint)testString.Length + 1, buffer.CharCapacity);
for (int i = 0; i < testString.Length; i++)
{
Assert.Equal(testString[i], buffer[(uint)i]);
}
// Check the null termination
Assert.Equal('\0', buffer.CharPointer[testString.Length]);
Assert.Equal(testString, buffer.ToString());
}
}
示例4: TryExpandShortFileName
private unsafe static string TryExpandShortFileName(StringBuffer outputBuffer, string originalPath)
{
// We guarantee we'll expand short names for paths that only partially exist. As such, we need to find the part of the path that actually does exist. To
// avoid allocating like crazy we'll create only one input array and modify the contents with embedded nulls.
Contract.Assert(!PathInternal.IsPartiallyQualified(outputBuffer), "should have resolved by now");
using (StringBuffer inputBuffer = new StringBuffer(outputBuffer))
{
bool success = false;
uint lastIndex = outputBuffer.Length - 1;
uint foundIndex = lastIndex;
uint rootLength = PathInternal.GetRootLength(outputBuffer);
while (!success)
{
uint result = Win32Native.GetLongPathNameW(inputBuffer.GetHandle(), outputBuffer.GetHandle(), outputBuffer.CharCapacity);
// Replace any temporary null we added
if (inputBuffer[foundIndex] == '\0') inputBuffer[foundIndex] = '\\';
if (result == 0)
{
// Look to see if we couldn't find the file
int error = Marshal.GetLastWin32Error();
if (error != Win32Native.ERROR_FILE_NOT_FOUND && error != Win32Native.ERROR_PATH_NOT_FOUND)
{
// Some other failure, give up
break;
}
// We couldn't find the path at the given index, start looking further back in the string.
foundIndex--;
for (; foundIndex > rootLength && inputBuffer[foundIndex] != '\\'; foundIndex--) ;
if (foundIndex == rootLength)
{
// Can't trim the path back any further
break;
}
else
{
// Temporarily set a null in the string to get Windows to look further up the path
inputBuffer[foundIndex] = '\0';
}
}
else if (result > outputBuffer.CharCapacity)
{
// Not enough space. The result count for this API does not include the null terminator.
outputBuffer.EnsureCharCapacity(result);
}
else
{
// Found the path
success = true;
outputBuffer.Length = result;
if (foundIndex < lastIndex)
{
// It was a partial find, put the non-existant part of the path back
outputBuffer.Append(inputBuffer, foundIndex, inputBuffer.Length - foundIndex);
}
}
}
StringBuffer bufferToUse = success ? outputBuffer : inputBuffer;
if (bufferToUse.SubstringEquals(originalPath))
{
// Use the original path to avoid allocating
return originalPath;
}
return bufferToUse.ToString();
}
}
示例5: AppendOverCountWithIndexThrows
public void AppendOverCountWithIndexThrows()
{
using (var buffer = new StringBuffer())
{
Assert.Throws<ArgumentOutOfRangeException>(() => buffer.Append("A", startIndex: 1, count: 1));
}
}
示例6: AppendNegativeIndexThrows
public void AppendNegativeIndexThrows()
{
using (var buffer = new StringBuffer())
{
Assert.Throws<ArgumentOutOfRangeException>(() => buffer.Append("a", startIndex: -1));
}
}
示例7: AppendNullStringBufferThrows
public void AppendNullStringBufferThrows()
{
using (var buffer = new StringBuffer())
{
Assert.Throws<ArgumentNullException>(() => buffer.Append((StringBuffer)null));
}
}
示例8: AppendTests
public void AppendTests(string source, string value, int startIndex, int count, string expected)
{
// From string
using (var buffer = new StringBuffer(source))
{
buffer.Append(value, startIndex, count);
Assert.Equal(expected, buffer.ToString());
}
// From buffer
using (var buffer = new StringBuffer(source))
using (var valueBuffer = new StringBuffer(value))
{
if (count == -1)
buffer.Append(valueBuffer, (ulong)startIndex, valueBuffer.Length - (ulong)startIndex);
else
buffer.Append(valueBuffer, (ulong)startIndex, (ulong)count);
Assert.Equal(expected, buffer.ToString());
}
}
示例9: StartsWith
public void StartsWith(string source, string value, bool expected)
{
using (var buffer = new StringBuffer())
{
buffer.Append(source);
Assert.Equal(expected, buffer.StartsWith(value));
}
}
示例10: CopyToBufferString
public void CopyToBufferString(string destination, string content, uint destinationIndex, uint bufferIndex, uint count, string expected)
{
using (var buffer = new StringBuffer())
using (var destinationBuffer = new StringBuffer())
{
buffer.Append(content);
destinationBuffer.Append(destination);
buffer.CopyTo(bufferIndex, destinationBuffer, destinationIndex, count);
Assert.Equal(expected, destinationBuffer.ToString());
}
}
示例11: SubstringEqualsOverSizeCountWithIndexThrows
public void SubstringEqualsOverSizeCountWithIndexThrows()
{
using (var buffer = new StringBuffer())
{
buffer.Append("A");
Assert.Throws<ArgumentOutOfRangeException>(() => buffer.SubstringEquals("", startIndex: 1, count: 1));
}
}
示例12: TrimEnd
public void TrimEnd(string content, char[] trimChars, string expected)
{
// We want equivalence with built-in string behavior
using (var buffer = new StringBuffer())
{
buffer.Append(content);
buffer.TrimEnd(trimChars);
Assert.Equal(expected, buffer.ToString());
}
}
示例13: CopyFromString
public void CopyFromString(string content, string source, uint bufferIndex, int sourceIndex, int count, string expected)
{
using (var buffer = new StringBuffer())
{
buffer.Append(content);
buffer.CopyFrom(bufferIndex, source, sourceIndex, count);
Assert.Equal(expected, buffer.ToString());
}
}
示例14: SetLengthToFirstNullTests
public unsafe void SetLengthToFirstNullTests(string content, ulong startLength, ulong endLength)
{
using (var buffer = new StringBuffer())
{
buffer.Append(content);
// With existing content
Assert.Equal(startLength, buffer.Length);
buffer.SetLengthToFirstNull();
Assert.Equal(endLength, buffer.Length);
// Clear the buffer & manually copy in
buffer.Length = 0;
fixed (char* contentPointer = content)
{
Buffer.MemoryCopy(contentPointer, buffer.CharPointer, (long)buffer.CharCapacity * 2, content.Length * sizeof(char));
}
Assert.Equal((uint)0, buffer.Length);
buffer.SetLengthToFirstNull();
Assert.Equal(endLength, buffer.Length);
}
}
示例15: SetLengthToFirstNullNoNull
public unsafe void SetLengthToFirstNullNoNull()
{
using (var buffer = new StringBuffer())
{
buffer.Append("A");
// Wipe out the last null
buffer.CharPointer[buffer.Length] = 'B';
buffer.SetLengthToFirstNull();
Assert.Equal((ulong)1, buffer.Length);
}
}