(file) Return to LanguageParser.h CVS log (file) (dir) Up to [Pegasus] / pegasus / src / Pegasus / Common

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

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2