123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287 |
- /*
- * CDE - Common Desktop Environment
- *
- * Copyright (c) 1993-2012, The Open Group. All rights reserved.
- *
- * These libraries and programs are free software; you can
- * redistribute them and/or modify them under the terms of the GNU
- * Lesser General Public License as published by the Free Software
- * Foundation; either version 2 of the License, or (at your option)
- * any later version.
- *
- * These libraries and programs are distributed in the hope that
- * they will be useful, but WITHOUT ANY WARRANTY; without even the
- * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
- * PURPOSE. See the GNU Lesser General Public License for more
- * details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with these libraries and programs; if not, write
- * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
- * Floor, Boston, MA 02110-1301 USA
- */
- /* $XConsortium: ExternalId.C /main/1 1996/07/29 16:51:51 cde-hp $ */
- // Copyright (c) 1994 James Clark
- // See the file COPYING for copying permission.
- #ifdef __GNUG__
- #pragma implementation
- #endif
- #include "splib.h"
- #include "ExternalId.h"
- #include "CharsetInfo.h"
- #include "macros.h"
- #include "ParserMessages.h"
- #ifdef SP_NAMESPACE
- namespace SP_NAMESPACE {
- #endif
- ExternalId::ExternalId()
- : haveSystem_(0), havePublic_(0)
- {
- }
- void ExternalId::setSystem(Text &text)
- {
- text.swap(system_);
- haveSystem_ = 1;
- }
- Boolean ExternalId::setPublic(Text &text, const CharsetInfo &charset,
- Char space, const MessageType1 *&error)
- {
- havePublic_ = 1;
- return public_.init(text, charset, space, error);
- }
- void ExternalId::setLocation(const Location &loc)
- {
- loc_ = loc;
- }
- PublicId::PublicId()
- : formal_(0), ownerType_(ISO), textClass_(CAPACITY), unavailable_(false), haveDisplayVersion_(false)
- {
- }
- Boolean PublicId::init(Text &text, const CharsetInfo &charset,
- Char space, const MessageType1 *&error)
- {
- text.swap(text_);
- const StringC &str = text_.string();
- formal_ = 0;
- const Char *next = str.data();
- const Char *lim = str.data() + str.size();
- Char solidus = charset.execToDesc('/');
- Char minus = charset.execToDesc('-');
- Char plus = charset.execToDesc('+');
- const Char *fieldStart;
- size_t fieldLength;
- if (!nextField(solidus, next, lim, fieldStart, fieldLength)) {
- error = &ParserMessages::fpiMissingField;
- return 0;
- }
- if (fieldLength == 1 && (*fieldStart == minus || *fieldStart == plus)) {
- ownerType_ = (*fieldStart == plus ? registered : unregistered);
- if (!nextField(solidus, next, lim, fieldStart, fieldLength)) {
- error = &ParserMessages::fpiMissingField;
- return 0;
- }
- }
- else
- ownerType_ = ISO;
- owner_.assign(fieldStart, fieldLength);
- if (!nextField(solidus, next, lim, fieldStart, fieldLength)) {
- error = &ParserMessages::fpiMissingField;
- return 0;
- }
- size_t i;
- for (i = 0; i < fieldLength; i++)
- if (fieldStart[i] == space)
- break;
- if (i >= fieldLength) {
- error = &ParserMessages::fpiMissingTextClassSpace;
- return 0;
- }
- StringC textClassString(fieldStart, i);
- if (!lookupTextClass(textClassString, charset, textClass_)) {
- error = &ParserMessages::fpiInvalidTextClass;
- return 0;
- }
- i++; // skip the space
- fieldStart += i;
- fieldLength -= i;
- if (fieldLength == 1 && *fieldStart == minus) {
- unavailable_ = 1;
- if (!nextField(solidus, next, lim, fieldStart, fieldLength)) {
- error = &ParserMessages::fpiMissingField;
- return 0;
- }
- }
- else
- unavailable_ = 0;
- description_.assign(fieldStart, fieldLength);
- if (!nextField(solidus, next, lim, fieldStart, fieldLength)) {
- error = &ParserMessages::fpiMissingField;
- return 0;
- }
- if (textClass_ != CHARSET) {
- for (i = 0; i < fieldLength; i++) {
- UnivChar c;
- if (!charset.descToUniv(fieldStart[i], c)
- || c < UnivCharsetDesc::A || c >= UnivCharsetDesc::A + 26) {
- error = &ParserMessages::fpiInvalidLanguage;
- return 0;
- }
- }
- // The public text language must be a name.
- // Names cannot be empty.
- if (fieldLength == 0) {
- error = &ParserMessages::fpiInvalidLanguage;
- return 0;
- }
- }
- languageOrDesignatingSequence_.assign(fieldStart, fieldLength);
- if (nextField(solidus, next, lim, fieldStart, fieldLength)) {
- switch (textClass_) {
- case CAPACITY:
- case CHARSET:
- case NOTATION:
- case SYNTAX:
- error = &ParserMessages::fpiIllegalDisplayVersion;
- return 0;
- default:
- break;
- }
- haveDisplayVersion_ = 1;
- displayVersion_.assign(fieldStart, fieldLength);
- }
- else
- haveDisplayVersion_ = 0;
- if (next != 0) {
- error = &ParserMessages::fpiExtraField;
- return 0;
- }
- formal_ = 1;
- return 1;
- }
- Boolean PublicId::nextField(Char solidus,
- const Char *&next,
- const Char *lim,
- const Char *&fieldStart,
- size_t &fieldLength)
- {
- if (next == 0)
- return 0;
- fieldStart = next;
- for (; next < lim; next++) {
- if (next[0] == solidus && next + 1 < lim && next[1] == solidus) {
- fieldLength = next - fieldStart;
- next += 2;
- return 1;
- }
- }
- fieldLength = lim - fieldStart;
- next = 0;
- return 1;
- }
- const char *const PublicId::textClasses[] = {
- "CAPACITY",
- "CHARSET",
- "DOCUMENT",
- "DTD",
- "ELEMENTS",
- "ENTITIES",
- "LPD",
- "NONSGML",
- "NOTATION",
- "SHORTREF",
- "SUBDOC",
- "SYNTAX",
- "TEXT",
- };
- Boolean PublicId::lookupTextClass(const StringC &str,
- const CharsetInfo &charset,
- TextClass &textClass)
- {
- for (size_t i = 0; i < SIZEOF(textClasses); i++)
- if (str == charset.execToDesc(textClasses[i])) {
- textClass = TextClass(i);
- return 1;
- }
- return 0;
- }
- Boolean PublicId::getOwnerType(OwnerType &result) const
- {
- if (!formal_)
- return 0;
- result = ownerType_;
- return 1;
- }
- Boolean PublicId::getOwner(StringC &result) const
- {
- if (!formal_)
- return 0;
- result = owner_;
- return 1;
- }
- Boolean PublicId::getTextClass(TextClass &result) const
- {
- if (!formal_)
- return 0;
- result = textClass_;
- return 1;
- }
- Boolean PublicId::getUnavailable(Boolean &result) const
- {
- if (!formal_)
- return 0;
- result = unavailable_;
- return 1;
- }
- Boolean PublicId::getDescription(StringC &result) const
- {
- if (!formal_)
- return 0;
- result = description_;
- return 1;
- }
- Boolean PublicId::getLanguage(StringC &result) const
- {
- if (!formal_ || textClass_ == CHARSET)
- return 0;
- result = languageOrDesignatingSequence_;
- return 1;
- }
- Boolean PublicId::getDesignatingSequence(StringC &result) const
- {
- if (!formal_ || textClass_ != CHARSET)
- return 0;
- result = languageOrDesignatingSequence_;
- return 1;
- }
- Boolean PublicId::getDisplayVersion(StringC &result) const
- {
- if (!formal_)
- return 0;
- if (haveDisplayVersion_)
- result = displayVersion_;
- return 1;
- }
- #ifdef SP_NAMESPACE
- }
- #endif
|