Stroika Library 3.0d16
 
Loading...
Searching...
No Matches
WriterUtils.h
1/*
2 * Copyright(c) Sophist Solutions, Inc. 1990-2025. All rights reserved
3 */
4#ifndef _Stroika_Foundation_DataExchange_XML_WriterUtils_h_
5#define _Stroika_Foundation_DataExchange_XML_WriterUtils_h_ 1
6
7#include "Stroika/Foundation/StroikaPreComp.h"
8
9#include <optional>
10
16
17/*
18 * TODO:
19 * @todo Short term- convert to using only Stroika string class (but make easy to still leverage from HF -
20 * think this out carefully befor change)
21 *
22 * @todo Harmonize the WriteQuoted/Format4XML routines - probably just switching to the later.
23 * Maybe add optional params for some types (control enums).
24 * Support dates, and VariantValue, and optional, etc...
25 */
26
27namespace Stroika::Foundation::DataExchange::XML {
28
29 using Characters::String;
30
31 /**
32 */
33 string QuoteForXMLAttribute (const string& s);
34 string QuoteForXMLAttribute (const wstring& s); // encode non-ascii characters as entity-references
35 string QuoteForXMLAttribute (const String& s);
36 string QuoteForXMLAttribute (const optional<String>& s);
37
38 /**
39 */
40 String QuoteForXMLAttributeW (const String& s);
41
42 /**
43 * This function only emits ascii characters (so makes no assumptions about the codepage used for writing xml). It
44 * emits non-ascii characters as entity references.
45 */
46 string QuoteForXML (const string& s);
47 string QuoteForXML (const wstring& s); // encode non-ascii characters as entity-references
48 string QuoteForXML (const String& s);
49 string QuoteForXML (const optional<String>& s);
50
51 /**
52 */
53 String QuoteForXMLW (const String& s);
54
55 class Indenter {
56 public:
57 Indenter (const String& indentText = "\t"sv);
58
59 public:
60 nonvirtual void Indent (unsigned int indentLevel, ostream& out) const;
61 nonvirtual void Indent (unsigned int indentLevel, wostream& out) const;
62
63 private:
64 string fTabS_;
65 wstring fTabW_;
66 };
67
68 /**
69 * Format values for XML output.
70 * PROBABLY should map QuoteForXML to this overloaded name?
71 *
72 * Note - this assumes we're outputting using UTF8.
73 *
74 * SHOULD probably include Memory::Optiona<> variations on all these as well - so we can fairly freely just say "Foramt4XML"
75 */
76 string Format4XML (bool v);
77 //string Format4XML (Time::Date v); NYI
78 //string Format4XML (Time::DateTime v);
79
80}
81
82/*
83 ********************************************************************************
84 ***************************** Implementation Details ***************************
85 ********************************************************************************
86 */
87#include "WriterUtils.inl"
88
89#endif /*_Stroika_Foundation_DataExchange_XML_WriterUtils_h_*/