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:
commit
5004e89e35
5 changed files with 59 additions and 5 deletions
|
@ -48,7 +48,13 @@ namespace System.Collections
|
||||||
//if (capacity < 0) ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.capacity);
|
//if (capacity < 0) ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.capacity);
|
||||||
if (capacity > 0) Initialize(capacity);
|
if (capacity > 0) Initialize(capacity);
|
||||||
//TODO: this.comparer = comparer ?? EqualityComparer<TKey>.Default;
|
//TODO: this.comparer = comparer ?? EqualityComparer<TKey>.Default;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public this(IEnumerator<KeyValuePair> enumerator)
|
||||||
|
{
|
||||||
|
for (var kv in enumerator)
|
||||||
|
this[kv.key] = kv.value;
|
||||||
|
}
|
||||||
|
|
||||||
public ~this()
|
public ~this()
|
||||||
{
|
{
|
||||||
|
|
|
@ -107,7 +107,7 @@ namespace System.IO
|
||||||
return .Ok;
|
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();
|
String strBuf = scope String();
|
||||||
for (var str in enumerator)
|
for (var str in enumerator)
|
||||||
|
@ -115,10 +115,10 @@ namespace System.IO
|
||||||
strBuf.Append(str);
|
strBuf.Append(str);
|
||||||
strBuf.Append(Environment.NewLine);
|
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();
|
String strBuf = scope String();
|
||||||
for (var str in enumerator)
|
for (var str in enumerator)
|
||||||
|
@ -126,7 +126,7 @@ namespace System.IO
|
||||||
strBuf.Append(str);
|
strBuf.Append(str);
|
||||||
strBuf.Append(Environment.NewLine);
|
strBuf.Append(Environment.NewLine);
|
||||||
}
|
}
|
||||||
return WriteAllText(path, strBuf);
|
return WriteAllText(path, strBuf, doAppend);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*public static Result<IEnumerator<Result<String>>> ReadLines(String fileName)
|
/*public static Result<IEnumerator<Result<String>>> ReadLines(String fileName)
|
||||||
|
|
|
@ -35,6 +35,38 @@ namespace System.IO
|
||||||
public const char8 VolumeSeparatorChar = '/';
|
public const char8 VolumeSeparatorChar = '/';
|
||||||
#endif //BF_PLATFORM_WINDOWS
|
#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.
|
// Make this public sometime.
|
||||||
// The max total path is 260, and the max individual component length is 255.
|
// The max total path is 260, and the max individual component length is 255.
|
||||||
// For example, D:\<256 char file name> isn't legal, even though it's under 260 chars.
|
// For example, D:\<256 char file name> isn't legal, even though it's under 260 chars.
|
||||||
|
|
|
@ -182,6 +182,17 @@ namespace System.IO
|
||||||
return .Ok;
|
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()
|
public Task<String> ReadLineAsync()
|
||||||
{
|
{
|
||||||
// If we have been inherited into a subclass, the following implementation could be incorrect
|
// If we have been inherited into a subclass, the following implementation could be incorrect
|
||||||
|
|
|
@ -77,6 +77,11 @@ namespace System.IO
|
||||||
return .Ok;
|
return .Ok;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Result<void> WriteLine()
|
||||||
|
{
|
||||||
|
return Write("\n");
|
||||||
|
}
|
||||||
|
|
||||||
public Result<void> WriteLine(StringView str)
|
public Result<void> WriteLine(StringView str)
|
||||||
{
|
{
|
||||||
Try!(Write(str));
|
Try!(Write(str));
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue