LCOV - code coverage report
Current view: top level - libreoffice/xmlreader/source - pad.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 22 27 81.5 %
Date: 2012-12-27 Functions: 4 5 80.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     2985591 : void Pad::add(char const * begin, sal_Int32 length) {
      32             :     assert(
      33             :         begin != 0 && length >= 0 && !(span_.is() && buffer_.getLength() != 0));
      34     2985591 :     if (length != 0) {
      35     2981865 :         flushSpan();
      36     2981865 :         if (buffer_.getLength() == 0) {
      37     2971017 :             span_ = Span(begin, length);
      38             :         } else {
      39       10848 :             buffer_.append(begin, length);
      40             :         }
      41             :     }
      42     2985591 : }
      43             : 
      44           0 : void Pad::addEphemeral(char const * begin, sal_Int32 length) {
      45             :     assert(
      46             :         begin != 0 && length >= 0 && !(span_.is() && buffer_.getLength() != 0));
      47           0 :     if (length != 0) {
      48           0 :         flushSpan();
      49           0 :         buffer_.append(begin, length);
      50             :     }
      51           0 : }
      52             : 
      53     3009856 : void Pad::clear() {
      54             :     assert(!(span_.is() && buffer_.getLength() != 0));
      55     3009856 :     span_.clear();
      56     3009856 :     buffer_.setLength(0);
      57     3009856 : }
      58             : 
      59     3005733 : Span Pad::get() const {
      60             :     assert(!(span_.is() && buffer_.getLength() != 0));
      61     3005733 :     if (span_.is()) {
      62     2967422 :         return span_;
      63       38311 :     } else if (buffer_.getLength() == 0) {
      64       35646 :         return Span(RTL_CONSTASCII_STRINGPARAM(""));
      65             :     } else {
      66        2665 :         return Span(buffer_.getStr(), buffer_.getLength());
      67             :     }
      68             : }
      69             : 
      70     2981865 : void Pad::flushSpan() {
      71     2981865 :     if (span_.is()) {
      72        2665 :         buffer_.append(span_.begin, span_.length);
      73        2665 :         span_.clear();
      74             :     }
      75     2981865 : }
      76             : 
      77             : }
      78             : 
      79             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10