LCOV - code coverage report
Current view: top level - libreoffice/xmlreader/source - pad.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 27 27 100.0 %
Date: 2012-12-17 Functions: 5 5 100.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 "sal/config.h"
      21             : 
      22             : #include <cassert>
      23             : 
      24             : #include "rtl/string.h"
      25             : #include "sal/types.h"
      26             : #include "xmlreader/pad.hxx"
      27             : #include "xmlreader/span.hxx"
      28             : 
      29             : namespace xmlreader {
      30             : 
      31     9667779 : void Pad::add(char const * begin, sal_Int32 length) {
      32             :     assert(
      33             :         begin != 0 && length >= 0 && !(span_.is() && buffer_.getLength() != 0));
      34     9667779 :     if (length != 0) {
      35     9651699 :         flushSpan();
      36     9651699 :         if (buffer_.getLength() == 0) {
      37     9616539 :             span_ = Span(begin, length);
      38             :         } else {
      39       35160 :             buffer_.append(begin, length);
      40             :         }
      41             :     }
      42     9667779 : }
      43             : 
      44          96 : void Pad::addEphemeral(char const * begin, sal_Int32 length) {
      45             :     assert(
      46             :         begin != 0 && length >= 0 && !(span_.is() && buffer_.getLength() != 0));
      47          96 :     if (length != 0) {
      48          96 :         flushSpan();
      49          96 :         buffer_.append(begin, length);
      50             :     }
      51          96 : }
      52             : 
      53     9744287 : void Pad::clear() {
      54             :     assert(!(span_.is() && buffer_.getLength() != 0));
      55     9744287 :     span_.clear();
      56     9744287 :     buffer_.setLength(0);
      57     9744287 : }
      58             : 
      59     9731155 : Span Pad::get() const {
      60             :     assert(!(span_.is() && buffer_.getLength() != 0));
      61     9731155 :     if (span_.is()) {
      62     9605043 :         return span_;
      63      126112 :     } else if (buffer_.getLength() == 0) {
      64      117226 :         return Span(RTL_CONSTASCII_STRINGPARAM(""));
      65             :     } else {
      66        8886 :         return Span(buffer_.getStr(), buffer_.getLength());
      67             :     }
      68             : }
      69             : 
      70     9651795 : void Pad::flushSpan() {
      71     9651795 :     if (span_.is()) {
      72        8886 :         buffer_.append(span_.begin, span_.length);
      73        8886 :         span_.clear();
      74             :     }
      75     9651795 : }
      76             : 
      77             : }
      78             : 
      79             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10