From bc92643c99695b0caa41c0e32e210861a904f3ec Mon Sep 17 00:00:00 2001 From: disarray2077 <86157825+disarray2077@users.noreply.github.com> Date: Sat, 1 Jan 2022 21:14:09 -0300 Subject: [PATCH 1/5] Add InvalidFileNameChars & InvalidPathChars to Path class --- BeefLibs/corlib/src/IO/Path.bf | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/BeefLibs/corlib/src/IO/Path.bf b/BeefLibs/corlib/src/IO/Path.bf index 270f345c..00a69c41 100644 --- a/BeefLibs/corlib/src/IO/Path.bf +++ b/BeefLibs/corlib/src/IO/Path.bf @@ -34,6 +34,38 @@ namespace System.IO #else public const char8 VolumeSeparatorChar = '/'; #endif //BF_PLATFORM_WINDOWS + +#if BF_PLATFORM_WINDOWS + public static readonly char8[?] InvalidFileNameChars = + .( + '\"', '<', '>', '|', '\0', + (.)1, (.)2, (.)3, (.)4, (.)5, (.)6, (.)7, (.)8, (.)9, (.)10, + (.)11, (.)12, (.)13, (.)14, (.)15, (.)16, (.)17, (.)18, (.)19, (.)20, + (.)21, (.)22, (.)23, (.)24, (.)25, (.)26, (.)27, (.)28, (.)29, (.)30, + (.)31, ':', '*', '?', '\\', '/' + ); +#else + public static readonly char8[?] InvalidFileNameChars = + .( + '\0', '/' + ); +#endif //BF_PLATFORM_WINDOWS + +#if BF_PLATFORM_WINDOWS + public static readonly char8[?] InvalidPathChars = + .( + '|', '\0', + (.)1, (.)2, (.)3, (.)4, (.)5, (.)6, (.)7, (.)8, (.)9, (.)10, + (.)11, (.)12, (.)13, (.)14, (.)15, (.)16, (.)17, (.)18, (.)19, (.)20, + (.)21, (.)22, (.)23, (.)24, (.)25, (.)26, (.)27, (.)28, (.)29, (.)30, + (.)31 + ); +#else + public static readonly char8[?] InvalidPathChars = + .( + '\0' + ); +#endif //BF_PLATFORM_WINDOWS // Make this public sometime. // The max total path is 260, and the max individual component length is 255. From 4acc2cca677124c827bca69990c1150d43dd78ef Mon Sep 17 00:00:00 2001 From: disarray2077 <86157825+disarray2077@users.noreply.github.com> Date: Sat, 1 Jan 2022 21:19:44 -0300 Subject: [PATCH 2/5] Add doAppend parameter to WriteAllLines --- BeefLibs/corlib/src/IO/File.bf | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/BeefLibs/corlib/src/IO/File.bf b/BeefLibs/corlib/src/IO/File.bf index 555a6d95..31ef4530 100644 --- a/BeefLibs/corlib/src/IO/File.bf +++ b/BeefLibs/corlib/src/IO/File.bf @@ -107,7 +107,7 @@ namespace System.IO return .Ok; } - public static Result WriteAllLines(StringView path, IEnumerator enumerator) + public static Result WriteAllLines(StringView path, IEnumerator enumerator, bool doAppend = false) { String strBuf = scope String(); for (var str in enumerator) @@ -115,10 +115,10 @@ namespace System.IO strBuf.Append(str); strBuf.Append(Environment.NewLine); } - return WriteAllText(path, strBuf); + return WriteAllText(path, strBuf, doAppend); } - public static Result WriteAllLines(StringView path, IEnumerator enumerator) + public static Result WriteAllLines(StringView path, IEnumerator enumerator, bool doAppend = false) { String strBuf = scope String(); for (var str in enumerator) @@ -126,7 +126,7 @@ namespace System.IO strBuf.Append(str); strBuf.Append(Environment.NewLine); } - return WriteAllText(path, strBuf); + return WriteAllText(path, strBuf, doAppend); } /*public static Result>> ReadLines(String fileName) From e146475a39d63120d66c662a691c0e3b43a4d2e1 Mon Sep 17 00:00:00 2001 From: disarray2077 <86157825+disarray2077@users.noreply.github.com> Date: Sat, 1 Jan 2022 21:22:18 -0300 Subject: [PATCH 3/5] Add parameterless WriteLine to StreamWriter class --- BeefLibs/corlib/src/IO/StreamWriter.bf | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/BeefLibs/corlib/src/IO/StreamWriter.bf b/BeefLibs/corlib/src/IO/StreamWriter.bf index 3e55e4e9..a95c064b 100644 --- a/BeefLibs/corlib/src/IO/StreamWriter.bf +++ b/BeefLibs/corlib/src/IO/StreamWriter.bf @@ -76,6 +76,11 @@ namespace System.IO return .Ok; } + + public Result WriteLine() + { + return Write("\n"); + } public Result WriteLine(StringView str) { From 9ce0cc217a4a56b5eda26a255dd2a937c2e2f436 Mon Sep 17 00:00:00 2001 From: disarray2077 <86157825+disarray2077@users.noreply.github.com> Date: Sat, 1 Jan 2022 21:25:52 -0300 Subject: [PATCH 4/5] Add Peek to StreamReader class --- BeefLibs/corlib/src/IO/StreamReader.bf | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/BeefLibs/corlib/src/IO/StreamReader.bf b/BeefLibs/corlib/src/IO/StreamReader.bf index 2c1257be..ff2a4ba6 100644 --- a/BeefLibs/corlib/src/IO/StreamReader.bf +++ b/BeefLibs/corlib/src/IO/StreamReader.bf @@ -181,6 +181,17 @@ namespace System.IO return .Ok; } + + public Result Peek() + { + if (mStream == null) + return .Err; + if (mCharPos == mCharLen) + { + if (Try!(ReadBuffer()) == 0) return .Err; + } + return mCharBuffer[mCharPos + 1]; + } public Task ReadLineAsync() { From cd065bd8bd6cf8d6d81d67a8f07d8b027f329fcc Mon Sep 17 00:00:00 2001 From: disarray2077 <86157825+disarray2077@users.noreply.github.com> Date: Sat, 1 Jan 2022 21:53:17 -0300 Subject: [PATCH 5/5] Add copy constructor to Dictionary class --- BeefLibs/corlib/src/Collections/Dictionary.bf | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/BeefLibs/corlib/src/Collections/Dictionary.bf b/BeefLibs/corlib/src/Collections/Dictionary.bf index 83219754..14f41dc9 100644 --- a/BeefLibs/corlib/src/Collections/Dictionary.bf +++ b/BeefLibs/corlib/src/Collections/Dictionary.bf @@ -48,7 +48,13 @@ namespace System.Collections //if (capacity < 0) ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.capacity); if (capacity > 0) Initialize(capacity); //TODO: this.comparer = comparer ?? EqualityComparer.Default; - } + } + + public this(IEnumerator enumerator) + { + for (var kv in enumerator) + this[kv.key] = kv.value; + } public ~this() {