Initial import of the CDE 2.1.30 sources from the Open Group.
[oweals/cde.git] / cde / programs / nsgmls / ExternalId.h
1 /* $XConsortium: ExternalId.h /main/1 1996/07/29 16:51:56 cde-hp $ */
2 // Copyright (c) 1994 James Clark
3 // See the file COPYING for copying permission.
4
5 #ifndef ExternalId_INCLUDED
6 #define ExternalId_INCLUDED 1
7 #ifdef __GNUG__
8 #pragma interface
9 #endif
10
11 #include "Boolean.h"
12 #include "StringC.h"
13 #include "Text.h"
14 #include "types.h"
15 #include "Message.h"
16
17 #ifdef SP_NAMESPACE
18 namespace SP_NAMESPACE {
19 #endif
20
21 class CharsetInfo;
22
23 class SP_API PublicId {
24 public:
25   enum TextClass {
26     CAPACITY,
27     CHARSET,
28     DOCUMENT,
29     DTD,
30     ELEMENTS,
31     ENTITIES,
32     LPD,
33     NONSGML,
34     NOTATION,
35     SHORTREF,
36     SUBDOC,
37     SYNTAX,
38     TEXT
39   };
40   enum OwnerType {
41     ISO,
42     registered,
43     unregistered
44     };
45   PublicId();
46
47   Boolean getOwnerType(OwnerType &) const;
48   Boolean getOwner(StringC &) const;
49   Boolean getTextClass(TextClass &) const;
50   Boolean getUnavailable(Boolean &) const;
51   Boolean getDescription(StringC &) const;
52   Boolean getLanguage(StringC &) const;
53   Boolean getDesignatingSequence(StringC &) const;
54   Boolean getDisplayVersion(StringC &) const;
55   // If it's not a valid formal public identifier, return 0
56   // and set error, otherwise return 1.
57   // charset describes the character set to use for parsing the
58   // id.
59   Boolean init(Text &, const CharsetInfo &, Char space,
60                const MessageType1 *&error);
61   const StringC &string() const;
62   const Text &text() const;
63 private:
64   static Boolean nextField(Char solidus,
65                            const Char *&next,
66                            const Char *lim,
67                            const Char *&fieldStart,
68                            size_t &fieldLength);
69   static Boolean lookupTextClass(const StringC &, const CharsetInfo &,
70                                  TextClass &);
71   static const char *const textClasses[];
72
73   PackedBoolean formal_;
74   OwnerType ownerType_;
75   StringC owner_;
76   TextClass textClass_;
77   PackedBoolean unavailable_;
78   StringC description_;
79   StringC languageOrDesignatingSequence_;
80   PackedBoolean haveDisplayVersion_;
81   StringC displayVersion_;
82   Text text_;
83 };
84
85 class SP_API ExternalId {
86 public:
87   ExternalId();
88   const StringC *systemIdString() const;
89   const StringC *publicIdString() const;
90   const StringC &effectiveSystemId() const;
91   const Text *systemIdText() const;
92   const Text *publicIdText() const;
93   const PublicId *publicId() const;
94   void setSystem(Text &);
95   void setEffectiveSystem(StringC &);
96   // If it's not a valid formal public identifier, return 0
97   // and set error, otherwise return 1.
98   // charset describes the character set to use for parsing the
99   // id.
100   Boolean setPublic(Text &, const CharsetInfo &, Char space,
101                     const MessageType1 *&error);
102   void setLocation(const Location &);
103   // location of keyword
104   const Location &location() const;
105 private:
106   PackedBoolean haveSystem_;
107   PackedBoolean havePublic_;
108   Text system_;
109   PublicId public_;
110   Location loc_;
111   StringC effectiveSystem_;
112 };
113
114 inline
115 const StringC &PublicId::string() const
116 {
117   return text_.string();
118 }
119
120 inline
121 const Text &PublicId::text() const
122 {
123   return text_;
124 }
125
126 inline
127 const StringC *ExternalId::systemIdString() const
128 {
129   return haveSystem_ ? &system_.string() : 0;
130 }
131
132 inline
133 const StringC *ExternalId::publicIdString() const
134 {
135   return havePublic_ ? &public_.string() : 0;
136 }
137
138 inline
139 const Text *ExternalId::systemIdText() const
140 {
141   return haveSystem_ ? &system_ : 0;
142 }
143
144 inline
145 const Text *ExternalId::publicIdText() const
146 {
147   return havePublic_ ? &public_.text() : 0;
148 }
149
150 inline
151 const PublicId *ExternalId::publicId() const
152 {
153   return havePublic_ ? &public_ : 0;
154 }
155
156 inline
157 const Location &ExternalId::location() const
158 {
159   return loc_;
160 }
161
162 inline
163 const StringC &ExternalId::effectiveSystemId() const
164 {
165   return effectiveSystem_;
166 }
167
168 inline
169 void ExternalId::setEffectiveSystem(StringC &str)
170 {
171   str.swap(effectiveSystem_);
172 }
173
174 #ifdef SP_NAMESPACE
175 }
176 #endif
177
178 #endif /* not ExternalId_INCLUDED */