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 "unohelper.hxx"
24 #include <rtl/ustring.hxx>
25 #include <com/sun/star/uno/Reference.hxx>
26 #include <com/sun/star/xml/dom/DocumentBuilder.hpp>
27 #include <comphelper/processfactory.hxx>
29 using com::sun::star::uno::Reference
;
30 using com::sun::star::uno::UNO_QUERY_THROW
;
31 using com::sun::star::container::XNameContainer
;
32 using com::sun::star::xml::dom::DocumentBuilder
;
33 using com::sun::star::xml::dom::XDocumentBuilder
;
37 // determine valid XML name
45 static inline sal_uInt8
lcl_getCharClass( sal_Unicode c
)
50 if( (c
>= 'A' && c
<= 'Z')
52 || (c
>= 'a' && c
<= 'z')
53 || (c
>= 0x00C0 && c
<= 0x00D6)
54 || (c
>= 0x00D8 && c
<= 0x00F6)
55 || (c
>= 0x00F8 && c
<= 0x02FF)
56 || (c
>= 0x0370 && c
<= 0x037D)
57 || (c
>= 0x037F && c
<= 0x1FFF)
58 || (c
>= 0x200C && c
<= 0x200D)
59 || (c
>= 0x2070 && c
<= 0x218F)
60 || (c
>= 0x2C00 && c
<= 0x2FEF)
61 || (c
>= 0x3001 && c
<= 0xD7FF)
62 || (c
>= 0xF900 && c
<= 0xFDCF)
63 || (c
>= 0xFDF0 && c
<= 0xFFFD)
66 || (c
>= 0xD800 && c
<= 0xDBFF)
67 || (c
>= 0xDC00 && c
<= 0xDFFF) )
73 || (c
>= '0' && c
<= '9')
75 || (c
>= 0x0300 && c
<= 0x036F)
76 || (c
>= 0x203F && c
<= 0x2040) )
88 bool isValidQName( const OUString
& sName
,
89 const Reference
<XNameContainer
>& /*xNamespaces*/ )
91 sal_Int32 nLength
= sName
.getLength();
92 const sal_Unicode
* pName
= sName
.getStr();
98 bRet
= ( ( lcl_getCharClass( pName
[0] ) & 4 ) != 0 );
99 for( sal_Int32 n
= 1; n
< nLength
; n
++ )
101 sal_uInt8 nClass
= lcl_getCharClass( pName
[n
] );
102 bRet
&= ( ( nClass
& 2 ) != 0 );
113 bool isValidPrefixName( const OUString
& sName
,
114 const Reference
<XNameContainer
>& /*xNamespaces*/ )
116 sal_Int32 nLength
= sName
.getLength();
117 const sal_Unicode
* pName
= sName
.getStr();
122 bRet
= ( ( lcl_getCharClass( pName
[0] ) & 4 ) != 0 );
123 for( sal_Int32 n
= 1; n
< nLength
; n
++ )
124 bRet
&= ( ( lcl_getCharClass( pName
[n
] ) & 8 ) != 0 );
130 Reference
<XDocumentBuilder
> getDocumentBuilder()
132 Reference
<XDocumentBuilder
> xBuilder(DocumentBuilder::create(::comphelper::getProcessComponentContext()));
136 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */