bump product version to 5.0.4.1
[LibreOffice.git] / svl / source / misc / ownlist.cxx
blobd2b87c9b8ad6073285be5ad10520adec83305974
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 .
20 #include <ctype.h>
21 #include <com/sun/star/beans/PropertyValues.hpp>
23 #include <svl/ownlist.hxx>
25 using namespace com::sun::star;
28 static OUString parseString(const OUString & rCmd, sal_Int32 * pIndex)
30 OUString result;
32 if(rCmd[*pIndex] == '\"') {
33 (*pIndex) ++;
35 sal_Int32 begin = *pIndex;
37 while(*pIndex < rCmd.getLength() && rCmd[(*pIndex) ++] != '\"') ;
39 result = rCmd.copy(begin, *pIndex - begin - 1);
42 return result;
45 static OUString parseWord(const OUString & rCmd, sal_Int32 * pIndex)
47 sal_Int32 begin = *pIndex;
49 while(*pIndex < rCmd.getLength()
50 && !isspace(sal::static_int_cast<int>(rCmd[*pIndex]))
51 && rCmd[*pIndex] != '=')
52 (*pIndex) ++;
54 return rCmd.copy(begin, *pIndex - begin);
57 static void eatSpace(const OUString & rCmd, sal_Int32 * pIndex)
59 while(*pIndex < rCmd.getLength() && isspace(sal::static_int_cast<int>(rCmd[*pIndex])))
60 (*pIndex) ++;
63 /**
64 * Text is parsed and the single commands are added to the list.
66 * @returns bool true
67 * The text was correctly parsed
68 false
69 The text was not parsed correctly
71 bool SvCommandList::AppendCommands
73 const OUString & rCmd, /* This text is translated to commands */
74 sal_Int32 * pEaten /* Count of chars that have been read */
77 sal_Int32 index = 0;
78 while(index < rCmd.getLength())
81 eatSpace(rCmd, &index);
82 OUString name = (rCmd[index] == '\"') ? parseString(rCmd, &index) : parseWord(rCmd, &index);
84 eatSpace(rCmd, &index);
85 OUString value;
86 if(index < rCmd.getLength() && rCmd[index] == '=')
88 index ++;
90 eatSpace(rCmd, &index);
91 value = (rCmd[index] == '\"') ? parseString(rCmd, &index) : parseWord(rCmd, &index);
94 aCommandList.push_back( SvCommand(name, value));
97 *pEaten = index;
99 return true;
103 * An object of the type SvCommand is created and the list is
104 * attached.
106 * @returns SvCommand & The created object
108 SvCommand & SvCommandList::Append
110 const OUString & rCommand, /* The command */
111 const OUString & rArg /* The command's argument */
114 aCommandList.push_back( SvCommand( rCommand, rArg ) );
115 return aCommandList.back();
118 bool SvCommandList::FillFromSequence( const com::sun::star::uno::Sequence < com::sun::star::beans::PropertyValue >& aCommandSequence )
120 const sal_Int32 nCount = aCommandSequence.getLength();
121 OUString aCommand, aArg;
122 OUString aApiArg;
123 for( sal_Int32 nIndex=0; nIndex<nCount; nIndex++ )
125 aCommand = aCommandSequence[nIndex].Name;
126 if( !( aCommandSequence[nIndex].Value >>= aApiArg ) )
127 return false;
128 aArg = aApiArg;
129 Append( aCommand, aArg );
132 return true;
135 void SvCommandList::FillSequence( com::sun::star::uno::Sequence < com::sun::star::beans::PropertyValue >& aCommandSequence )
137 const sal_Int32 nCount = aCommandList.size();
138 aCommandSequence.realloc( nCount );
139 for( sal_Int32 nIndex = 0; nIndex < nCount; nIndex++ )
141 aCommandSequence[nIndex].Name = aCommandList[ nIndex ].GetCommand();
142 aCommandSequence[nIndex].Handle = -1;
143 aCommandSequence[nIndex].Value = uno::makeAny( aCommandList[ nIndex ].GetArgument() );
144 aCommandSequence[nIndex].State = beans::PropertyState_DIRECT_VALUE;
148 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */