Avoid potential negative array index access to cached text.
[LibreOffice.git] / xmloff / source / chart / SchXMLParagraphContext.cxx
blob84e22c5a5c71b1a87744a02839a28901155167c1
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 .
21 #include "SchXMLParagraphContext.hxx"
23 #include <sal/log.hxx>
24 #include <xmloff/xmlimp.hxx>
25 #include <xmloff/xmlnamespace.hxx>
26 #include <xmloff/xmltoken.hxx>
27 #include <xmloff/namespacemap.hxx>
29 #include <com/sun/star/xml/sax/XAttributeList.hpp>
31 using namespace com::sun::star;
32 using namespace ::xmloff::token;
34 SchXMLParagraphContext::SchXMLParagraphContext( SvXMLImport& rImport,
35 OUString& rText,
36 OUString * pOutId /* = 0 */ ) :
37 SvXMLImportContext( rImport ),
38 mrText( rText ),
39 mpId( pOutId )
43 SchXMLParagraphContext::~SchXMLParagraphContext()
46 void SchXMLParagraphContext::startFastElement(
47 sal_Int32 /*nElement*/,
48 const uno::Reference< xml::sax::XFastAttributeList >& xAttrList )
50 // remember the id. It is used for storing the original cell range string in
51 // a local table (cached data)
52 if( !mpId )
53 return;
55 bool bHaveXmlId( false );
57 for( auto& aIter : sax_fastparser::castToFastAttributeList(xAttrList) )
59 switch(aIter.getToken())
61 case XML_ELEMENT(XML, XML_ID):
62 (*mpId) = aIter.toString();
63 bHaveXmlId = true;
64 break;
65 case XML_ELEMENT(TEXT, XML_ID):
66 { // text:id shall be ignored if xml:id exists
67 if (!bHaveXmlId)
69 (*mpId) = aIter.toString();
71 break;
73 default:
74 XMLOFF_WARN_UNKNOWN("xmloff", aIter);
79 void SchXMLParagraphContext::endFastElement(sal_Int32 )
81 mrText = maBuffer.makeStringAndClear();
84 css::uno::Reference< css::xml::sax::XFastContextHandler > SchXMLParagraphContext::createFastChildContext(
85 sal_Int32 nElement,
86 const css::uno::Reference< css::xml::sax::XFastAttributeList >& )
88 if( nElement == XML_ELEMENT(TEXT, XML_TAB_STOP) )
90 maBuffer.append( u'\x0009'); // tabulator
92 else if( nElement == XML_ELEMENT(TEXT, XML_LINE_BREAK) )
94 maBuffer.append( u'\x000A'); // linefeed
96 else
97 XMLOFF_WARN_UNKNOWN_ELEMENT("xmloff", nElement);
99 return nullptr;
102 void SchXMLParagraphContext::characters( const OUString& rChars )
104 maBuffer.append( rChars );
107 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */