2 kumpf 1.1 //
3 // Copyright (c) 2000, 2001, 2002 BMC Software; Hewlett-Packard Development
4 // Company, L.P.; IBM Corp.; The Open Group; Tivoli Systems.
5 // Copyright (c) 2003 BMC Software; Hewlett-Packard Development Company, L.P.;
6 // IBM Corp.; EMC Corporation, The Open Group.
7 // Copyright (c) 2004 BMC Software; Hewlett-Packard Development Company, L.P.;
8 // IBM Corp.; EMC Corporation; VERITAS Software Corporation; The Open Group.
9 // Copyright (c) 2005 Hewlett-Packard Development Company, L.P.; IBM Corp.;
10 // EMC Corporation; VERITAS Software Corporation; The Open Group.
|
13 kumpf 1.1 //
14 // Permission is hereby granted, free of charge, to any person obtaining a copy
15 // of this software and associated documentation files (the "Software"), to
16 // deal in the Software without restriction, including without limitation the
17 // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
18 // sell copies of the Software, and to permit persons to whom the Software is
19 // furnished to do so, subject to the following conditions:
20 //
21 // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
22 // ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED
23 // "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
24 // LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
25 // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
26 // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
27 // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 //
30 //==============================================================================
31 //
32 // Author: Roger Kumpf, Hewlett-Packard Company (roger_kumpf@hp.com)
33 //
34 kumpf 1.1 // Modified By:
35 //
36 //%/////////////////////////////////////////////////////////////////////////////
37
38 #include <Pegasus/Common/LanguageTag.h>
39 #include <Pegasus/Common/LanguageParser.h>
40 #include <Pegasus/Common/AutoPtr.h>
41 #include <Pegasus/Common/InternalException.h>
42
43 PEGASUS_NAMESPACE_BEGIN
44
45 class LanguageTagRep
46 {
47 public:
48 String tag; // complete language tag
49 String language; // language part of language tag
50 String country; // country code part of the language tag
51 String variant; // language variant part of the language tag
52 };
53
54 // Check for a valid rep pointer. Throw an UninitializedObjectException if
55 kumpf 1.1 // the rep is null.
56 static void _checkRep(LanguageTagRep* rep)
57 {
58 if (!rep)
59 {
60 throw UninitializedObjectException();
61 }
62 }
63
64 LanguageTag::LanguageTag()
65 {
66 _rep = 0;
67 }
68
69 LanguageTag::LanguageTag(const String& languageTagString)
70 {
71 _rep = new LanguageTagRep();
72 AutoPtr<LanguageTagRep> rep(_rep);
73
74 LanguageParser::parseLanguageTag(
75 languageTagString,
76 kumpf 1.1 _rep->language,
77 _rep->country,
78 _rep->variant);
79
80 _rep->tag = languageTagString;
81
82 rep.release();
83 }
84
85 LanguageTag::LanguageTag(const LanguageTag& languageTag)
86 {
87 if (languageTag._rep)
88 {
89 _rep = new LanguageTagRep();
90 AutoPtr<LanguageTagRep> rep(_rep);
91
92 _rep->tag = languageTag._rep->tag;
93 _rep->language = languageTag._rep->language;
94 _rep->country = languageTag._rep->country;
95 _rep->variant = languageTag._rep->variant;
96
97 kumpf 1.1 rep.release();
98 }
99 else
100 {
101 _rep = 0;
102 }
103 }
104
105 LanguageTag::~LanguageTag()
106 {
107 delete _rep;
108 }
109
110 LanguageTag& LanguageTag::operator=(const LanguageTag& languageTag)
111 {
112 if (&languageTag != this)
113 {
114 if (!languageTag._rep)
115 {
116 delete _rep;
117 _rep = 0;
118 kumpf 1.1 }
119 else
120 {
121 if (!_rep)
122 {
123 _rep = new LanguageTagRep();
124 }
125
126 AutoPtr<LanguageTagRep> rep(_rep);
127
128 _rep->tag = languageTag._rep->tag;
129 _rep->language = languageTag._rep->language;
130 _rep->country = languageTag._rep->country;
131 _rep->variant = languageTag._rep->variant;
132
133 rep.release();
134 }
135 }
136 return *this;
137 }
138
139 kumpf 1.1 String LanguageTag::getLanguage() const
140 {
141 _checkRep(_rep);
142 return _rep->language;
143 }
144
145 String LanguageTag::getCountry() const
146 {
147 _checkRep(_rep);
148 return _rep->country;
149 }
150
151 String LanguageTag::getVariant() const
152 {
153 _checkRep(_rep);
154 return _rep->variant;
155 }
156
157 String LanguageTag::toString() const
158 {
159 _checkRep(_rep);
160 kumpf 1.1 return _rep->tag;
161 }
162
163 Boolean LanguageTag::operator==(const LanguageTag& languageTag) const
164 {
165 return String::equalNoCase(toString(), languageTag.toString());
166 }
167
168 Boolean LanguageTag::operator!=(const LanguageTag& languageTag) const
169 {
170 return !String::equalNoCase(toString(), languageTag.toString());
171 }
172
173 PEGASUS_NAMESPACE_END
|