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

Generated by: LCOV version 1.10