xref: /aoo41x/main/xmlreader/source/pad.cxx (revision cdf0e10c)
1 /*************************************************************************
2 *
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
6 *
7 * OpenOffice.org - a multi-platform office productivity suite
8 *
9 * This file is part of OpenOffice.org.
10 *
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
14 *
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
20 *
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org.  If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
25 *
26 ************************************************************************/
27 
28 #include "precompiled_xmlreader.hxx"
29 #include "sal/config.h"
30 
31 #include "osl/diagnose.h"
32 #include "rtl/string.h"
33 #include "sal/types.h"
34 #include "xmlreader/pad.hxx"
35 #include "xmlreader/span.hxx"
36 
37 namespace xmlreader {
38 
39 void Pad::add(char const * begin, sal_Int32 length) {
40     OSL_ASSERT(
41         begin != 0 && length >= 0 && !(span_.is() && buffer_.getLength() != 0));
42     if (length != 0) {
43         flushSpan();
44         if (buffer_.getLength() == 0) {
45             span_ = Span(begin, length);
46         } else {
47             buffer_.append(begin, length);
48         }
49     }
50 }
51 
52 void Pad::addEphemeral(char const * begin, sal_Int32 length) {
53     OSL_ASSERT(
54         begin != 0 && length >= 0 && !(span_.is() && buffer_.getLength() != 0));
55     if (length != 0) {
56         flushSpan();
57         buffer_.append(begin, length);
58     }
59 }
60 
61 void Pad::clear() {
62     OSL_ASSERT(!(span_.is() && buffer_.getLength() != 0));
63     span_.clear();
64     buffer_.setLength(0);
65 }
66 
67 Span Pad::get() const {
68     OSL_ASSERT(!(span_.is() && buffer_.getLength() != 0));
69     if (span_.is()) {
70         return span_;
71     } else if (buffer_.getLength() == 0) {
72         return Span(RTL_CONSTASCII_STRINGPARAM(""));
73     } else {
74         return Span(buffer_.getStr(), buffer_.getLength());
75     }
76 }
77 
78 void Pad::flushSpan() {
79     if (span_.is()) {
80         buffer_.append(span_.begin, span_.length);
81         span_.clear();
82     }
83 }
84 
85 }
86