|
@@ -1,3 +1,5 @@ |
|
|
|
|
|
using System.Text; |
|
|
|
|
|
|
|
|
namespace Discord |
|
|
namespace Discord |
|
|
{ |
|
|
{ |
|
|
/// <summary> A helper class for formatting characters. </summary> |
|
|
/// <summary> A helper class for formatting characters. </summary> |
|
@@ -37,5 +39,41 @@ namespace Discord |
|
|
text = text.Replace(unsafeChar, $"\\{unsafeChar}"); |
|
|
text = text.Replace(unsafeChar, $"\\{unsafeChar}"); |
|
|
return text; |
|
|
return text; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/// <summary> |
|
|
|
|
|
/// Formats a string as a quote. |
|
|
|
|
|
/// </summary> |
|
|
|
|
|
/// <param name="text">The text to format.</param> |
|
|
|
|
|
/// <returns>Gets the formatted quote text.</returns> // TODO: better xmldoc |
|
|
|
|
|
public static string Quote(string text) |
|
|
|
|
|
{ |
|
|
|
|
|
if (text == null) |
|
|
|
|
|
return null; |
|
|
|
|
|
|
|
|
|
|
|
StringBuilder result = new StringBuilder(); |
|
|
|
|
|
|
|
|
|
|
|
int startIndex = 0; |
|
|
|
|
|
int newLineIndex; |
|
|
|
|
|
do |
|
|
|
|
|
{ |
|
|
|
|
|
newLineIndex = text.IndexOf('\n', startIndex); |
|
|
|
|
|
if (newLineIndex == -1) |
|
|
|
|
|
{ |
|
|
|
|
|
// read the rest of the string |
|
|
|
|
|
var str = text.Substring(startIndex); |
|
|
|
|
|
result.Append($"> {str}"); |
|
|
|
|
|
} |
|
|
|
|
|
else |
|
|
|
|
|
{ |
|
|
|
|
|
// read until the next newline |
|
|
|
|
|
var str = text.Substring(startIndex, newLineIndex - startIndex); |
|
|
|
|
|
result.Append($"> {str}\n"); |
|
|
|
|
|
} |
|
|
|
|
|
startIndex = newLineIndex + 1; |
|
|
|
|
|
} |
|
|
|
|
|
while (newLineIndex != -1 && startIndex != text.Length); |
|
|
|
|
|
|
|
|
|
|
|
return result.ToString(); |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |