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