tdf#162786, tdf#161947: Add support for setuptools and pip
[LibreOffice.git] / include / comphelper / xmlencode.hxx
blob9fbf18f8b7112a5e083a284ab624990b2bcf8934
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
2 /*
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/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #pragma once
22 #include <rtl/ustring.hxx>
23 #include <rtl/ustrbuf.hxx>
25 namespace comphelper::string
27 inline OUString encodeForXml(std::u16string_view rStr)
29 // encode conforming xml:
30 sal_Int32 len = rStr.length();
31 OUStringBuffer buf(len + 16); // it's going to be at least len
32 for (sal_Int32 pos = 0; pos < len; ++pos)
34 sal_Unicode c = rStr[pos];
35 switch (c)
37 case '<':
38 buf.append("&lt;");
39 break;
40 case '>':
41 buf.append("&gt;");
42 break;
43 case '&':
44 buf.append("&amp;");
45 break;
46 case '\'':
47 buf.append("&apos;");
48 break;
49 case '\"':
50 buf.append("&quot;");
51 break;
52 default:
53 buf.append(c);
54 break;
58 return buf.makeStringAndClear();
61 } /* Namespace */
63 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */