4#include "Stroika/Foundation/StroikaPreComp.h"
10#include "Stroika/Foundation/Containers/Support/ReserveTweaks.h"
12#include "WriterUtils.h"
17using namespace Stroika::Foundation::DataExchange::XML;
24string XML::QuoteForXMLAttribute (
const string& s)
27 r.reserve (Containers::Support::ReserveTweaks::GetScaledUpCapacity (6 * s.size () / 5));
28 for (
auto i = s.begin (); i != s.end (); ++i) {
53string XML::QuoteForXMLAttribute (
const wstring& s)
56 r.reserve (Containers::Support::ReserveTweaks::GetScaledUpCapacity (6 * s.size () / 5));
57 for (
auto i = s.begin (); i != s.end (); ++i) {
76 if (ccode !=
'\t' and ccode !=
'\n' and ccode !=
'\r' and (ccode < 32 or ccode > 127)) {
77 r += CString::Format (
"&#%d;", ccode);
80 r.push_back (
static_cast<char> (ccode));
88string XML::QuoteForXMLAttribute (
const String& s)
90 return QuoteForXMLAttribute (s.
As<wstring> ());
93string XML::QuoteForXMLAttribute (
const optional<String>& s)
95 if (not s.has_value ()) {
98 return QuoteForXMLAttribute (*s);
103 string tmp = QuoteForXMLAttribute (s);
104 return String::FromNarrowSDKString (tmp);
112string XML::QuoteForXML (
const string& s)
115 r.reserve (s.size () * 6 / 5);
116 for (
auto i = s.begin (); i != s.end (); ++i) {
134 if ((i == s.begin ()) or (i + 1 == s.end ()) or (*(i - 1) == '-')) {
149string XML::QuoteForXML (
const wstring& s)
152 r.reserve (Containers::Support::ReserveTweaks::GetScaledUpCapacity (6 * s.size () / 5));
153 for (
auto i = s.begin (); i != s.end (); ++i) {
171 if ((i == s.begin ()) or (i + 1 == s.end ()) or (*(i - 1) == '-')) {
180 if (ccode !=
'\t' and ccode !=
'\n' and ccode !=
'\r' and (ccode < 32 or ccode > 127)) {
181 r += CString::Format (
"&#%d;", ccode);
184 r.push_back (
static_cast<char> (ccode));
194 string tmp = QuoteForXML (s);
195 return String::FromNarrowSDKString (tmp);
198string XML::QuoteForXML (
const String& s)
200 return QuoteForXML (s.
As<wstring> ());
203string XML::QuoteForXML (
const optional<String>& s)
205 if (not s.has_value ()) {
208 return QuoteForXML (*s);
216Indenter::Indenter (
const String& indentText)
217 : fTabS_{indentText.AsUTF8<string> ()}
218 , fTabW_{indentText.As<wstring> ()}
222void Indenter::Indent (
unsigned indentLevel, ostream& out)
const
224 for (
unsigned int i = 0; i < indentLevel; ++i) {
229void Indenter::Indent (
unsigned int indentLevel, wostream& out)
const
231 for (
unsigned int i = 0; i < indentLevel; ++i) {
236string XML::Format4XML (
bool v)
238 return v ?
"true" :
"false";
String is like std::u32string, except it is much easier to use, often much more space efficient,...