1 /*
2 * Copyright (c) 1999-2000, Eric Moon.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions, and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions, and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 *
16 * 3. The name of the author may not be used to endorse or promote products
17 * derived from this software without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR
20 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
21 * OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
23 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
26 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
27 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */
30
31
32 // StringContent.cpp
33
34 #include "StringContent.h"
35 #include "ImportContext.h"
36
37 #include <cctype>
38
39 __USE_CORTEX_NAMESPACE
40
41 // -------------------------------------------------------- //
42 // EXPORT [not implemented]
43 // -------------------------------------------------------- //
44
xmlExportBegin(ExportContext & context) const45 void StringContent::xmlExportBegin(
46 ExportContext& context) const {
47 context.reportError("StringContent: no export");
48 }
xmlExportAttributes(ExportContext & context) const49 void StringContent::xmlExportAttributes(
50 ExportContext& context) const {
51 context.reportError("StringContent: no export");
52 }
xmlExportContent(ExportContext & context) const53 void StringContent::xmlExportContent(
54 ExportContext& context) const {
55 context.reportError("StringContent: no export");
56 }
xmlExportEnd(ExportContext & context) const57 void StringContent::xmlExportEnd(
58 ExportContext& context) const {
59 context.reportError("StringContent: no export");
60 }
61
62 // -------------------------------------------------------- //
63 // IMPORT
64 // -------------------------------------------------------- //
65
xmlImportBegin(ImportContext & context)66 void StringContent::xmlImportBegin(
67 ImportContext& context) {}
68
xmlImportAttribute(const char * key,const char * value,ImportContext & context)69 void StringContent::xmlImportAttribute(
70 const char* key,
71 const char* value,
72 ImportContext& context) {}
73
xmlImportContent(const char * data,uint32 length,ImportContext & context)74 void StringContent::xmlImportContent(
75 const char* data,
76 uint32 length,
77 ImportContext& context) {
78 content.Append(data, length);
79 }
80
xmlImportChild(IPersistent * child,ImportContext & context)81 void StringContent::xmlImportChild(
82 IPersistent* child,
83 ImportContext& context) {
84 context.reportError("StringContent: child not expected");
85 }
86
xmlImportComplete(ImportContext & context)87 void StringContent::xmlImportComplete(
88 ImportContext& context) {
89
90 // chomp leading/trailing whitespace
91 if(content.Length() == 0)
92 return;
93
94 int32 last = 0;
95 for(; last < content.Length() && isspace(content[last]); ++last) {}
96 if(last > 0)
97 content.Remove(0, last);
98
99 last = content.Length() - 1;
100 int32 from = last;
101 for(; from > 0 && isspace(content[from]); --from) {}
102 if(from < last)
103 content.Remove(from+1, last-from);
104 }
105
106 // END -- StringContent.cpp --
107
108