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

fix string unescape, add escape, fix obsoletes

This commit is contained in:
EinBurgbauer 2022-03-19 21:14:21 +01:00
parent ccdabc800a
commit 9f9f21fb8e
2 changed files with 49 additions and 52 deletions

View file

@ -447,9 +447,23 @@ namespace System
strBuffer.Append(this);
}
[Obsolete("Replaced with Quote", false)]
public static void QuoteString(char8* ptr, int length, String outString) => Quote(ptr, length, outString);
public static void Quote(char8* ptr, int length, String outString)
{
outString.Append('"');
Escape(ptr, length, outString);
outString.Append('"');
}
public void Quote(String outString)
{
Quote(Ptr, Length, outString);
}
public static void Escape(char8* ptr, int length, String outString)
{
for (int i < length)
{
char8 c = ptr[i];
@ -477,19 +491,15 @@ namespace System
outString.Append(c);
}
}
outString.Append('"');
}
public void Quote(String outString)
public void Escape(String outString)
{
Quote(Ptr, Length, outString);
Escape(Ptr, Length, outString);
}
[Obsolete("Replaced with Quote", false)]
public void QuoteString(String outString)
{
Quote(Ptr, Length, outString);
}
[Obsolete("Replaced with Unquote", false)]
public static Result<void> UnquoteString(char8* ptr, int length, String outString) => Unquote(ptr, length, outString);
public static Result<void> Unquote(char8* ptr, int length, String outString)
{
@ -504,11 +514,9 @@ namespace System
}
if ((*ptr != '\"') && (ptr[length - 1] != '\"'))
{
return .Err;
}
return Unescape(ptr, length, outString);
return Unescape(ptr + 1, length - 2, outString);
}
public Result<void> Unquote(String outString)
@ -516,20 +524,10 @@ namespace System
return Unquote(Ptr, Length, outString);
}
[Obsolete("Replaced with Unquote", false)]
public Result<void> UnQuoteString(String outString)
{
return Unquote(outString);
}
public static Result<void> Unescape(char8* ptr, int length, String outString)
{
if (length < 2)
return .Err;
var ptr;
ptr++;
char8* endPtr = ptr + length - 2;
char8* endPtr = ptr + length - 1;
while (ptr < endPtr)
{
@ -553,6 +551,7 @@ namespace System
case 'r': outString.Append("\r");
case 't': outString.Append("\t");
case 'v': outString.Append("\v");
default:
return .Err;
}

View file

@ -1283,10 +1283,8 @@ namespace System.Reflection
strBuffer.Append((*(bool*)&mValue) ? "true" : "false");
case typeof(char8), typeof(char16), typeof(char32):
strBuffer.Append('\'');
var str = (*(char32*)&mValue).ToString(.. scope .());
let len = str.Length;
String.Quote(&str[0], len, str);
strBuffer.Append(str[(len + 1)...^2]);
let str = (*(char32*)&mValue).ToString(.. scope .(4));
str.Escape(strBuffer);
strBuffer.Append('\'');
case typeof(uint64), typeof(uint):
(*(uint64*)&mValue).ToString(strBuffer);