LCOV - code coverage report
Current view: top level - svl/source/misc - ownlist.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 0 57 0.0 %
Date: 2015-06-13 12:38:46 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 <com/sun/star/beans/PropertyValues.hpp>
      22             : 
      23             : #include <svl/ownlist.hxx>
      24             : 
      25             : using namespace com::sun::star;
      26             : 
      27             : 
      28           0 : static OUString parseString(const OUString & rCmd, sal_Int32 * pIndex)
      29             : {
      30           0 :     OUString result;
      31             : 
      32           0 :     if(rCmd[*pIndex] == '\"') {
      33           0 :         (*pIndex) ++;
      34             : 
      35           0 :         sal_Int32 begin = *pIndex;
      36             : 
      37           0 :         while(*pIndex < rCmd.getLength() && rCmd[(*pIndex) ++] != '\"') ;
      38             : 
      39           0 :         result = rCmd.copy(begin, *pIndex - begin - 1);
      40             :     }
      41             : 
      42           0 :     return result;
      43             : }
      44             : 
      45           0 : static OUString parseWord(const OUString & rCmd, sal_Int32 * pIndex)
      46             : {
      47           0 :     sal_Int32 begin = *pIndex;
      48             : 
      49           0 :     while(*pIndex < rCmd.getLength()
      50           0 :           && !isspace(sal::static_int_cast<int>(rCmd[*pIndex]))
      51           0 :           && rCmd[*pIndex] != '=')
      52           0 :         (*pIndex) ++;
      53             : 
      54           0 :     return rCmd.copy(begin, *pIndex - begin);
      55             : }
      56             : 
      57           0 : static void eatSpace(const OUString & rCmd, sal_Int32 * pIndex)
      58             : {
      59           0 :     while(*pIndex < rCmd.getLength() && isspace(sal::static_int_cast<int>(rCmd[*pIndex])))
      60           0 :         (*pIndex) ++;
      61           0 : }
      62             : 
      63             : /**
      64             :  * Text is parsed and the single commands are added to the list.
      65             :  *
      66             :  * @returns bool  true
      67             :  *                The text was correctly parsed
      68             :                   false
      69             :                   The text was not parsed correctly
      70             : */
      71           0 : bool SvCommandList::AppendCommands
      72             : (
      73             :  const OUString & rCmd,    /* This text is translated to commands */
      74             :  sal_Int32 * pEaten        /* Count of chars that have been read */
      75             : )
      76             : {
      77           0 :     sal_Int32 index = 0;
      78           0 :     while(index < rCmd.getLength())
      79             :     {
      80             : 
      81           0 :         eatSpace(rCmd, &index);
      82           0 :         OUString name = (rCmd[index] == '\"') ? parseString(rCmd, &index) : parseWord(rCmd, &index);
      83             : 
      84           0 :         eatSpace(rCmd, &index);
      85           0 :         OUString value;
      86           0 :         if(index < rCmd.getLength() && rCmd[index] == '=')
      87             :         {
      88           0 :             index ++;
      89             : 
      90           0 :             eatSpace(rCmd, &index);
      91           0 :             value = (rCmd[index] == '\"') ? parseString(rCmd, &index) : parseWord(rCmd, &index);
      92             :         }
      93             : 
      94           0 :         aCommandList.push_back( SvCommand(name, value));
      95           0 :     }
      96             : 
      97           0 :     *pEaten = index;
      98             : 
      99           0 :     return true;
     100             : }
     101             : 
     102             : /**
     103             :  * An object of the type SvCommand is created and the list is
     104             :  * attached.
     105             :  *
     106             :  * @returns SvCommand & The created object
     107             : */
     108           0 : SvCommand & SvCommandList::Append
     109             : (
     110             :  const OUString & rCommand,    /* The command */
     111             :  const OUString & rArg         /* The command's argument */
     112             : )
     113             : {
     114           0 :     aCommandList.push_back( SvCommand( rCommand, rArg ) );
     115           0 :     return aCommandList.back();
     116             : }
     117             : 
     118           0 : bool SvCommandList::FillFromSequence( const com::sun::star::uno::Sequence < com::sun::star::beans::PropertyValue >& aCommandSequence )
     119             : {
     120           0 :     const sal_Int32 nCount = aCommandSequence.getLength();
     121           0 :     OUString aCommand, aArg;
     122           0 :     OUString aApiArg;
     123           0 :     for( sal_Int32 nIndex=0; nIndex<nCount; nIndex++ )
     124             :     {
     125           0 :         aCommand = aCommandSequence[nIndex].Name;
     126           0 :         if( !( aCommandSequence[nIndex].Value >>= aApiArg ) )
     127           0 :             return false;
     128           0 :         aArg = aApiArg;
     129           0 :         Append( aCommand, aArg );
     130             :     }
     131             : 
     132           0 :     return true;
     133             : }
     134             : 
     135           0 : void SvCommandList::FillSequence( com::sun::star::uno::Sequence < com::sun::star::beans::PropertyValue >& aCommandSequence )
     136             : {
     137           0 :     const sal_Int32 nCount = aCommandList.size();
     138           0 :     aCommandSequence.realloc( nCount );
     139           0 :     for( sal_Int32 nIndex = 0; nIndex < nCount; nIndex++ )
     140             :     {
     141           0 :         aCommandSequence[nIndex].Name = aCommandList[ nIndex ].GetCommand();
     142           0 :         aCommandSequence[nIndex].Handle = -1;
     143           0 :         aCommandSequence[nIndex].Value = uno::makeAny( aCommandList[ nIndex ].GetArgument() );
     144           0 :         aCommandSequence[nIndex].State = beans::PropertyState_DIRECT_VALUE;
     145             :     }
     146           0 : }
     147             : 
     148             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11