|
|
|
@ -23,6 +23,53 @@ namespace Fungus
|
|
|
|
|
|
|
|
|
|
protected bool exitSayWait; |
|
|
|
|
|
|
|
|
|
/// <summary> |
|
|
|
|
/// Splits the string passed in by the delimiters passed in. |
|
|
|
|
/// Quoted sections are not split, and all tokens have whitespace |
|
|
|
|
/// trimmed from the start and end. |
|
|
|
|
protected static string[] Split(string stringToSplit) |
|
|
|
|
{ |
|
|
|
|
var results = new List<string>(); |
|
|
|
|
|
|
|
|
|
bool inQuote = false; |
|
|
|
|
var currentToken = new StringBuilder(); |
|
|
|
|
for (int index = 0; index < stringToSplit.Length; ++index) |
|
|
|
|
{ |
|
|
|
|
char currentCharacter = stringToSplit[index]; |
|
|
|
|
if (currentCharacter == '"') |
|
|
|
|
{ |
|
|
|
|
// When we see a ", we need to decide whether we are |
|
|
|
|
// at the start or send of a quoted section... |
|
|
|
|
inQuote = !inQuote; |
|
|
|
|
} |
|
|
|
|
else if (char.IsWhiteSpace(currentCharacter) && !inQuote) |
|
|
|
|
{ |
|
|
|
|
// We've come to the end of a token, so we find the token, |
|
|
|
|
// trim it and add it to the collection of results... |
|
|
|
|
string result = currentToken.ToString().Trim( new [] { ' ', '\n', '\t', '\"'} ); |
|
|
|
|
if (result != "") results.Add(result); |
|
|
|
|
|
|
|
|
|
// We start a new token... |
|
|
|
|
currentToken = new StringBuilder(); |
|
|
|
|
} |
|
|
|
|
else |
|
|
|
|
{ |
|
|
|
|
// We've got a 'normal' character, so we add it to |
|
|
|
|
// the curent token... |
|
|
|
|
currentToken.Append(currentCharacter); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// We've come to the end of the string, so we add the last token... |
|
|
|
|
string lastResult = currentToken.ToString().Trim(); |
|
|
|
|
if (lastResult != "") |
|
|
|
|
{ |
|
|
|
|
results.Add(lastResult); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return results.ToArray(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
protected ISayDialog GetSayDialog(Character character) |
|
|
|
|
{ |
|
|
|
|
ISayDialog sayDialog = null; |
|
|
|
@ -208,53 +255,6 @@ namespace Fungus
|
|
|
|
|
return item; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/// <summary> |
|
|
|
|
/// Splits the string passed in by the delimiters passed in. |
|
|
|
|
/// Quoted sections are not split, and all tokens have whitespace |
|
|
|
|
/// trimmed from the start and end. |
|
|
|
|
protected static string[] Split(string stringToSplit) |
|
|
|
|
{ |
|
|
|
|
var results = new List<string>(); |
|
|
|
|
|
|
|
|
|
bool inQuote = false; |
|
|
|
|
var currentToken = new StringBuilder(); |
|
|
|
|
for (int index = 0; index < stringToSplit.Length; ++index) |
|
|
|
|
{ |
|
|
|
|
char currentCharacter = stringToSplit[index]; |
|
|
|
|
if (currentCharacter == '"') |
|
|
|
|
{ |
|
|
|
|
// When we see a ", we need to decide whether we are |
|
|
|
|
// at the start or send of a quoted section... |
|
|
|
|
inQuote = !inQuote; |
|
|
|
|
} |
|
|
|
|
else if (char.IsWhiteSpace(currentCharacter) && !inQuote) |
|
|
|
|
{ |
|
|
|
|
// We've come to the end of a token, so we find the token, |
|
|
|
|
// trim it and add it to the collection of results... |
|
|
|
|
string result = currentToken.ToString().Trim( new [] { ' ', '\n', '\t', '\"'} ); |
|
|
|
|
if (result != "") results.Add(result); |
|
|
|
|
|
|
|
|
|
// We start a new token... |
|
|
|
|
currentToken = new StringBuilder(); |
|
|
|
|
} |
|
|
|
|
else |
|
|
|
|
{ |
|
|
|
|
// We've got a 'normal' character, so we add it to |
|
|
|
|
// the curent token... |
|
|
|
|
currentToken.Append(currentCharacter); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// We've come to the end of the string, so we add the last token... |
|
|
|
|
string lastResult = currentToken.ToString().Trim(); |
|
|
|
|
if (lastResult != "") |
|
|
|
|
{ |
|
|
|
|
results.Add(lastResult); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return results.ToArray(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
#region IConversationManager |
|
|
|
|
|
|
|
|
|
public void PopulateCharacterCache() |
|
|
|
|