LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/svl/source/misc - ownlist.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 57 0.0 %
Date: 2013-07-09 Functions: 0 7 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             : #include <ctype.h>
      21             : #include <stdio.h>
      22             : #include <com/sun/star/beans/PropertyValues.hpp>
      23             : 
      24             : #include <svl/ownlist.hxx>
      25             : 
      26             : using namespace com::sun::star;
      27             : 
      28             : //=========================================================================
      29             : //============== SvCommandList ============================================
      30             : //=========================================================================
      31             : 
      32           0 : static OUString parseString(const OUString & rCmd, sal_Int32 * pIndex)
      33             : {
      34           0 :     OUString result;
      35             : 
      36           0 :     if(rCmd[*pIndex] == sal_Unicode('\"')) {
      37           0 :         (*pIndex) ++;
      38             : 
      39           0 :         sal_Int32 begin = *pIndex;
      40             : 
      41           0 :         while(*pIndex < rCmd.getLength() && rCmd[(*pIndex) ++] != sal_Unicode('\"')) ;
      42             : 
      43           0 :         result = rCmd.copy(begin, *pIndex - begin - 1);
      44             :     }
      45             : 
      46           0 :     return result;
      47             : }
      48             : 
      49           0 : static OUString parseWord(const OUString & rCmd, sal_Int32 * pIndex)
      50             : {
      51           0 :     sal_Int32 begin = *pIndex;
      52             : 
      53           0 :     while(*pIndex < rCmd.getLength()
      54           0 :           && !isspace(sal::static_int_cast<int>(rCmd[*pIndex]))
      55           0 :           && rCmd[*pIndex] != sal_Unicode('='))
      56           0 :         (*pIndex) ++;
      57             : 
      58           0 :     return rCmd.copy(begin, *pIndex - begin);
      59             : }
      60             : 
      61           0 : static void eatSpace(const OUString & rCmd, sal_Int32 * pIndex)
      62             : {
      63           0 :     while(*pIndex < rCmd.getLength() && isspace(sal::static_int_cast<int>(rCmd[*pIndex])))
      64           0 :         (*pIndex) ++;
      65           0 : }
      66             : 
      67             : 
      68             : //=========================================================================
      69           0 : bool SvCommandList::AppendCommands
      70             : (
      71             :  const OUString & rCmd,    /* Dieser Text wird in Kommandos umgesetzt */
      72             :  sal_Int32 * pEaten         /* Anzahl der Zeichen, die gelesen wurden */
      73             : )
      74             : /*  [Beschreibung]
      75             : 
      76             :     Es wird eine Text geparsed und die einzelnen Kommandos werden an
      77             :     die Liste angeh"angt.
      78             : 
      79             :     [R"uckgabewert]
      80             : 
      81             :     bool        true, der Text wurde korrekt geparsed.
      82             :                 false, der Text wurde nicht korrekt geparsed.
      83             : */
      84             : {
      85           0 :     sal_Int32 index = 0;
      86           0 :     while(index < rCmd.getLength())
      87             :     {
      88             : 
      89           0 :         eatSpace(rCmd, &index);
      90           0 :         OUString name = (rCmd[index] == sal_Unicode('\"')) ? parseString(rCmd, &index) : parseWord(rCmd, &index);
      91             : 
      92           0 :         eatSpace(rCmd, &index);
      93           0 :         OUString value;
      94           0 :         if(index < rCmd.getLength() && rCmd[index] == sal_Unicode('='))
      95             :         {
      96           0 :             index ++;
      97             : 
      98           0 :             eatSpace(rCmd, &index);
      99           0 :             value = (rCmd[index] == sal_Unicode('\"')) ? parseString(rCmd, &index) : parseWord(rCmd, &index);
     100             :         }
     101             : 
     102           0 :         aCommandList.push_back( SvCommand(name, value));
     103           0 :     }
     104             : 
     105           0 :     *pEaten = index;
     106             : 
     107           0 :     return true;
     108             : }
     109             : 
     110             : //=========================================================================
     111           0 : SvCommand & SvCommandList::Append
     112             : (
     113             :  const OUString & rCommand,    /* das Kommando */
     114             :  const OUString & rArg         /* dasArgument des Kommandos */
     115             : )
     116             : /*  [Beschreibung]
     117             : 
     118             :     Es wird eine Objekt vom Typ SvCommand erzeugt und an die Liste
     119             :     angeh"angt.
     120             : 
     121             :     [R"uckgabewert]
     122             : 
     123             :     SvCommand &     Das erteugte Objekt wird zur"uckgegeben.
     124             : */
     125             : {
     126           0 :     aCommandList.push_back( SvCommand( rCommand, rArg ) );
     127           0 :     return aCommandList.back();
     128             : }
     129             : 
     130           0 : bool SvCommandList::FillFromSequence( const com::sun::star::uno::Sequence < com::sun::star::beans::PropertyValue >& aCommandSequence )
     131             : {
     132           0 :     const sal_Int32 nCount = aCommandSequence.getLength();
     133           0 :     OUString aCommand, aArg;
     134           0 :     OUString aApiArg;
     135           0 :     for( sal_Int32 nIndex=0; nIndex<nCount; nIndex++ )
     136             :     {
     137           0 :         aCommand = aCommandSequence[nIndex].Name;
     138           0 :         if( !( aCommandSequence[nIndex].Value >>= aApiArg ) )
     139           0 :             return false;
     140           0 :         aArg = aApiArg;
     141           0 :         Append( aCommand, aArg );
     142             :     }
     143             : 
     144           0 :     return true;
     145             : }
     146             : 
     147           0 : void SvCommandList::FillSequence( com::sun::star::uno::Sequence < com::sun::star::beans::PropertyValue >& aCommandSequence )
     148             : {
     149           0 :     const sal_Int32 nCount = aCommandList.size();
     150           0 :     aCommandSequence.realloc( nCount );
     151           0 :     for( sal_Int32 nIndex = 0; nIndex < nCount; nIndex++ )
     152             :     {
     153           0 :         aCommandSequence[nIndex].Name = aCommandList[ nIndex ].GetCommand();
     154           0 :         aCommandSequence[nIndex].Handle = -1;
     155           0 :         aCommandSequence[nIndex].Value = uno::makeAny( aCommandList[ nIndex ].GetArgument() );
     156           0 :         aCommandSequence[nIndex].State = beans::PropertyState_DIRECT_VALUE;
     157             :     }
     158           0 : }
     159             : 
     160             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10