wxExtend
Additional templates and function helpers for wxWidgets
Loading...
Searching...
No Matches
xml.h
1/*
2 ​​​​SPDX-License-Identifier: GPL-3.0-or-later
3 Copyright © 2016-2022 Amebis
4 Copyright © 2016 GÉANT
5*/
6
7#pragma once
8
9#include "common.h"
10
11#include "crypto.h"
12
13#include <codeanalysis\warnings.h>
14#pragma warning(push)
15#pragma warning(disable: WXWIDGETS_CODE_ANALYSIS_WARNINGS)
16#include <wx/string.h>
17#include <wx/xml/xml.h>
18#pragma warning(pop)
19
22
29inline wxString wxXmlEscapeText(_In_ const wxString& str)
30{
31 wxString escaped;
32 escaped.reserve(str.length());
33
34 for (auto i = str.begin(); i != str.end(); ++i) {
35 const wxChar c = *i;
36 switch (c) {
37 case wxS('<'):
38 escaped.append(wxS("&lt;"));
39 break;
40 case wxS('>'):
41 escaped.append(wxS("&gt;"));
42 break;
43 case wxS('&'):
44 escaped.append(wxS("&amp;"));
45 break;
46 case wxS('\r'):
47 escaped.append(wxS("&#xD;"));
48 break;
49 default:
50 escaped.append(c);
51 }
52 }
53
54 return escaped;
55}
56
57
65inline wxString wxXmlEscapeAttr(_In_ const wxString& str)
66{
67 wxString escaped;
68 escaped.reserve(str.length());
69
70 for (auto i = str.begin(); i != str.end(); ++i) {
71 const wxChar c = *i;
72 switch (c) {
73 case wxS('<'):
74 escaped.append(wxS("&lt;"));
75 break;
76 case wxS('>'):
77 escaped.append(wxS("&gt;"));
78 break;
79 case wxS('&'):
80 escaped.append(wxS("&amp;"));
81 break;
82 case wxS('\r'):
83 escaped.append(wxS("&#xD;"));
84 break;
85 case wxS('"'):
86 escaped.append(wxS("&quot;"));
87 break;
88 case wxS('\t'):
89 escaped.append(wxS("&#x9;"));
90 break;
91 case wxS('\n'):
92 escaped.append(wxS("&#xA;"));
93 break;
94 default:
95 escaped.append(c);
96 }
97 }
98
99 return escaped;
100}
101
102
110bool WXEXTEND_API wxXmlHashNode(_In_ wxCryptoHash &hash, _In_ const wxXmlNode *node);
111
Cryptographics Hash Base.
Definition crypto.h:86
wxString wxXmlEscapeAttr(const wxString &str)
Escapes attribute value string for XML insertion.
Definition xml.h:65
wxString wxXmlEscapeText(const wxString &str)
Escapes text string for XML insertion.
Definition xml.h:29
bool WXEXTEND_API wxXmlHashNode(wxCryptoHash &hash, const wxXmlNode *node)
Calculates hash of the node and all its children.
Definition xml.cpp:11
#define WXEXTEND_API
Public function calling convention.
Definition common.h:56