fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / dtrans / source / cnttype / mcnttype.cxx
blobe9c2915dbe20feb0c1b33a271036420b3d816ae3
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 "mcnttype.hxx"
22 // namespace directives
24 using namespace com::sun::star::uno;
25 using namespace com::sun::star::lang;
26 using namespace com::sun::star::container;
27 using namespace std;
28 using namespace osl;
30 // constants
32 const char TSPECIALS[] = "()<>@,;:\\\"/[]?=";
33 const char TOKEN[] = "!#$%&'*+-0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ^_`abcdefghijklmnopqrstuvwxyz{|}~.";
34 const char SPACE[] = " ";
35 const char SEMICOLON[] = ";";
37 // ctor
39 CMimeContentType::CMimeContentType( const OUString& aCntType )
41 init( aCntType );
44 OUString SAL_CALL CMimeContentType::getMediaType( ) throw(RuntimeException, std::exception)
46 return m_MediaType;
49 OUString SAL_CALL CMimeContentType::getMediaSubtype( ) throw(RuntimeException, std::exception)
51 return m_MediaSubtype;
54 OUString SAL_CALL CMimeContentType::getFullMediaType( ) throw(RuntimeException, std::exception)
56 return m_MediaType + "/" + m_MediaSubtype;
59 Sequence< OUString > SAL_CALL CMimeContentType::getParameters( ) throw(RuntimeException, std::exception)
61 MutexGuard aGuard( m_aMutex );
63 Sequence< OUString > seqParams;
65 map< OUString, OUString >::iterator iter;
66 map< OUString, OUString >::iterator iter_end = m_ParameterMap.end( );
68 for ( iter = m_ParameterMap.begin( ); iter != iter_end; ++iter )
70 seqParams.realloc( seqParams.getLength( ) + 1 );
71 seqParams[seqParams.getLength( ) - 1] = iter->first;
74 return seqParams;
77 sal_Bool SAL_CALL CMimeContentType::hasParameter( const OUString& aName ) throw(RuntimeException, std::exception)
79 MutexGuard aGuard( m_aMutex );
80 return ( m_ParameterMap.end( ) != m_ParameterMap.find( aName ) );
83 OUString SAL_CALL CMimeContentType::getParameterValue( const OUString& aName ) throw(NoSuchElementException, RuntimeException, std::exception)
85 MutexGuard aGuard( m_aMutex );
87 if ( !hasParameter( aName ) )
88 throw NoSuchElementException( );
90 return m_ParameterMap.find( aName )->second;
93 void SAL_CALL CMimeContentType::init( const OUString& aCntType ) throw( IllegalArgumentException )
95 if ( aCntType.isEmpty( ) )
96 throw IllegalArgumentException( );
98 m_nPos = 0;
99 m_ContentType = aCntType;
100 getSym( );
101 type();
104 void SAL_CALL CMimeContentType::getSym()
106 if ( m_nPos < m_ContentType.getLength( ) )
108 m_nxtSym = m_ContentType.copy(m_nPos, 1);
109 ++m_nPos;
110 return;
113 m_nxtSym = OUString( );
116 void SAL_CALL CMimeContentType::acceptSym( const OUString& pSymTlb )
118 if ( pSymTlb.indexOf( m_nxtSym ) < 0 )
119 throw IllegalArgumentException( );
121 getSym();
124 void SAL_CALL CMimeContentType::skipSpaces()
126 while (m_nxtSym == SPACE)
127 getSym( );
130 void SAL_CALL CMimeContentType::type()
132 skipSpaces( );
134 OUString sToken(TOKEN);
136 // check FIRST( type )
137 if ( !isInRange( m_nxtSym, sToken ) )
138 throw IllegalArgumentException( );
140 // parse
141 while( !m_nxtSym.isEmpty( ) )
143 if ( isInRange( m_nxtSym, sToken ) )
144 m_MediaType += m_nxtSym;
145 else if ( isInRange( m_nxtSym, OUString("/ ") ) )
146 break;
147 else
148 throw IllegalArgumentException( );
149 getSym( );
152 // check FOLLOW( type )
153 skipSpaces( );
154 acceptSym( OUString("/") );
156 subtype( );
159 void SAL_CALL CMimeContentType::subtype()
161 skipSpaces( );
163 OUString sToken(TOKEN);
165 // check FIRST( subtype )
166 if ( !isInRange( m_nxtSym, sToken ) )
167 throw IllegalArgumentException( );
169 while( !m_nxtSym.isEmpty( ) )
171 if ( isInRange( m_nxtSym, sToken ) )
172 m_MediaSubtype += m_nxtSym;
173 else if ( isInRange( m_nxtSym, OUString("; ") ) )
174 break;
175 else
176 throw IllegalArgumentException( );
177 getSym( );
180 // parse the rest
181 skipSpaces( );
182 trailer();
185 void SAL_CALL CMimeContentType::trailer()
187 OUString sToken(TOKEN);
188 while( !m_nxtSym.isEmpty( ) )
190 if ( m_nxtSym == "(" )
192 getSym( );
193 comment( );
194 acceptSym( OUString(")") );
196 else if ( m_nxtSym == ";" )
198 // get the parameter name
199 getSym( );
200 skipSpaces( );
202 if ( !isInRange( m_nxtSym, sToken ) )
203 throw IllegalArgumentException( );
205 OUString pname = pName( );
207 skipSpaces();
208 acceptSym( OUString("=") );
210 // get the parameter value
211 skipSpaces( );
213 OUString pvalue = pValue( );
215 // insert into map
216 if ( !m_ParameterMap.insert( pair < const OUString, OUString > ( pname, pvalue ) ).second )
217 throw IllegalArgumentException( );
219 else
220 throw IllegalArgumentException( );
222 skipSpaces( );
226 OUString SAL_CALL CMimeContentType::pName( )
228 OUString pname;
230 OUString sToken(TOKEN);
231 while( !m_nxtSym.isEmpty( ) )
233 if ( isInRange( m_nxtSym, sToken ) )
234 pname += m_nxtSym;
235 else if ( isInRange( m_nxtSym, OUString("= ") ) )
236 break;
237 else
238 throw IllegalArgumentException( );
239 getSym( );
242 return pname;
245 OUString SAL_CALL CMimeContentType::pValue( )
247 OUString pvalue;
249 OUString sToken(TOKEN);
250 // quoted pvalue
251 if ( m_nxtSym == "\"" )
253 getSym( );
254 pvalue = quotedPValue( );
256 if ( pvalue[pvalue.getLength() - 1] != '"' )
257 throw IllegalArgumentException( );
259 // remove the last quote-sign
260 pvalue = pvalue.copy(0, pvalue.getLength() - 1);
262 if ( pvalue.isEmpty( ) )
263 throw IllegalArgumentException( );
265 else if ( isInRange( m_nxtSym, sToken ) ) // unquoted pvalue
267 pvalue = nonquotedPValue( );
269 else
270 throw IllegalArgumentException( );
272 return pvalue;
275 // the following combinations within a quoted value are not allowed:
276 // '";' (quote sign followed by semicolon) and '" ' (quote sign followed
277 // by space)
279 OUString SAL_CALL CMimeContentType::quotedPValue( )
281 OUString pvalue;
282 bool bAfterQuoteSign = false;
284 while ( !m_nxtSym.isEmpty( ) )
286 if ( bAfterQuoteSign && (
287 (m_nxtSym == SPACE) ||
288 (m_nxtSym == SEMICOLON))
291 break;
293 else if ( isInRange( m_nxtSym, OUStringLiteral(TOKEN) + TSPECIALS + SPACE ) )
295 pvalue += m_nxtSym;
296 if ( m_nxtSym == "\"" )
297 bAfterQuoteSign = true;
298 else
299 bAfterQuoteSign = false;
301 else
302 throw IllegalArgumentException( );
303 getSym( );
306 return pvalue;
309 OUString SAL_CALL CMimeContentType::nonquotedPValue( )
311 OUString pvalue;
313 OUString sToken(TOKEN);
314 while ( !m_nxtSym.isEmpty( ) )
316 if ( isInRange( m_nxtSym, sToken ) )
317 pvalue += m_nxtSym;
318 else if ( isInRange( m_nxtSym, OUString("; ") ) )
319 break;
320 else
321 throw IllegalArgumentException( );
322 getSym( );
325 return pvalue;
328 void SAL_CALL CMimeContentType::comment()
330 while ( !m_nxtSym.isEmpty( ) )
332 if ( isInRange( m_nxtSym, OUStringLiteral(TOKEN) + SPACE ) )
333 getSym( );
334 else if ( m_nxtSym == ")" )
335 break;
336 else
337 throw IllegalArgumentException( );
341 bool SAL_CALL CMimeContentType::isInRange( const OUString& aChr, const OUString& aRange )
343 return ( aRange.indexOf( aChr ) > -1 );
346 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */