예제 #1
0
 public void ReduceLength()
 {
     using (var buffer = new StringBuffer("Food"))
     {
         Assert.Equal((ulong)5, buffer.CharCapacity);
         buffer.Length = 3;
         Assert.Equal("Foo", buffer.ToString());
         // Shouldn't reduce capacity when dropping length
         Assert.Equal((ulong)5, buffer.CharCapacity);
     }
 }
예제 #2
0
        static void Main(string[] args)
        {
            var f = new StringBuffer();
            f.AppendFormat(formatTest, v1, v2);
            Console.WriteLine(f.ToString());
            Console.WriteLine(formatTest, v1, v2);

            // test custom formatters
            StringBuffer.SetCustomFormatter<Blah>(CustomFormat);
            f.Clear();
            f.AppendFormat("Hello {0:yes}{0:no}", new Blah { Thing = 42 });
            Console.WriteLine(f.ToString());

            // test static convenience method
            Console.WriteLine(StringBuffer.Format(formatTest, v1, v2));

            PerfTest();
            #if DEBUG
            Console.ReadLine();
            #endif
        }
예제 #3
0
        public unsafe void CreateFromString()
        {
            string testString = "Test";
            using (var buffer = new StringBuffer(testString))
            {
                Assert.Equal((ulong)testString.Length, buffer.Length);
                Assert.Equal((ulong)testString.Length + 1, buffer.CharCapacity);

                for (int i = 0; i < testString.Length; i++)
                {
                    Assert.Equal(testString[i], buffer[(ulong)i]);
                }

                // Check the null termination
                Assert.Equal('\0', buffer.CharPointer[testString.Length]);

                Assert.Equal(testString, buffer.ToString());
            }
        }
예제 #4
0
        private static string NewGetCurrentDirectory()
        {
            using (StringBuffer buffer = new StringBuffer(PathInternal.MaxShortPath))
            {
                uint result = 0;
                while ((result = Win32Native.GetCurrentDirectoryW(buffer.CharCapacity, buffer.GetHandle())) > buffer.CharCapacity)
                {
                    // Reported size is greater than the buffer size. Increase the capacity.
                    // The size returned includes the null only if more space is needed (this case).
                    buffer.EnsureCharCapacity(result);
                }

                if (result == 0)
                    __Error.WinIOError();

                buffer.Length = result;

#if !PLATFORM_UNIX
                if (buffer.Contains('~'))
                    return LongPathHelper.GetLongPathName(buffer);
#endif

                return buffer.ToString();
            }
        }
예제 #5
0
        unsafe internal static string GetLongPathName(string path)
        {
            using (StringBuffer outputBuffer = new StringBuffer((uint)path.Length))
            {
                uint result = 0;
                while ((result = Win32Native.GetLongPathNameW(path, outputBuffer.GetHandle(), outputBuffer.CharCapacity)) > outputBuffer.CharCapacity)
                {
                    // Reported size (which does not include the null) is greater than the buffer size. Increase the capacity.
                    outputBuffer.EnsureCharCapacity(result);
                }

                if (result == 0)
                {
                    // Failure, get the error and throw
                    GetErrorAndThrow(path);
                }

                outputBuffer.Length = result;
                return outputBuffer.ToString();
            }
        }
예제 #6
0
 public void CopyToBufferString(string destination, string content, ulong destinationIndex, ulong bufferIndex, ulong count, string expected)
 {
     using (var buffer = new StringBuffer(content))
     using (var destinationBuffer = new StringBuffer(destination))
     {
         buffer.CopyTo(bufferIndex, destinationBuffer, destinationIndex, count);
         Assert.Equal(expected, destinationBuffer.ToString());
     }
 }
예제 #7
0
 public void CopyFromString(string content, string source, ulong bufferIndex, int sourceIndex, int count, string expected)
 {
     using (var buffer = new StringBuffer(content))
     {
         buffer.CopyFrom(bufferIndex, source, sourceIndex, count);
         Assert.Equal(expected, buffer.ToString());
     }
 }
예제 #8
0
 public void TrimEnd(string content, char[] trimChars, string expected)
 {
     // We want equivalence with built-in string behavior
     using (var buffer = new StringBuffer(content))
     {
         buffer.TrimEnd(trimChars);
         Assert.Equal(expected, buffer.ToString());
     }
 }
예제 #9
0
        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());
            }
        }
예제 #10
0
파일: Directory.cs 프로젝트: kouvel/coreclr
         /*===============================CurrentDirectory===============================
        **Action:  Provides a getter and setter for the current directory.  The original
        **         current DirectoryInfo is the one from which the process was started.  
        **Returns: The current DirectoryInfo (from the getter).  Void from the setter.
        **Arguments: The current DirectoryInfo to which to switch to the setter.
        **Exceptions: 
        ==============================================================================*/
        public static String GetCurrentDirectory()
        {
            // Start with a buffer the size of MAX_PATH
            using (StringBuffer buffer = new StringBuffer(260))
            {
                uint result = 0;
                while ((result = Win32Native.GetCurrentDirectoryW(buffer.CharCapacity, buffer.GetHandle())) > buffer.CharCapacity)
                {
                    // Reported size is greater than the buffer size. Increase the capacity.
                    // The size returned includes the null only if more space is needed (this case).
                    buffer.EnsureCharCapacity(result);
                }

                if (result == 0)
                    __Error.WinIOError();

                buffer.Length = result;

#if !PLATFORM_UNIX
                if (buffer.Contains('~'))
                    return Path.GetFullPath(buffer.ToString());
#endif

                return buffer.ToString();
            }
        }