初始提交
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
namespace MAF1.Utils;
|
||||
|
||||
public static class JsonText
|
||||
{
|
||||
public static string UnwrapObject(string text)
|
||||
{
|
||||
string trimmed = text.Trim();
|
||||
if (trimmed.StartsWith("```", StringComparison.Ordinal))
|
||||
{
|
||||
int firstNewLine = trimmed.IndexOf('\n');
|
||||
int lastFence = trimmed.LastIndexOf("```", StringComparison.Ordinal);
|
||||
if (firstNewLine >= 0 && lastFence > firstNewLine)
|
||||
{
|
||||
trimmed = trimmed[(firstNewLine + 1)..lastFence].Trim();
|
||||
}
|
||||
}
|
||||
|
||||
int objectStart = trimmed.IndexOf('{');
|
||||
int objectEnd = trimmed.LastIndexOf('}');
|
||||
if (objectStart >= 0 && objectEnd > objectStart)
|
||||
{
|
||||
return trimmed[objectStart..(objectEnd + 1)];
|
||||
}
|
||||
|
||||
return trimmed;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user