1*b725e8ebSAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
3*b725e8ebSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4*b725e8ebSAndrew Rist * or more contributor license agreements. See the NOTICE file
5*b725e8ebSAndrew Rist * distributed with this work for additional information
6*b725e8ebSAndrew Rist * regarding copyright ownership. The ASF licenses this file
7*b725e8ebSAndrew Rist * to you under the Apache License, Version 2.0 (the
8*b725e8ebSAndrew Rist * "License"); you may not use this file except in compliance
9*b725e8ebSAndrew Rist * with the License. You may obtain a copy of the License at
10cdf0e10cSrcweir *
11*b725e8ebSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir *
13*b725e8ebSAndrew Rist * Unless required by applicable law or agreed to in writing,
14*b725e8ebSAndrew Rist * software distributed under the License is distributed on an
15*b725e8ebSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*b725e8ebSAndrew Rist * KIND, either express or implied. See the License for the
17*b725e8ebSAndrew Rist * specific language governing permissions and limitations
18*b725e8ebSAndrew Rist * under the License.
19cdf0e10cSrcweir *
20*b725e8ebSAndrew Rist *************************************************************/
21*b725e8ebSAndrew Rist
22*b725e8ebSAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir #include "precompiled_xmlreader.hxx"
25cdf0e10cSrcweir #include "sal/config.h"
26cdf0e10cSrcweir
27cdf0e10cSrcweir #include "osl/diagnose.h"
28cdf0e10cSrcweir #include "rtl/string.h"
29cdf0e10cSrcweir #include "sal/types.h"
30cdf0e10cSrcweir #include "xmlreader/pad.hxx"
31cdf0e10cSrcweir #include "xmlreader/span.hxx"
32cdf0e10cSrcweir
33cdf0e10cSrcweir namespace xmlreader {
34cdf0e10cSrcweir
add(char const * begin,sal_Int32 length)35cdf0e10cSrcweir void Pad::add(char const * begin, sal_Int32 length) {
36cdf0e10cSrcweir OSL_ASSERT(
37cdf0e10cSrcweir begin != 0 && length >= 0 && !(span_.is() && buffer_.getLength() != 0));
38cdf0e10cSrcweir if (length != 0) {
39cdf0e10cSrcweir flushSpan();
40cdf0e10cSrcweir if (buffer_.getLength() == 0) {
41cdf0e10cSrcweir span_ = Span(begin, length);
42cdf0e10cSrcweir } else {
43cdf0e10cSrcweir buffer_.append(begin, length);
44cdf0e10cSrcweir }
45cdf0e10cSrcweir }
46cdf0e10cSrcweir }
47cdf0e10cSrcweir
addEphemeral(char const * begin,sal_Int32 length)48cdf0e10cSrcweir void Pad::addEphemeral(char const * begin, sal_Int32 length) {
49cdf0e10cSrcweir OSL_ASSERT(
50cdf0e10cSrcweir begin != 0 && length >= 0 && !(span_.is() && buffer_.getLength() != 0));
51cdf0e10cSrcweir if (length != 0) {
52cdf0e10cSrcweir flushSpan();
53cdf0e10cSrcweir buffer_.append(begin, length);
54cdf0e10cSrcweir }
55cdf0e10cSrcweir }
56cdf0e10cSrcweir
clear()57cdf0e10cSrcweir void Pad::clear() {
58cdf0e10cSrcweir OSL_ASSERT(!(span_.is() && buffer_.getLength() != 0));
59cdf0e10cSrcweir span_.clear();
60cdf0e10cSrcweir buffer_.setLength(0);
61cdf0e10cSrcweir }
62cdf0e10cSrcweir
get() const63cdf0e10cSrcweir Span Pad::get() const {
64cdf0e10cSrcweir OSL_ASSERT(!(span_.is() && buffer_.getLength() != 0));
65cdf0e10cSrcweir if (span_.is()) {
66cdf0e10cSrcweir return span_;
67cdf0e10cSrcweir } else if (buffer_.getLength() == 0) {
68cdf0e10cSrcweir return Span(RTL_CONSTASCII_STRINGPARAM(""));
69cdf0e10cSrcweir } else {
70cdf0e10cSrcweir return Span(buffer_.getStr(), buffer_.getLength());
71cdf0e10cSrcweir }
72cdf0e10cSrcweir }
73cdf0e10cSrcweir
flushSpan()74cdf0e10cSrcweir void Pad::flushSpan() {
75cdf0e10cSrcweir if (span_.is()) {
76cdf0e10cSrcweir buffer_.append(span_.begin, span_.length);
77cdf0e10cSrcweir span_.clear();
78cdf0e10cSrcweir }
79cdf0e10cSrcweir }
80cdf0e10cSrcweir
81cdf0e10cSrcweir }
82