1
0
Fork 0
mirror of https://github.com/beefytech/Beef.git synced 2025-07-05 15:56:00 +02:00

Merge pull request #1637 from disarray2077/sv_null

Allow StringView to be created from null
This commit is contained in:
Brian Fiete 2022-07-10 07:53:50 -04:00 committed by GitHub
commit 8c24eb9278
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -3307,12 +3307,23 @@ namespace System
public this(String string) public this(String string)
{ {
if (string == null)
{
this = default;
return;
}
mPtr = string.Ptr; mPtr = string.Ptr;
mLength = string.Length; mLength = string.Length;
} }
public this(String string, int offset) public this(String string, int offset)
{ {
if (string == null)
{
Debug.Assert(offset == 0);
this = default;
return;
}
Debug.Assert((uint)offset <= (uint)string.Length); Debug.Assert((uint)offset <= (uint)string.Length);
mPtr = string.Ptr + offset; mPtr = string.Ptr + offset;
mLength = string.Length - offset; mLength = string.Length - offset;
@ -3320,6 +3331,12 @@ namespace System
public this(String string, int offset, int length) public this(String string, int offset, int length)
{ {
if (string == null)
{
Debug.Assert(offset == 0 && length == 0);
this = default;
return;
}
Debug.Assert((uint)offset + (uint)length <= (uint)string.Length); Debug.Assert((uint)offset + (uint)length <= (uint)string.Length);
mPtr = string.Ptr + offset; mPtr = string.Ptr + offset;
mLength = length; mLength = length;
@ -3347,6 +3364,12 @@ namespace System
public this(char8[] arr, int offset, int length) public this(char8[] arr, int offset, int length)
{ {
if (arr == null)
{
Debug.Assert(offset == 0 && length == 0);
this = default;
return;
}
Debug.Assert((uint)offset + (uint)length <= (uint)arr.Count); Debug.Assert((uint)offset + (uint)length <= (uint)arr.Count);
mPtr = arr.CArray() + offset; mPtr = arr.CArray() + offset;
mLength = length; mLength = length;
@ -3354,13 +3377,23 @@ namespace System
public this(char8* ptr) public this(char8* ptr)
{ {
if (ptr == null)
{
this = default;
return;
}
mPtr = ptr; mPtr = ptr;
mLength = String.StrLen(ptr); mLength = String.StrLen(ptr);
} }
public this(char8* ptr, int length) public this(char8* ptr, int length)
{ {
if (ptr == null)
{
Debug.Assert(length == 0);
this = default;
return;
}
mPtr = ptr; mPtr = ptr;
mLength = length; mLength = length;
} }