LCOV - code coverage report
Current view: top level - libreoffice/forms/source/xforms - xmlhelper.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 36 0.0 %
Date: 2012-12-27 Functions: 0 4 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       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/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      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 .
      18             :  */
      19             : 
      20             : 
      21             : #include "xmlhelper.hxx"
      22             : 
      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>
      28             : 
      29             : using rtl::OUString;
      30             : using com::sun::star::uno::Reference;
      31             : using com::sun::star::uno::UNO_QUERY_THROW;
      32             : using com::sun::star::container::XNameContainer;
      33             : using com::sun::star::xml::dom::DocumentBuilder;
      34             : using com::sun::star::xml::dom::XDocumentBuilder;
      35             : 
      36             : 
      37             : //
      38             : // determine valid XML name
      39             : //
      40             : 
      41             : // character class:
      42             : // 1: NameStartChar
      43             : // 2: NameChar
      44             : // 4: NCNameStartChar
      45             : // 8: NCNameChar
      46           0 : static inline sal_uInt8 lcl_getCharClass( sal_Unicode c )
      47             : {
      48           0 :     sal_uInt8 nClass = 0;
      49             : 
      50             :     // NameStartChar
      51           0 :     if( (c >= 'A' && c <= 'Z')
      52             :         || c == '_'
      53             :         || (c >=    'a' && c <=    'z')
      54             :         || (c >= 0x00C0 && c <= 0x00D6)
      55             :         || (c >= 0x00D8 && c <= 0x00F6)
      56             :         || (c >= 0x00F8 && c <= 0x02FF)
      57             :         || (c >= 0x0370 && c <= 0x037D)
      58             :         || (c >= 0x037F && c <= 0x1FFF)
      59             :         || (c >= 0x200C && c <= 0x200D)
      60             :         || (c >= 0x2070 && c <= 0x218F)
      61             :         || (c >= 0x2C00 && c <= 0x2FEF)
      62             :         || (c >= 0x3001 && c <= 0xD7FF)
      63             :         || (c >= 0xF900 && c <= 0xFDCF)
      64             :         || (c >= 0xFDF0 && c <= 0xFFFD)
      65             : 
      66             :         // surrogates
      67             :         || (c >= 0xD800 && c <= 0xDBFF)
      68             :         || (c >= 0xDC00 && c <= 0xDFFF) )
      69             :     {
      70           0 :         nClass = 15;
      71             :     }
      72           0 :     else if( c == '-'
      73             :              || c == '.'
      74             :              || (c >= '0' && c <= '9')
      75             :              || (c == 0x00B7)
      76             :              || (c >= 0x0300 && c <= 0x036F)
      77             :              || (c >= 0x203F && c <= 0x2040) )
      78             :     {
      79           0 :         nClass = 10;
      80             :     }
      81           0 :     else if( c == ':' )
      82             :     {
      83           0 :         nClass = 3;
      84             :     }
      85             : 
      86           0 :     return nClass;
      87             : }
      88             : 
      89           0 : bool isValidQName( const OUString& sName,
      90             :                    const Reference<XNameContainer>& /*xNamespaces*/ )
      91             : {
      92           0 :     sal_Int32 nLength = sName.getLength();
      93           0 :     const sal_Unicode* pName = sName.getStr();
      94             : 
      95           0 :     bool bRet = false;
      96           0 :     sal_Int32 nColon = 0;
      97           0 :     if( nLength > 0 )
      98             :     {
      99           0 :         bRet = ( ( lcl_getCharClass( pName[0] ) & 4 ) != 0 );
     100           0 :         for( sal_Int32 n = 1; n < nLength; n++ )
     101             :         {
     102           0 :             sal_uInt8 nClass = lcl_getCharClass( pName[n] );
     103           0 :             bRet &= ( ( nClass & 2 ) != 0 );
     104           0 :             if( nClass == 3 )
     105           0 :                 nColon++;
     106             :         }
     107             :     }
     108           0 :     if( nColon > 1 )
     109           0 :         bRet = sal_False;
     110             : 
     111           0 :     return bRet;
     112             : }
     113             : 
     114           0 : bool isValidPrefixName( const OUString& sName,
     115             :                         const Reference<XNameContainer>& /*xNamespaces*/ )
     116             : {
     117           0 :     sal_Int32 nLength = sName.getLength();
     118           0 :     const sal_Unicode* pName = sName.getStr();
     119           0 :     bool bRet = false;
     120             : 
     121           0 :     if( nLength > 0 )
     122             :     {
     123           0 :         bRet = ( ( lcl_getCharClass( pName[0] ) & 4 ) != 0 );
     124           0 :         for( sal_Int32 n = 1; n < nLength; n++ )
     125           0 :             bRet &= ( ( lcl_getCharClass( pName[n] ) & 8 ) != 0 );
     126             :     }
     127             : 
     128           0 :     return bRet;
     129             : }
     130             : 
     131           0 : Reference<XDocumentBuilder> getDocumentBuilder()
     132             : {
     133           0 :     Reference<XDocumentBuilder> xBuilder(DocumentBuilder::create(::comphelper::getProcessComponentContext()));
     134           0 :     return xBuilder;
     135             : }
     136             : 
     137             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10