2 * CDE - Common Desktop Environment
4 * Copyright (c) 1993-2012, The Open Group. All rights reserved.
6 * These libraries and programs are free software; you can
7 * redistribute them and/or modify them under the terms of the GNU
8 * Lesser General Public License as published by the Free Software
9 * Foundation; either version 2 of the License, or (at your option)
12 * These libraries and programs are distributed in the hope that
13 * they will be useful, but WITHOUT ANY WARRANTY; without even the
14 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU Lesser General Public License for more
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with these librararies and programs; if not, write
20 * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21 * Floor, Boston, MA 02110-1301 USA
23 /* $XConsortium: ExternalId.C /main/1 1996/07/29 16:51:51 cde-hp $ */
24 // Copyright (c) 1994 James Clark
25 // See the file COPYING for copying permission.
28 #pragma implementation
31 #include "ExternalId.h"
32 #include "CharsetInfo.h"
34 #include "ParserMessages.h"
37 namespace SP_NAMESPACE {
40 ExternalId::ExternalId()
41 : haveSystem_(0), havePublic_(0)
45 void ExternalId::setSystem(Text &text)
51 Boolean ExternalId::setPublic(Text &text, const CharsetInfo &charset,
52 Char space, const MessageType1 *&error)
55 return public_.init(text, charset, space, error);
58 void ExternalId::setLocation(const Location &loc)
68 Boolean PublicId::init(Text &text, const CharsetInfo &charset,
69 Char space, const MessageType1 *&error)
72 const StringC &str = text_.string();
74 const Char *next = str.data();
75 const Char *lim = str.data() + str.size();
76 Char solidus = charset.execToDesc('/');
77 Char minus = charset.execToDesc('-');
78 Char plus = charset.execToDesc('+');
79 const Char *fieldStart;
81 if (!nextField(solidus, next, lim, fieldStart, fieldLength)) {
82 error = &ParserMessages::fpiMissingField;
85 if (fieldLength == 1 && (*fieldStart == minus || *fieldStart == plus)) {
86 ownerType_ = (*fieldStart == plus ? registered : unregistered);
87 if (!nextField(solidus, next, lim, fieldStart, fieldLength)) {
88 error = &ParserMessages::fpiMissingField;
94 owner_.assign(fieldStart, fieldLength);
95 if (!nextField(solidus, next, lim, fieldStart, fieldLength)) {
96 error = &ParserMessages::fpiMissingField;
100 for (i = 0; i < fieldLength; i++)
101 if (fieldStart[i] == space)
103 if (i >= fieldLength) {
104 error = &ParserMessages::fpiMissingTextClassSpace;
107 StringC textClassString(fieldStart, i);
108 if (!lookupTextClass(textClassString, charset, textClass_)) {
109 error = &ParserMessages::fpiInvalidTextClass;
112 i++; // skip the space
115 if (fieldLength == 1 && *fieldStart == minus) {
117 if (!nextField(solidus, next, lim, fieldStart, fieldLength)) {
118 error = &ParserMessages::fpiMissingField;
124 description_.assign(fieldStart, fieldLength);
125 if (!nextField(solidus, next, lim, fieldStart, fieldLength)) {
126 error = &ParserMessages::fpiMissingField;
129 if (textClass_ != CHARSET) {
130 for (i = 0; i < fieldLength; i++) {
132 if (!charset.descToUniv(fieldStart[i], c)
133 || c < UnivCharsetDesc::A || c >= UnivCharsetDesc::A + 26) {
134 error = &ParserMessages::fpiInvalidLanguage;
138 // The public text language must be a name.
139 // Names cannot be empty.
140 if (fieldLength == 0) {
141 error = &ParserMessages::fpiInvalidLanguage;
145 languageOrDesignatingSequence_.assign(fieldStart, fieldLength);
146 if (nextField(solidus, next, lim, fieldStart, fieldLength)) {
147 switch (textClass_) {
152 error = &ParserMessages::fpiIllegalDisplayVersion;
157 haveDisplayVersion_ = 1;
158 displayVersion_.assign(fieldStart, fieldLength);
161 haveDisplayVersion_ = 0;
163 error = &ParserMessages::fpiExtraField;
170 Boolean PublicId::nextField(Char solidus,
173 const Char *&fieldStart,
180 for (; next < lim; next++) {
181 if (next[0] == solidus && next + 1 < lim && next[1] == solidus) {
182 fieldLength = next - fieldStart;
187 fieldLength = lim - fieldStart;
192 const char *const PublicId::textClasses[] = {
208 Boolean PublicId::lookupTextClass(const StringC &str,
209 const CharsetInfo &charset,
210 TextClass &textClass)
212 for (size_t i = 0; i < SIZEOF(textClasses); i++)
213 if (str == charset.execToDesc(textClasses[i])) {
214 textClass = TextClass(i);
220 Boolean PublicId::getOwnerType(OwnerType &result) const
228 Boolean PublicId::getOwner(StringC &result) const
236 Boolean PublicId::getTextClass(TextClass &result) const
244 Boolean PublicId::getUnavailable(Boolean &result) const
248 result = unavailable_;
252 Boolean PublicId::getDescription(StringC &result) const
256 result = description_;
260 Boolean PublicId::getLanguage(StringC &result) const
262 if (!formal_ || textClass_ == CHARSET)
264 result = languageOrDesignatingSequence_;
268 Boolean PublicId::getDesignatingSequence(StringC &result) const
270 if (!formal_ || textClass_ != CHARSET)
272 result = languageOrDesignatingSequence_;
276 Boolean PublicId::getDisplayVersion(StringC &result) const
280 if (haveDisplayVersion_)
281 result = displayVersion_;