Back to index

lightning-sunbird  0.9+nobinonly
Public Member Functions | Protected Member Functions
nsMacLocale Class Reference

#include <nsMacLocale.h>

Inheritance diagram for nsMacLocale:
Inheritance graph
[legend]
Collaboration diagram for nsMacLocale:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 nsMacLocale ()
virtual ~nsMacLocale ()
NS_IMETHOD GetPlatformLocale (const nsAString &locale, short *scriptCode, short *langCode, short *regionCode)
NS_IMETHOD GetXPLocale (short scriptCode, short langCode, short regionCode, nsAString &locale)

Protected Member Functions

PRBool ParseLocaleString (const char *locale_string, char *language, char *country, char *region, char separator)

Detailed Description

Definition at line 48 of file nsMacLocale.h.


Constructor & Destructor Documentation

Definition at line 222 of file nsMacLocale.cpp.

{
}

Definition at line 226 of file nsMacLocale.cpp.

{

}

Member Function Documentation

NS_IMETHODIMP nsMacLocale::GetPlatformLocale ( const nsAString &  locale,
short *  scriptCode,
short *  langCode,
short *  regionCode 
) [virtual]

Implements nsIMacLocale.

Definition at line 232 of file nsMacLocale.cpp.

{
  char  country_code[3];
  char  lang_code[3];
  char  region_code[3];
  bool  validCountryFound;
  int  i;
  
  if (!ParseLocaleString(NS_LossyConvertUTF16toASCII(locale).get(), lang_code, country_code, region_code, '-')) {
    *scriptCode = smRoman;
    *langCode = langEnglish;
    *regionCode = verUS;
    return NS_ERROR_FAILURE;
  }
  
  if (country_code[0]!=0) 
  {
    validCountryFound=false;
    for(i=0;country_list[i].iso_code;i++) {
      if (strcmp(country_list[i].iso_code,country_code)==0) {
        *regionCode = country_list[i].mac_region_code;
        validCountryFound=true;
        break;
      }
    }
    if (!validCountryFound) {
      *scriptCode = smRoman;
      *langCode = langEnglish;
      *regionCode = verUS;
      return NS_ERROR_FAILURE;
    }
  }
    
  for(i=0;lang_list[i].iso_code;i++) {
    if (strcmp(lang_list[i].iso_code, lang_code)==0) {
      *scriptCode = lang_list[i].mac_script_code;
      *langCode = lang_list[i].mac_lang_code;
      return NS_OK;
    }
  }
  return NS_ERROR_FAILURE;
}

Here is the call graph for this function:

NS_IMETHODIMP nsMacLocale::GetXPLocale ( short  scriptCode,
short  langCode,
short  regionCode,
nsAString &  locale 
) [virtual]

Implements nsIMacLocale.

Definition at line 276 of file nsMacLocale.cpp.

{

  int i;
  bool validResultFound = false;

  locale.Truncate();
  
  //
  // parse language
  //
  for(i=0;lang_list[i].iso_code;i++) {
    if (langCode==lang_list[i].mac_lang_code && scriptCode==lang_list[i].mac_script_code) {
      CopyASCIItoUTF16(nsDependentCString(lang_list[i].iso_code), locale);
      validResultFound = true;
      break;
    }
  }
  
  if (!validResultFound) {
    return NS_ERROR_FAILURE;
  }
  
  //
  // parse region
  //
  for(i=0;country_list[i].iso_code;i++) {
    if (regionCode==country_list[i].mac_region_code) {
      locale.Append(PRUnichar('-'));
      AppendASCIItoUTF16(country_list[i].iso_code, locale);
      validResultFound = true;
      break;
    }
  }
  
  if (validResultFound) {
    return NS_OK;
  }
  
  return NS_ERROR_FAILURE;
}

Here is the call graph for this function:

PRBool nsMacLocale::ParseLocaleString ( const char *  locale_string,
char *  language,
char *  country,
char *  region,
char  separator 
) [inline, protected]

Definition at line 321 of file nsMacLocale.cpp.

{
  size_t    len;

  len = strlen(locale_string);
  if (len==0 || (len!=2 && len!=5 && len!=8))
    return PR_FALSE;
  
  if (len==2) {
    language[0]=locale_string[0];
    language[1]=locale_string[1];
    language[2]=0;
    country[0]=0;
    region[0]=0;
  } else if (len==5) {
    language[0]=locale_string[0];
    language[1]=locale_string[1];
    language[2]=0;
    country[0]=locale_string[3];
    country[1]=locale_string[4];
    country[2]=0;
    region[0]=0;
    if (locale_string[2]!=separator) return PR_FALSE;
  } else if (len==8) {
    language[0]=locale_string[0];
    language[1]=locale_string[1];
    language[2]=0;
    country[0]=locale_string[3];
    country[1]=locale_string[4];
    country[2]=0;
    region[0]=locale_string[6];
    region[1]=locale_string[7];
    region[2]=0;
    if (locale_string[2]!=separator || locale_string[5]!=separator) return PR_FALSE;
  } else {
    return PR_FALSE;
  }

  return PR_TRUE;
}

Here is the caller graph for this function:


The documentation for this class was generated from the following files: