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:
parent
ccdabc800a
commit
9f9f21fb8e
2 changed files with 49 additions and 52 deletions
|
@ -447,9 +447,23 @@ namespace System
|
||||||
strBuffer.Append(this);
|
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)
|
public static void Quote(char8* ptr, int length, String outString)
|
||||||
{
|
{
|
||||||
outString.Append('"');
|
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)
|
for (int i < length)
|
||||||
{
|
{
|
||||||
char8 c = ptr[i];
|
char8 c = ptr[i];
|
||||||
|
@ -477,19 +491,15 @@ namespace System
|
||||||
outString.Append(c);
|
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)]
|
[Obsolete("Replaced with Unquote", false)]
|
||||||
public void QuoteString(String outString)
|
public static Result<void> UnquoteString(char8* ptr, int length, String outString) => Unquote(ptr, length, outString);
|
||||||
{
|
|
||||||
Quote(Ptr, Length, outString);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Result<void> Unquote(char8* ptr, int length, String outString)
|
public static Result<void> Unquote(char8* ptr, int length, String outString)
|
||||||
{
|
{
|
||||||
|
@ -504,11 +514,9 @@ namespace System
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((*ptr != '\"') && (ptr[length - 1] != '\"'))
|
if ((*ptr != '\"') && (ptr[length - 1] != '\"'))
|
||||||
{
|
|
||||||
return .Err;
|
return .Err;
|
||||||
}
|
|
||||||
|
|
||||||
return Unescape(ptr, length, outString);
|
return Unescape(ptr + 1, length - 2, outString);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Result<void> Unquote(String outString)
|
public Result<void> Unquote(String outString)
|
||||||
|
@ -516,20 +524,10 @@ namespace System
|
||||||
return Unquote(Ptr, Length, outString);
|
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)
|
public static Result<void> Unescape(char8* ptr, int length, String outString)
|
||||||
{
|
{
|
||||||
if (length < 2)
|
|
||||||
return .Err;
|
|
||||||
|
|
||||||
var ptr;
|
var ptr;
|
||||||
ptr++;
|
char8* endPtr = ptr + length - 1;
|
||||||
char8* endPtr = ptr + length - 2;
|
|
||||||
|
|
||||||
while (ptr < endPtr)
|
while (ptr < endPtr)
|
||||||
{
|
{
|
||||||
|
@ -553,6 +551,7 @@ namespace System
|
||||||
case 'r': outString.Append("\r");
|
case 'r': outString.Append("\r");
|
||||||
case 't': outString.Append("\t");
|
case 't': outString.Append("\t");
|
||||||
case 'v': outString.Append("\v");
|
case 'v': outString.Append("\v");
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return .Err;
|
return .Err;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1283,10 +1283,8 @@ namespace System.Reflection
|
||||||
strBuffer.Append((*(bool*)&mValue) ? "true" : "false");
|
strBuffer.Append((*(bool*)&mValue) ? "true" : "false");
|
||||||
case typeof(char8), typeof(char16), typeof(char32):
|
case typeof(char8), typeof(char16), typeof(char32):
|
||||||
strBuffer.Append('\'');
|
strBuffer.Append('\'');
|
||||||
var str = (*(char32*)&mValue).ToString(.. scope .());
|
let str = (*(char32*)&mValue).ToString(.. scope .(4));
|
||||||
let len = str.Length;
|
str.Escape(strBuffer);
|
||||||
String.Quote(&str[0], len, str);
|
|
||||||
strBuffer.Append(str[(len + 1)...^2]);
|
|
||||||
strBuffer.Append('\'');
|
strBuffer.Append('\'');
|
||||||
case typeof(uint64), typeof(uint):
|
case typeof(uint64), typeof(uint):
|
||||||
(*(uint64*)&mValue).ToString(strBuffer);
|
(*(uint64*)&mValue).ToString(strBuffer);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue