Back to index

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

#include <nsIwin32LocaleImpl.h>

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

List of all members.

Public Member Functions

 nsIWin32LocaleImpl (void)
 ~nsIWin32LocaleImpl (void)
NS_IMETHOD GetPlatformLocale (const nsAString &locale, LCID *winLCID)
NS_IMETHOD GetXPLocale (LCID winLCID, nsAString &locale)

Protected Member Functions

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

Detailed Description

Definition at line 49 of file nsIwin32LocaleImpl.h.


Constructor & Destructor Documentation

Definition at line 610 of file nsIWin32LocaleImpl.cpp.

{
}

Definition at line 614 of file nsIWin32LocaleImpl.cpp.

{

}

Member Function Documentation

NS_IMETHODIMP nsIWin32LocaleImpl::GetPlatformLocale ( const nsAString &  locale,
LCID *  winLCID 
) [virtual]

Implements nsIWin32Locale.

Definition at line 626 of file nsIWin32LocaleImpl.cpp.

{
  char    language_code[3];
  char    country_code[3];
  char    region_code[3];
  int     i,j;

  if (!ParseLocaleString(NS_LossyConvertUTF16toASCII(locale).get(),language_code,country_code,region_code)) {
    *winLCID = MAKELCID(MAKELANGID(USER_DEFINED_PRIMARYLANG,USER_DEFINED_SUBLANGUAGE),
                        SORT_DEFAULT);
    return NS_OK;
  }
  // we have a LL-CC-RR style string

  for(i=0;i<LENGTH_MAPPING_LIST;i++) {
    if (strcmp(language_code,iso_list[i].iso_code)==0) {
      for(j=0;iso_list[i].sublang_list[j].win_code;j++) {
        if (strcmp(country_code,iso_list[i].sublang_list[j].iso_code)==0) {
          *winLCID = MAKELCID(MAKELANGID(iso_list[i].win_code,iso_list[i].sublang_list[j].win_code),SORT_DEFAULT);
          return NS_OK;
        }
      }
      // here we have a language match but no country match
      *winLCID = MAKELCID(MAKELANGID(iso_list[i].win_code,SUBLANG_DEFAULT),SORT_DEFAULT);
      return NS_OK;
    }
  }
    
  return NS_ERROR_FAILURE;
}

Here is the call graph for this function:

NS_IMETHODIMP nsIWin32LocaleImpl::GetXPLocale ( LCID  winLCID,
nsAString &  locale 
) [virtual]

Implements nsIWin32Locale.

Definition at line 658 of file nsIWin32LocaleImpl.cpp.

{
  DWORD    lang_id, sublang_id;
  int      i,j;

  lang_id = PRIMARYLANGID(LANGIDFROMLCID(winLCID));
  sublang_id = SUBLANGID(LANGIDFROMLCID(winLCID));

  for(i=0;i<LENGTH_MAPPING_LIST;i++) {
    if (lang_id==iso_list[i].win_code) {
      /* Special-case Croatian and Serbian, which have the same LANG_ID on
         Windows, but have been split into separate ISO-639-2 codes */
      if (lang_id == LANG_CROATIAN) {
        if (sublang_id == SUBLANG_DEFAULT) {
          locale.AssignLiteral(CROATIAN_ISO_CODE);
        } else {
          locale.AssignLiteral(SERBIAN_ISO_CODE);
        }
      } else {
        locale.AssignASCII(iso_list[i].iso_code);
      }
      for(j=0;iso_list[i].sublang_list[j].win_code;j++) {
        if (sublang_id == iso_list[i].sublang_list[j].win_code) {
          locale.Append(PRUnichar('-'));
          locale.AppendASCII(iso_list[i].sublang_list[j].iso_code);
          break;
        }
      }
      return NS_OK;
    }
  }

  //
  // didn't find any match. fall back to en-US, which is better 
  // than unusable buttons without 'OK', 'Cancel', etc (bug 224546)       
  //
  locale.AssignLiteral("en-US"); 
  return NS_OK;

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

Definition at line 702 of file nsIWin32LocaleImpl.cpp.

{
       size_t        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]!='-') 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]!='-' || locale_string[5]!='-') 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: