mirror of
https://github.com/Xahau/xahaud.git
synced 2025-12-06 17:27:52 +00:00
Simplify the Beast fatal error reporting framework:
* Reduce interface to a single function which reports error details * Remove unused functions
This commit is contained in:
@@ -155,148 +155,6 @@ String getFileNameFromPath (const char* sourceFileName, int numberOfParents)
|
||||
return path;
|
||||
}
|
||||
|
||||
// Returns a String with double quotes escaped
|
||||
static const String withEscapedQuotes (String const& string)
|
||||
{
|
||||
String escaped;
|
||||
|
||||
int i0 = 0;
|
||||
int i;
|
||||
|
||||
do
|
||||
{
|
||||
i = string.indexOfChar (i0, '"');
|
||||
|
||||
if (i == -1)
|
||||
{
|
||||
escaped << string.substring (i0, string.length ());
|
||||
}
|
||||
else
|
||||
{
|
||||
escaped << string.substring (i0, i) << "\\\"";
|
||||
i0 = i + 1;
|
||||
}
|
||||
}
|
||||
while (i != -1);
|
||||
|
||||
return escaped;
|
||||
}
|
||||
|
||||
// Converts escaped quotes back into regular quotes
|
||||
static const String withUnescapedQuotes (String const& string)
|
||||
{
|
||||
String unescaped;
|
||||
|
||||
int i0 = 0;
|
||||
int i;
|
||||
|
||||
do
|
||||
{
|
||||
i = string.indexOfChar (i0, '\\');
|
||||
|
||||
if (i == -1)
|
||||
{
|
||||
unescaped << string.substring (i0, string.length ());
|
||||
}
|
||||
else
|
||||
{
|
||||
// peek
|
||||
if (string.length () > i && string[i + 1] == '\"')
|
||||
{
|
||||
unescaped << string.substring (i0, i) << '"';
|
||||
i0 = i + 2;
|
||||
}
|
||||
else
|
||||
{
|
||||
unescaped << string.substring (i0, i + 1);
|
||||
i0 = i + 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
while (i != -1);
|
||||
|
||||
return unescaped;
|
||||
}
|
||||
|
||||
// Converts a String that may contain newlines, into a
|
||||
// command line where each line is delimited with quotes.
|
||||
// Any quotes in the actual string will be escaped via \".
|
||||
String stringToCommandLine (String const& string)
|
||||
{
|
||||
String commandLine;
|
||||
|
||||
int i0 = 0;
|
||||
int i;
|
||||
|
||||
for (i = 0; i < string.length (); i++)
|
||||
{
|
||||
beast_wchar c = string[i];
|
||||
|
||||
if (c == '\n')
|
||||
{
|
||||
if (i0 != 0)
|
||||
commandLine << ' ';
|
||||
|
||||
commandLine << '"' << withEscapedQuotes (string.substring (i0, i)) << '"';
|
||||
i0 = i + 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (i0 < i)
|
||||
{
|
||||
if (i0 != 0)
|
||||
commandLine << ' ';
|
||||
|
||||
commandLine << '"' << withEscapedQuotes (string.substring (i0, i)) << '"';
|
||||
}
|
||||
|
||||
return commandLine;
|
||||
}
|
||||
|
||||
// Converts a command line consisting of multiple quoted strings
|
||||
// back into a single string with newlines delimiting each quoted
|
||||
// string. Escaped quotes \" are turned into real quotes.
|
||||
String commandLineToString (const String& commandLine)
|
||||
{
|
||||
String string;
|
||||
|
||||
bool quoting = false;
|
||||
int i0 = 0;
|
||||
int i;
|
||||
|
||||
for (i = 0; i < commandLine.length (); i++)
|
||||
{
|
||||
beast_wchar c = commandLine[i];
|
||||
|
||||
if (c == '\\')
|
||||
{
|
||||
// peek
|
||||
if (commandLine.length () > i && commandLine[i + 1] == '\"')
|
||||
{
|
||||
i++;
|
||||
}
|
||||
}
|
||||
else if (c == '"')
|
||||
{
|
||||
if (!quoting)
|
||||
{
|
||||
i0 = i + 1;
|
||||
quoting = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!string.isEmpty ())
|
||||
string << '\n';
|
||||
|
||||
string << withUnescapedQuotes (commandLine.substring (i0, i));
|
||||
quoting = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return string;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user