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

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

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2