3 karl 1.7 // 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.;
|
9 karl 1.5 //
10 // Permission is hereby granted, free of charge, to any person obtaining a copy
11 // of this software and associated documentation files (the "Software"), to
12 // deal in the Software without restriction, including without limitation the
13 // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
14 // sell copies of the Software, and to permit persons to whom the Software is
15 // furnished to do so, subject to the following conditions:
16 //
17 // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
18 // ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED
19 // "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
20 // LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
21 // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
22 // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
23 // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
24 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 //
26 //==============================================================================
|
27 alagaraja 1.6 //
28 // Author: Humberto Rivero (hurivero@us.ibm.com)
29 //
30 // Modified By:
31 //
32 //%/////////////////////////////////////////////////////////////////////////////
33
34 #ifndef Pegasus_LanguageParser_h
35 #define Pegasus_LanguageParser_h
36
37 #include <cstdlib>
38 #include <cctype>
39 #include <Pegasus/Common/Linkage.h>
40 #include <Pegasus/Common/Config.h>
41 #include <Pegasus/Common/String.h>
42 #include <Pegasus/Common/Array.h>
43
44 #ifdef PEGASUS_USE_EXPERIMENTAL_INTERFACES
45
46 PEGASUS_NAMESPACE_BEGIN
47
48 alagaraja 1.6
49 /** This class parses and validates AcceptLanguage OR ContentLanguage values
50 * from the respective HTTP headers, and provides various utility functions
51 * to parse and manipulate language information
52 */
53 class PEGASUS_COMMON_LINKAGE LanguageParser{
54
55 public:
56
57 /** This member is used to represent an empty LanguageParser. Using this
58 member avoids construction of an empty LanguageParser
59 (e.g., LanguageParser()).
60 */
61 static const LanguageParser EMPTY;
62
63 /** Parses the value portion of either an AcceptLanguage HTTP header or a
64 * ContentLanguage HTTP header, extracts the individual fields and stores
65 * them in an array.
66 * @param values Array<String>& where the individual fields are stored
67 * @param hdr String the value portion of the HTTP Accept/ContentLanguage header
68 */
69 alagaraja 1.6 void parseHdr(Array<String> &values, String & hdr);
70
71 /** Parses an AcceptLanguage or ContentLanguage value from a header.
72 * If a valid AcceptLanguage value is determined to contain a quality
73 * value, then this quality once validated is returned. Otherwise -1 is returned.
74 * It is up to the caller to know in what context this call is being made,
75 * that is: it is the callers responsibility to know whether
76 * an AcceptLanguage or a ContentLanguage value is being parsed.
77 * @param language String& where the valid language is stored
78 * @param hdr String the value being parsed and validated
79 * @return Real32 if a valid quality found then 1 <=> 0, otherwise 1
80 * @exception throws ???
81 */
82 Real32 parseAcceptLanguageValue(String &language, String & hdr);
83
84 String parseContentLanguageValue(String & hdr);
85
86 /**
87 * Given a language ex: en-US-xx,
88 * returns the base of the language "en".
89 * @param language String
90 alagaraja 1.6 * @param separator Char16 the character that separates the various subtags
91 * @return String base of the language parameter
92 */
93 String getLanguage(String & language_tag);
94
95 String getCountry(String & language_tag);
96
97 String getVariant(String & language_tag);
98
99 private:
100
101 /**
102 * Fills the first position in the array with the most general part of
103 * the language String, each subsequent postion is the array gets more
104 * and more detailed. For example: en-us-fooblah would be returned as
105 * ["en"]["us"]["fooblah"]
106 * @param subtags Array<String>& array filled in with the root and subtags
107 * @param language String the language to parse
108 * @param separator Char16 the character that separates the various subtags
109 * @return String the root of the language tag
110 */
111 alagaraja 1.6 void parseLanguageSubtags(Array<String> &subtags, String language_tag);
112
113 /** Breaks the language into its parts(subtags), then validates each part
114 * according to the RFCs.
115 * @param s String language to be validated
116 * @return Boolean
117 */
118 Boolean isValid(String language_tag, Boolean length_check = true);
119
120 /** Checks if the String has all characters in A-Z OR a-z range.
121 * @param s String
122 * @return Boolean
123 */
124 Boolean checkAlpha(CString _str);
125
126 CString replaceSeparator(CString _s, char new_sep = '-');
127
128 char findSeparator(CString _str);
129
130 String convertPrivateLanguageTag(String language_tag);
131
132 alagaraja 1.6 }; //end LanguageParser
133
134 PEGASUS_NAMESPACE_END
|