mirror of
https://github.com/MindWorkAI/AI-Studio.git
synced 2026-12-06 04:31:36 +00:00
Added whole documents to the Translation, Grammar & Spelling, and Rewrite & Improve assistants (#1179)
Co-authored-by: Thorsten Sommer <SommerEngineering@users.noreply.github.com>
This commit is contained in:
1 parent
f7666861f1
commit
918572c158
150 files changed
+12850
-302
No files matched your search
@@ -0,0 +1,37 @@
|
||||
using System.Text;
|
||||
using System.Xml;
|
||||
|
||||
namespace AIStudio.Tools.OpenXml;
|
||||
|
||||
/// <summary>
|
||||
/// Prepares texts for the Office documents AI Studio writes.
|
||||
/// </summary>
|
||||
internal static class OpenXmlText
|
||||
{
|
||||
/// <summary>
|
||||
/// Leaves out the characters XML cannot carry, which a model may produce now and then. The file
|
||||
/// could not be saved with them.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// A character outside the Basic Multilingual Plane, such as an emoji, takes two chars; such a
|
||||
/// pair stays, whereas a half of one alone goes.
|
||||
/// </remarks>
|
||||
/// <param name="text">The text.</param>
|
||||
/// <returns>The text without the characters XML cannot carry.</returns>
|
||||
public static string XmlSafe(string text)
|
||||
{
|
||||
if (text.All(XmlConvert.IsXmlChar))
|
||||
return text;
|
||||
|
||||
var result = new StringBuilder(text.Length);
|
||||
for (var index = 0; index < text.Length; index++)
|
||||
{
|
||||
if (XmlConvert.IsXmlChar(text[index]))
|
||||
result.Append(text[index]);
|
||||
else if (index + 1 < text.Length && XmlConvert.IsXmlSurrogatePair(text[index + 1], text[index]))
|
||||
result.Append(text[index]).Append(text[++index]);
|
||||
}
|
||||
|
||||
return result.ToString();
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user