1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
10 #include <sal/config.h>
12 #include <o3tl/safeint.hxx>
19 const OString
& rText
, const OString
& rUnEscaped
, const OString
& rEscaped
)
21 assert( rEscaped
.getLength() == 2*rUnEscaped
.getLength() );
22 OStringBuffer sReturn
;
23 for ( sal_Int32 nIndex
= 0; nIndex
< rText
.getLength(); ++nIndex
)
25 sal_Int32 nUnEscapedOne
= rUnEscaped
.indexOf(rText
[nIndex
]);
26 if( nUnEscapedOne
!= -1 )
28 sReturn
.append(rEscaped
.subView(nUnEscapedOne
*2,2));
31 sReturn
.append(rText
[nIndex
]);
33 return sReturn
.makeStringAndClear();
38 const OString
& rText
, const OString
& rEscaped
, std::string_view rUnEscaped
)
40 assert( o3tl::make_unsigned(rEscaped
.getLength()) == 2*rUnEscaped
.length() );
41 OStringBuffer sReturn
;
42 const sal_Int32 nLength
= rText
.getLength();
43 for ( sal_Int32 nIndex
= 0; nIndex
< nLength
; ++nIndex
)
45 if( rText
[nIndex
] == '\\' && nIndex
+1 < nLength
)
47 sal_Int32 nEscapedOne
= rEscaped
.indexOf(rText
.subView(nIndex
,2));
48 if( nEscapedOne
!= -1 )
50 sReturn
.append(rUnEscaped
[nEscapedOne
/2]);
55 sReturn
.append(rText
[nIndex
]);
59 sReturn
.append(rText
[nIndex
]);
61 return sReturn
.makeStringAndClear();
65 OString
QuotHTML(const OString
&rString
)
67 OStringBuffer sReturn
;
68 for (sal_Int32 i
= 0; i
< rString
.getLength(); ++i
)
73 sReturn
.append("<");
76 sReturn
.append(">");
79 sReturn
.append(""");
82 sReturn
.append("'");
85 if (rString
.match("&", i
))
88 sReturn
.append("&");
91 sReturn
.append(rString
[i
]);
95 return sReturn
.makeStringAndClear();
98 OString
UnQuotHTML( const OString
& rString
)
100 OStringBuffer sReturn
;
101 for (sal_Int32 i
= 0; i
!= rString
.getLength();) {
102 if (rString
.match("&", i
)) {
104 i
+= RTL_CONSTASCII_LENGTH("&");
105 } else if (rString
.match("<", i
)) {
107 i
+= RTL_CONSTASCII_LENGTH("<");
108 } else if (rString
.match(">", i
)) {
110 i
+= RTL_CONSTASCII_LENGTH(">");
111 } else if (rString
.match(""", i
)) {
113 i
+= RTL_CONSTASCII_LENGTH(""");
114 } else if (rString
.match("'", i
)) {
115 sReturn
.append('\'');
116 i
+= RTL_CONSTASCII_LENGTH("'");
118 sReturn
.append(rString
[i
]);
122 return sReturn
.makeStringAndClear();
125 bool isWellFormedXML( std::string_view text
)
130 OString content
= OString::Concat("<root>") + text
+ "</root>";
131 doc
= xmlParseMemory(content
.getStr(),static_cast<int>(content
.getLength()));
132 if (doc
== nullptr) {
140 //Convert xmlChar* to OString
141 OString
xmlStrToOString( const xmlChar
* pString
)
143 xmlChar
* pTemp
= xmlStrdup( pString
);
144 OString sResult
= reinterpret_cast<char*>( pTemp
);
151 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */