Branch data 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 : 32139268 : void Pad::add(char const * begin, sal_Int32 length) {
32 : : assert(
33 : : begin != 0 && length >= 0 && !(span_.is() && buffer_.getLength() != 0));
34 [ + + ]: 32139268 : if (length != 0) {
35 : 32093156 : flushSpan();
36 [ + + ]: 32093156 : if (buffer_.getLength() == 0) {
37 : 32014576 : span_ = Span(begin, length);
38 : : } else {
39 : 78580 : buffer_.append(begin, length);
40 : : }
41 : : }
42 : 32139268 : }
43 : :
44 : 1920 : void Pad::addEphemeral(char const * begin, sal_Int32 length) {
45 : : assert(
46 : : begin != 0 && length >= 0 && !(span_.is() && buffer_.getLength() != 0));
47 [ + - ]: 1920 : if (length != 0) {
48 : 1920 : flushSpan();
49 : 1920 : buffer_.append(begin, length);
50 : : }
51 : 1920 : }
52 : :
53 : 32428354 : void Pad::clear() {
54 : : assert(!(span_.is() && buffer_.getLength() != 0));
55 : 32428354 : span_.clear();
56 : 32428354 : buffer_.setLength(0);
57 : 32428354 : }
58 : :
59 : 32394310 : Span Pad::get() const {
60 : : assert(!(span_.is() && buffer_.getLength() != 0));
61 [ + + ]: 32394310 : if (span_.is()) {
62 : 31989980 : return span_;
63 [ + + ]: 404330 : } else if (buffer_.getLength() == 0) {
64 : 382686 : return Span(RTL_CONSTASCII_STRINGPARAM(""));
65 : : } else {
66 : 32394310 : return Span(buffer_.getStr(), buffer_.getLength());
67 : : }
68 : : }
69 : :
70 : 32095076 : void Pad::flushSpan() {
71 [ + + ]: 32095076 : if (span_.is()) {
72 : 21644 : buffer_.append(span_.begin, span_.length);
73 : 21644 : span_.clear();
74 : : }
75 : 32095076 : }
76 : :
77 : : }
78 : :
79 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|