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

Diff for /pegasus/src/Pegasus/Common/LanguageParser.h between version 1.5.6.1 and 1.19.2.1

version 1.5.6.1, 2004/03/10 21:22:11 version 1.19.2.1, 2006/03/14 20:08:21
Line 1 
Line 1 
 //%2003////////////////////////////////////////////////////////////////////////  //%2006////////////////////////////////////////////////////////////////////////
 // //
 // Copyright (c) 2000, 2001, 2002  BMC Software, Hewlett-Packard Development  // Copyright (c) 2000, 2001, 2002 BMC Software; Hewlett-Packard Development
 // Company, L. P., IBM Corp., The Open Group, Tivoli Systems.  // Company, L.P.; IBM Corp.; The Open Group; Tivoli Systems.
 // Copyright (c) 2003 BMC Software; Hewlett-Packard Development Company, L. P.; // Copyright (c) 2003 BMC Software; Hewlett-Packard Development Company, L. P.;
 // IBM Corp.; EMC Corporation, The Open Group. // IBM Corp.; EMC Corporation, The Open Group.
   // Copyright (c) 2004 BMC Software; Hewlett-Packard Development Company, L.P.;
   // IBM Corp.; EMC Corporation; VERITAS Software Corporation; The Open Group.
   // Copyright (c) 2005 Hewlett-Packard Development Company, L.P.; IBM Corp.;
   // EMC Corporation; VERITAS Software Corporation; The Open Group.
   // Copyright (c) 2006 Hewlett-Packard Development Company, L.P.; IBM Corp.;
   // EMC Corporation; Symantec Corporation; The Open Group.
 // //
 // Permission is hereby granted, free of charge, to any person obtaining a copy // Permission is hereby granted, free of charge, to any person obtaining a copy
 // of this software and associated documentation files (the "Software"), to // of this software and associated documentation files (the "Software"), to
Line 23 
Line 29 
 // //
 //============================================================================== //==============================================================================
 // //
   
 // Author: Humberto Rivero (hurivero@us.ibm.com) // Author: Humberto Rivero (hurivero@us.ibm.com)
   
 // //
   // Modified By: Aruran, IBM (ashanmug@in.ibm.com) for Bug# 3697, 3698, 3699, 3700
 // Modified By:  //              Aruran, IBM (ashanmug@in.ibm.com) for Bug# 3701, 3702, 3703
   //              Roger Kumpf, Hewlett-Packard Company (roger_kumpf@hp.com)
 // //
   
 //%///////////////////////////////////////////////////////////////////////////// //%/////////////////////////////////////////////////////////////////////////////
  
   
   
 #ifndef Pegasus_LanguageParser_h #ifndef Pegasus_LanguageParser_h
   
 #define Pegasus_LanguageParser_h #define Pegasus_LanguageParser_h
  
   
   
 #include <cstdlib> #include <cstdlib>
   
 #include <cctype> #include <cctype>
   
 #include <Pegasus/Common/Linkage.h> #include <Pegasus/Common/Linkage.h>
   
 #include <Pegasus/Common/Config.h> #include <Pegasus/Common/Config.h>
   
 #include <Pegasus/Common/String.h> #include <Pegasus/Common/String.h>
   
 #include <Pegasus/Common/Array.h> #include <Pegasus/Common/Array.h>
   #include <Pegasus/Common/AcceptLanguageList.h>
   #include <Pegasus/Common/ContentLanguageList.h>
 #ifdef PEGASUS_USE_EXPERIMENTAL_INTERFACES  
   
   
  
 PEGASUS_NAMESPACE_BEGIN PEGASUS_NAMESPACE_BEGIN
  
   /**
       This class parses and validates Accept-Language and Content-Language values
       from the respective HTTP headers, and provides utility functions to parse
       and manipulate language information
 /** This class parses and validates AcceptLanguage OR ContentLanguage values  
   
  * from the respective HTTP headers, and provides various utility functions  
   
  * to parse and manipulate language information  
   
  */  */
   class PEGASUS_COMMON_LINKAGE LanguageParser
 class PEGASUS_COMMON_LINKAGE LanguageParser{  {
   
   
   
 public: public:
  
       /**
           Builds an AcceptLanguageList object from an HTTP Accept-Language
 /**     This member is used to represent an empty LanguageParser. Using this          header value.
           @param acceptLanguageHeader A String containing an HTTP
     member avoids construction of an empty LanguageParser          Accept-Language header value from which to build the AcceptLanguageList
           object.
     (e.g., LanguageParser()).          @exception InvalidAcceptLanguageHeader if a syntax error is
           encountered.
 */ */
       static AcceptLanguageList parseAcceptLanguageHeader(
           const String& acceptLanguageHeader);
  
 static const LanguageParser EMPTY;      /**
           Builds a ContentLanguageList object from an HTTP Content-Language
           header value.
           @param contentLanguageHeader A String containing an HTTP
 /** Parses the value portion of either an AcceptLanguage HTTP header or a          Content-Language header value from which to build the
           ContentLanguageList object.
  * ContentLanguage HTTP header, extracts the individual fields and stores          @exception InvalidContentLanguageHeader if a syntax error is
           encountered.
  * them in an array.  
   
  * @param values Array<String>& where the individual fields are stored  
   
  * @param hdr String the value portion of the HTTP Accept/ContentLanguage header  
   
  */  */
       static ContentLanguageList parseContentLanguageHeader(
           const String& contentLanguageHeader);
  
 void parseHdr(Array<String> &values, String & hdr);      /**
           Validates the syntax of a language tag according to RFC 3066.
           Parses the language tag into language, country, and variant, if
           the language tag is formed using ISO codes (ISO 639 and ISO 3166).
 /** Parses an AcceptLanguage or ContentLanguage value from a header.          @param languageTagString The language tag string to parse and
           validate.
  * If a valid AcceptLanguage value is determined to contain a quality          @param language The returned language value parsed from the language
           tag, if applicable.
  * value, then this quality once validated is returned. Otherwise -1 is returned.          @param country The returned country value parsed from the language
           tag, if applicable.
  * It is up to the caller to know in what context this call is being made,          @param variant The returned language variant value parsed from the
           language tag, if applicable.
  * that is: it is the callers responsibility to know whether          @exception Exception if the language tag is syntactically invalid.
        */
  * an AcceptLanguage or a ContentLanguage value is being parsed.      static void parseLanguageTag(
           const String& languageTagString,
  * @param language String& where the valid language is stored          String& language,
           String& country,
  * @param hdr String the value being parsed and validated          String& variant);
   
  * @return Real32 if a valid quality found then 1 <=> 0, otherwise 1  
   
  * @exception throws ???  
  
       /**
           Validates the syntax of an Accept-Language quality value.
           @param quality A Real32 quality value to validate.
           @exception Exception if the quality value is invalid.
  */  */
       static void validateQualityValue(Real32 quality);
 Real32 parseAcceptLanguageValue(String &language, String & hdr);  
   
   
   
 String parseContentLanguageValue(String & hdr);  
   
   
  
 /** /**
           Builds an HTTP Accept-Language header value from an AcceptLanguageList
  * Given a language ex: en-US-xx,          object.
           @param acceptLanguages The AcceptLanguageList object to be encoded in
  * returns the base of the language "en".          an HTTP Accept-Language header.
   
  * @param language String  
   
  * @param separator Char16 the character that separates the various subtags  
   
  * @return String base of the language parameter  
   
  */  */
       static String buildAcceptLanguageHeader(
 String getLanguage(String & language_tag);          const AcceptLanguageList& acceptLanguages);
   
   
   
 String getCountry(String & language_tag);  
   
   
   
 String getVariant(String & language_tag);  
   
   
   
 private:  
   
   
  
 /** /**
           Builds an HTTP Content-Language header value from a ContentLanguageList
  * Fills the first position in the array with the most general part of          object.
           @param contentLanguages The ContentLanguageList object to be encoded
  * the language String, each subsequent postion is the array gets more          in an HTTP Content-Language header.
   
  * and more detailed.  For example: en-us-fooblah would be returned as  
   
  * ["en"]["us"]["fooblah"]  
   
  * @param subtags Array<String>& array filled in with the root and subtags  
   
  * @param language String the language to parse  
   
  * @param separator Char16 the character that separates the various subtags  
   
  * @return String the root of the language tag  
   
  */  */
       static String buildContentLanguageHeader(
           const ContentLanguageList& contentLanguages);
  
 void parseLanguageSubtags(Array<String> &subtags, String language_tag);  #ifdef PEGASUS_HAS_ICU
       /**
           Converts a locale ID to language tag syntax by replacing the '_'
           separators with '-' separators.
 /** Breaks the language into its parts(subtags), then validates each part          @param localeId The locale ID string to convert to language tag
           syntax.  The conversion is performed on the localeId object
  * according to the RFCs.          directly.
           @return The converted String with language tag syntax.
  * @param s String language to be validated  
   
  * @return Boolean  
   
  */  */
       static String& convertLocaleIdToLanguageTag(String& localeId);
   #endif
  
 Boolean isValid(String language_tag, Boolean length_check = true);      /**
           Returns the default accept languages based on environment settings.
           ATTN: What is the behavior?  This is only implemented if MESSAGES and
           ICU are used.
 /** Checks if the String has all characters in A-Z OR a-z range.  
   
  * @param s String  
   
  * @return Boolean  
   
  */  */
       static AcceptLanguageList getDefaultAcceptLanguages();
  
 Boolean checkAlpha(CString _str);  private:
   
   
   
 CString replaceSeparator(CString _s, char new_sep = '-');  
   
   
   
 char findSeparator(CString _str);  
   
   
   
 String convertPrivateLanguageTag(String language_tag);  
  
       /**
           Parses the value portion of an HTTP Accept-Language or Content-Language
           header into individual language elements.  Comments and whitespace are
           removed.
           @param headerElements An array of Strings into which the language
           elements are stored.
           @param languageHeaderValue A String containing the value portion of
           an HTTP Accept-Language or Content-Language header.
           @exception Exception if a syntax error is encountered.
        */
       static void _parseLanguageHeader(
           const String& languageHeaderValue,
           Array<String>& languageElements);
  
       /**
           Parses an AcceptLanguage or ContentLanguage value from a header.
           If a valid AcceptLanguage value is determined to contain a quality
           value, then this quality is validated and returned. Otherwise -1 is
           returned.  It is up to the caller to know in what context this call
           is being made, that is: it is the callers responsibility to know
           whether an AcceptLanguage or a ContentLanguage value is being parsed.
           @param acceptLanguageHeaderElement String to be parsed into a
           language tag and quality value.  The String must not contain comments
           or whitespace.
           @param languageTag String into which the parsed language tag is
           stored.
           @param quality Real32 into which the parsed quality value is stored.
           @exception Exception if a syntax error is encountered.
        */
       static void _parseAcceptLanguageElement(
           const String& acceptLanguageElement,
           String& languageTag,
           Real32& quality);
  
 }; //end LanguageParser      /**
           Fills the first position in the array with the most general part of
           the language String, each subsequent postion is the array gets more
           and more detailed.  For example: en-us-fooblah would be returned as
           ["en"]["us"]["fooblah"]
           @param subtags Array<String>& array filled in with the root and subtags
           @param languageTag String the language to parse
           @return String the root of the language tag
           @exception Exception if a syntax error is encountered.
        */
       static void _parseLanguageSubtags(
           Array<String>& subtags,
           const String& languageTagString);
  
       /**
           Checks if a String represents a valid language tag primary subtag.
           A valid primary subtag contains 1 to 8 alphabetic characters.
           @param subtag The subtag String to validate.
           @return True if the String represents a valid language tag primary
           subtag; false otherwise.
        */
       static Boolean _isValidPrimarySubtagSyntax(const String& subtag);
  
       /**
           Checks if a String represents a valid language tag subtag.
           A valid primary subtag contains 1 to 8 alphanumeric characters.
           @param subtag The subtag String to validate.
           @return True if the String represents a valid language tag subtag;
           false otherwise.
        */
       static Boolean _isValidSubtagSyntax(const String& subtag);
   };
  
 PEGASUS_NAMESPACE_END PEGASUS_NAMESPACE_END
  
   
 #endif  // PEGASUS_USE_EXPERIMENTAL_INTERFACES  
   
   
 #endif #endif
   


Legend:
Removed from v.1.5.6.1  
changed lines
  Added in v.1.19.2.1

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2