tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / forms / source / xforms / xmlhelper.cxx
blob75f0f92bd5945dfef31a3f3a6f1f8043de23cec9
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 .
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
37 // character class:
38 // 1: NameStartChar
39 // 2: NameChar
40 // 4: NCNameStartChar
41 // 8: NCNameChar
42 static sal_uInt8 lcl_getCharClass( sal_Unicode c )
44 sal_uInt8 nClass = 0;
46 // NameStartChar
47 if( (c >= 'A' && c <= 'Z')
48 || c == '_'
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)
62 // surrogates
63 || (c >= 0xD800 && c <= 0xDBFF)
64 || (c >= 0xDC00 && c <= 0xDFFF) )
66 nClass = 15;
68 else if( c == '-'
69 || c == '.'
70 || (c >= '0' && c <= '9')
71 || (c == 0x00B7)
72 || (c >= 0x0300 && c <= 0x036F)
73 || (c >= 0x203F && c <= 0x2040) )
75 nClass = 10;
77 else if( c == ':' )
79 nClass = 3;
82 return nClass;
85 bool isValidQName( const OUString& sName,
86 const Reference<XNameContainer>& /*xNamespaces*/ )
88 sal_Int32 nLength = sName.getLength();
89 const sal_Unicode* pName = sName.getStr();
91 bool bRet = false;
92 sal_Int32 nColon = 0;
93 if( nLength > 0 )
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 );
100 if( nClass == 3 )
101 nColon++;
104 if( nColon > 1 )
105 bRet = false;
107 return bRet;
110 bool isValidPrefixName( const OUString& sName,
111 const Reference<XNameContainer>& /*xNamespaces*/ )
113 sal_Int32 nLength = sName.getLength();
114 const sal_Unicode* pName = sName.getStr();
115 bool bRet = false;
117 if( nLength > 0 )
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 );
124 return bRet;
127 Reference<XDocumentBuilder> getDocumentBuilder()
129 Reference<XDocumentBuilder> xBuilder(DocumentBuilder::create(::comphelper::getProcessComponentContext()));
130 return xBuilder;
133 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */