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/.
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 .
21 #include "xmlhelper.hxx"
23 #include <rtl/ustring.hxx>
24 #include <com/sun/star/uno/Reference.hxx>
25 #include <com/sun/star/xml/dom/DocumentBuilder.hpp>
26 #include <comphelper/processfactory.hxx>
28 using com::sun::star::uno::Reference
;
29 using com::sun::star::container::XNameContainer
;
30 using com::sun::star::xml::dom::DocumentBuilder
;
31 using com::sun::star::xml::dom::XDocumentBuilder
;
34 // determine valid XML name
42 static sal_uInt8
lcl_getCharClass( sal_Unicode c
)
47 if( (c
>= 'A' && c
<= 'Z')
49 || (c
>= 'a' && c
<= 'z')
50 || (c
>= 0x00C0 && c
<= 0x00D6)
51 || (c
>= 0x00D8 && c
<= 0x00F6)
52 || (c
>= 0x00F8 && c
<= 0x02FF)
53 || (c
>= 0x0370 && c
<= 0x037D)
54 || (c
>= 0x037F && c
<= 0x1FFF)
55 || (c
>= 0x200C && c
<= 0x200D)
56 || (c
>= 0x2070 && c
<= 0x218F)
57 || (c
>= 0x2C00 && c
<= 0x2FEF)
58 || (c
>= 0x3001 && c
<= 0xD7FF)
59 || (c
>= 0xF900 && c
<= 0xFDCF)
60 || (c
>= 0xFDF0 && c
<= 0xFFFD)
63 || (c
>= 0xD800 && c
<= 0xDBFF)
64 || (c
>= 0xDC00 && c
<= 0xDFFF) )
70 || (c
>= '0' && c
<= '9')
72 || (c
>= 0x0300 && c
<= 0x036F)
73 || (c
>= 0x203F && c
<= 0x2040) )
85 bool isValidQName( const OUString
& sName
,
86 const Reference
<XNameContainer
>& /*xNamespaces*/ )
88 sal_Int32 nLength
= sName
.getLength();
89 const sal_Unicode
* pName
= sName
.getStr();
95 bRet
= ( ( lcl_getCharClass( pName
[0] ) & 4 ) != 0 );
96 for( sal_Int32 n
= 1; n
< nLength
; n
++ )
98 sal_uInt8 nClass
= lcl_getCharClass( pName
[n
] );
99 bRet
&= ( ( nClass
& 2 ) != 0 );
110 bool isValidPrefixName( const OUString
& sName
,
111 const Reference
<XNameContainer
>& /*xNamespaces*/ )
113 sal_Int32 nLength
= sName
.getLength();
114 const sal_Unicode
* pName
= sName
.getStr();
119 bRet
= ( ( lcl_getCharClass( pName
[0] ) & 4 ) != 0 );
120 for( sal_Int32 n
= 1; n
< nLength
; n
++ )
121 bRet
&= ( ( lcl_getCharClass( pName
[n
] ) & 8 ) != 0 );
127 Reference
<XDocumentBuilder
> getDocumentBuilder()
129 Reference
<XDocumentBuilder
> xBuilder(DocumentBuilder::create(::comphelper::getProcessComponentContext()));
133 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */