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

Diff for /pegasus/src/Pegasus/Common/LanguageParser.cpp between version 1.6 and 1.19

version 1.6, 2003/09/04 18:35:37 version 1.19, 2005/05/31 12:23:38
Line 1 
Line 1 
 //%/////////////////////////////////////////////////////////////////////////////  //%2005////////////////////////////////////////////////////////////////////////
 // //
 // Copyright (c) 2000, 2001, 2002 BMC Software, Hewlett-Packard Company, IBM,  // Copyright (c) 2000, 2001, 2002 BMC Software; Hewlett-Packard Development
 // 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.;
   // 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.
 // //
 // 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:  // Modified By: Aruran, IBM (ashanmug@in.ibm.com) for Bug# 3697, 3698, 3699, 3700
   //              Aruran, IBM (ashanmug@in.ibm.com) for Bug# 3701, 3702, 3703, 3704
 // //
 //%///////////////////////////////////////////////////////////////////////////// //%/////////////////////////////////////////////////////////////////////////////
  
Line 32 
Line 39 
 #include <Pegasus/Common/Tracer.h> #include <Pegasus/Common/Tracer.h>
 #include <Pegasus/Common/MessageLoader.h> //l10n #include <Pegasus/Common/MessageLoader.h> //l10n
 #include <cstring> #include <cstring>
 #include <iostream>  
 #include <cstdlib>  
 //PEGASUS_USING_STD; //PEGASUS_USING_STD;
 PEGASUS_NAMESPACE_BEGIN PEGASUS_NAMESPACE_BEGIN
  
 const LanguageParser LanguageParser::EMPTY = LanguageParser(); const LanguageParser LanguageParser::EMPTY = LanguageParser();
  
 void LanguageParser::parseHdr(Array<String> &values, String & hdr){  void LanguageParser::parseHdr(Array<String> &values, String hdr){
         // look for ',' which designates distict (Accept/Content)-Language fields         // look for ',' which designates distict (Accept/Content)-Language fields
         // the form: [languagetag, languagetag, languagetag] so whitespace removal         // the form: [languagetag, languagetag, languagetag] so whitespace removal
         // may be necessary.         // may be necessary.
Line 60 
Line 66 
         PEG_METHOD_EXIT();         PEG_METHOD_EXIT();
 } }
  
 Real32 LanguageParser::parseAcceptLanguageValue(String &language_tag, String & hdr){  Real32 LanguageParser::parseAcceptLanguageValue(String &language_tag, String hdr){
         // look for ';' in hdr, that means we have a quality value to capture         // look for ';' in hdr, that means we have a quality value to capture
     // if not, we only have a language     // if not, we only have a language
  
Line 127 
Line 133 
         return quality;         return quality;
 } }
  
 String LanguageParser::parseContentLanguageValue(String & hdr){  String LanguageParser::parseContentLanguageValue(const String& hdr){
         // we are looking for the language part of the hdr only,         // we are looking for the language part of the hdr only,
         // according to the RFC, there may be parenthesized strings         // according to the RFC, there may be parenthesized strings
         // that describe the purpose of the language, we need to ignore those         // that describe the purpose of the language, we need to ignore those
Line 163 
Line 169 
         return value;         return value;
 } }
  
 String LanguageParser::getLanguage(String & language_tag){  String LanguageParser::getLanguage(const String & language_tag){
         // given a language_tag: en-US-mn we want to return "en"         // given a language_tag: en-US-mn we want to return "en"
         Uint32 i;         Uint32 i;
         if((i = language_tag.find(findSeparator(language_tag.getCString()))) != PEG_NOT_FOUND)         if((i = language_tag.find(findSeparator(language_tag.getCString()))) != PEG_NOT_FOUND)
Line 171 
Line 177 
         return String(language_tag);         return String(language_tag);
 } }
  
 String LanguageParser::getCountry(String & language_tag){  String LanguageParser::getCountry(const String & language_tag){
         // given a language_tag: en-US-mn we want to return "US"         // given a language_tag: en-US-mn we want to return "US"
         Uint32 i,j;         Uint32 i,j;
         if( (i = language_tag.find(findSeparator(language_tag.getCString()))) != PEG_NOT_FOUND )         if( (i = language_tag.find(findSeparator(language_tag.getCString()))) != PEG_NOT_FOUND )
Line 182 
Line 188 
         return String::EMPTY;         return String::EMPTY;
 } }
  
 String LanguageParser::getVariant(String & language_tag){  String LanguageParser::getVariant(const String & language_tag){
         // given a language_tag: en-US-mn we want to return "mn"         // given a language_tag: en-US-mn we want to return "mn"
         Uint32 i;         Uint32 i;
         if( (i = language_tag.find(findSeparator(language_tag.getCString()))) != PEG_NOT_FOUND )         if( (i = language_tag.find(findSeparator(language_tag.getCString()))) != PEG_NOT_FOUND )
Line 195 
Line 201 
     PEG_METHOD_ENTER(TRC_L10N, "LanguageParser::parseLanguageSubtags");     PEG_METHOD_ENTER(TRC_L10N, "LanguageParser::parseLanguageSubtags");
         Uint32 i;         Uint32 i;
         char separator = findSeparator(language_tag.getCString());         char separator = findSeparator(language_tag.getCString());
   
         while( (i = language_tag.find(Char16(separator))) != PEG_NOT_FOUND ){         while( (i = language_tag.find(Char16(separator))) != PEG_NOT_FOUND ){
   
                         subtags.append(language_tag.subString(0,i));                         subtags.append(language_tag.subString(0,i));
                         language_tag.remove(0,i + 1);                         language_tag.remove(0,i + 1);
         }         }
Line 206 
Line 210 
         PEG_METHOD_EXIT();         PEG_METHOD_EXIT();
 } }
  
 Boolean LanguageParser::isValid(String language_tag, Boolean validate_length){  Boolean LanguageParser::isValid(const String& language_tag, Boolean validate_length){
         //break the String down into parts(subtags), then validate each part         //break the String down into parts(subtags), then validate each part
  
         if(language_tag == "*") return true;         if(language_tag == "*") return true;
Line 226 
Line 230 
         return true;         return true;
 } }
  
 String LanguageParser::convertPrivateLanguageTag(String language_tag){  String LanguageParser::convertPrivateLanguageTag(const String & language_tag){
         // figure out if its a unix style locale or windows locale         // figure out if its a unix style locale or windows locale
         Uint32 i;         Uint32 i;
         if(( i = language_tag.find("pegasus-")) != PEG_NOT_FOUND ){         if(( i = language_tag.find("pegasus-")) != PEG_NOT_FOUND ){
                 language_tag = language_tag.subString(i+5);  // capture the remainder of the string                  String str;
                 return String(replaceSeparator(language_tag.getCString(), '-'));                  str = language_tag.subString(i+5);
                   //language_tag = language_tag.subString(i+5);  // capture the remainder of the string
                   return String(replaceSeparator(str.getCString(), '-'));
         }         }
         //else if( (i = language_tag.find("win-")) != PEG_NOT_FOUND ){         //else if( (i = language_tag.find("win-")) != PEG_NOT_FOUND ){
           // return language_tag.subString(i+4);  // capture the remainder of the string           // return language_tag.subString(i+4);  // capture the remainder of the string
Line 242 
Line 248 
         }         }
 } }
  
 Boolean LanguageParser::checkAlpha(CString _str){  Boolean LanguageParser::checkAlpha(const CString & _str){
         Uint32 length = (Uint32) strlen(_str);         Uint32 length = (Uint32) strlen(_str);
         for(Uint32 i = 0; i < length; i++){          for(Uint32 i = 0; i < length; i++)
         if (!(((_str[i] >= 'A') && (_str[i] <= 'Z')) ||  
            ((_str[i] >= 'a') && (_str[i] <= 'z'))))  
                         return false;  
         }  
         return true;  
   
         /*for(Uint32 i = 0; i < length; i++)  
                 if( !isalpha(_str[i]) )                 if( !isalpha(_str[i]) )
                         return false;                         return false;
         return true;*/  
 }  
   
 Boolean LanguageParser::checkAlphaNum(char c){  
   
         if (!(((c >= 'A') && (c <= 'Z')) ||  
            ((c >= 'a') && (c <= 'z')) ||  
            ((c >= '0') && (c <= '9'))))  
                         return false;  
   
         return true;         return true;
 } }
  
 char LanguageParser::findSeparator(CString _str){  char LanguageParser::findSeparator(const CString & _str){
         Uint32 length = (Uint32) strlen(_str);         Uint32 length = (Uint32) strlen(_str);
         for(Uint32 i = 0; i < length; i++)         for(Uint32 i = 0; i < length; i++)
                 if(!checkAlphaNum(_str[i]))                  if(!isalnum(_str[i]))
                         return _str[i];                         return _str[i];
         return '\0';         return '\0';
 } }
  
 CString LanguageParser::replaceSeparator(CString _s, char new_sep){  CString LanguageParser::replaceSeparator(const CString & _s, char new_sep){
         char * _str = const_cast<char *>((const char*)_s);          char * _str = 0;
           strcpy(_str,_s);
         Uint32 length = (Uint32) strlen(_str);         Uint32 length = (Uint32) strlen(_str);
         for(Uint32 i = 0; i < length; i++)         for(Uint32 i = 0; i < length; i++)
                 _str[i] = (!checkAlphaNum(_str[i])) ? new_sep : _str[i];                  _str[i] = (!isalnum(_str[i])) ? new_sep : _str[i];
         return (String(_str)).getCString();         return (String(_str)).getCString();
 } }
  


Legend:
Removed from v.1.6  
changed lines
  Added in v.1.19

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2