1
0
Fork 0
mirror of https://github.com/beefytech/Beef.git synced 2025-06-19 08:30:25 +02:00

Merge pull request #1336 from disarray2077/patch-2

Some miscellaneous additions to corlib
This commit is contained in:
Brian Fiete 2022-01-02 11:58:30 +01:00 committed by GitHub
commit 5004e89e35
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 59 additions and 5 deletions

View file

@ -48,7 +48,13 @@ namespace System.Collections
//if (capacity < 0) ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.capacity);
if (capacity > 0) Initialize(capacity);
//TODO: this.comparer = comparer ?? EqualityComparer<TKey>.Default;
}
}
public this(IEnumerator<KeyValuePair> enumerator)
{
for (var kv in enumerator)
this[kv.key] = kv.value;
}
public ~this()
{

View file

@ -107,7 +107,7 @@ namespace System.IO
return .Ok;
}
public static Result<void> WriteAllLines(StringView path, IEnumerator<StringView> enumerator)
public static Result<void> WriteAllLines(StringView path, IEnumerator<StringView> 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<void> WriteAllLines(StringView path, IEnumerator<String> enumerator)
public static Result<void> WriteAllLines(StringView path, IEnumerator<String> 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<IEnumerator<Result<String>>> ReadLines(String fileName)

View file

@ -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.

View file

@ -181,6 +181,17 @@ namespace System.IO
return .Ok;
}
public Result<char8> Peek()
{
if (mStream == null)
return .Err;
if (mCharPos == mCharLen)
{
if (Try!(ReadBuffer()) == 0) return .Err;
}
return mCharBuffer[mCharPos + 1];
}
public Task<String> ReadLineAsync()
{

View file

@ -76,6 +76,11 @@ namespace System.IO
return .Ok;
}
public Result<void> WriteLine()
{
return Write("\n");
}
public Result<void> WriteLine(StringView str)
{