Back to index

lightning-sunbird  0.9+nobinonly
Functions
nsDateTimeFormatMac.cpp File Reference
#include "nsIServiceManager.h"
#include "nsDateTimeFormatMac.h"
#include <Resources.h>
#include <IntlResources.h>
#include <DateTimeUtils.h>
#include <Script.h>
#include <TextUtils.h>
#include "nsIComponentManager.h"
#include "nsLocaleCID.h"
#include "nsILocaleService.h"
#include "nsIPlatformCharset.h"
#include "nsIMacLocale.h"
#include "nsCRT.h"
#include "plstr.h"
#include "prmem.h"
#include "nsUnicharUtils.h"

Go to the source code of this file.

Functions

static Intl1Hndl GetItl1Resource (short scriptcode, short regioncode)
static Intl0Hndl GetItl0Resource (short scriptcode, short regioncode)
static void AbbrevWeekdayString (DateTimeRec &dateTime, Str255 weekdayString, Intl1Hndl Itl1RecordHandle)
static void CopyPascalStringToC (StringPtr aSrc, char *aDest)

Function Documentation

static void AbbrevWeekdayString ( DateTimeRec &  dateTime,
Str255  weekdayString,
Intl1Hndl  Itl1RecordHandle 
) [static]

Definition at line 130 of file nsDateTimeFormatMac.cpp.

{
       Boolean gotit = false;
       
       // If we can get itl1Resource, exam it.
       if(Itl1RecordHandle != NULL )
       {
              if(*Itl1RecordHandle == NULL)
                     ::LoadResource((Handle)Itl1RecordHandle);

              if(*Itl1RecordHandle == NULL)
              {
                     weekdayString[0] = 0;
                     return;
              }
              // if itl1 resource is in the itl1ExtRec format 
              // look at the additional table
              // See IM-Text Appendix B for details
              if((unsigned short)((*Itl1RecordHandle)->localRtn[0]) == 0xA89F)
              {      // use itl1ExtRect
                     Itl1ExtRec **Itl1ExtRecHandle;
                     Itl1ExtRecHandle = (Itl1ExtRec **) Itl1RecordHandle;
                     
                     // check abbrevDaysTableLength and abbrevDaysTableOffset
                     if(((*Itl1ExtRecHandle)->abbrevDaysTableLength != 0) &&
                        ((*Itl1ExtRecHandle)->abbrevDaysTableOffset != 0))
                     {      
                            // use the additional table for abbreviation weekday name
                            // Japanese use it.
                            // Start Pointer access to Handle, no HLock since we don't
                            // call any API here.
                            // Be careful when you debug- don't move memory :)
                            Ptr abTablePt;
                            short itemlen;
                            
                            // Ok, change it back to range [0-6]
                            short weekday = dateTime.dayOfWeek - 1;   
                            
                            abTablePt = (Ptr)(*Itl1ExtRecHandle);
                            abTablePt +=  (*Itl1ExtRecHandle)->abbrevDaysTableOffset;
                            
                            // first 2 byte in the table should be the count.
                            itemlen = (short) *((short*)abTablePt);   
                            abTablePt += 2;      
                            
                            if(weekday < itemlen)
                            {
                                   unsigned char len;
                                   short i;
                                   // iterate till we hit the weekday name we want
                                   for(i = 0 ; i < weekday ; i++)     
                                   {
                                          len = *abTablePt;
                                          // shift to the next one. don't forget the len byte itself.
                                          abTablePt += len + 1;       
                                   }
                                   // Ok, we got it, let's copy it.
                                   len = *abTablePt;
                                   ::BlockMoveData(abTablePt,&weekdayString[0] ,len+1);
                                   gotit = true;
                            }
                     }
              }
              
              // didn't get it. Either it is not in itl1ExtRect format or it don't have
              // additional abbreviation table. 
              // use itl1Rect instead.
              if(! gotit)
              {      
                     // get abbreviation length
                     // not the length is not always 3. Some country use longer (say 4)
                     // abbreviation.
                     short abbrLen = (*Itl1RecordHandle)->abbrLen;
                     // Fix  Traditional Chinese problem
                     if(((((*Itl1RecordHandle)->intl1Vers) >> 8) == verTaiwan ) &&
                        (abbrLen == 4) &&
                        ((*Itl1RecordHandle)->days[0][0] == 6) && 
                        ((*Itl1RecordHandle)->days[1][0] == 6) && 
                        ((*Itl1RecordHandle)->days[2][0] == 6) && 
                        ((*Itl1RecordHandle)->days[3][0] == 6) && 
                        ((*Itl1RecordHandle)->days[4][0] == 6) && 
                        ((*Itl1RecordHandle)->days[5][0] == 6) && 
                        ((*Itl1RecordHandle)->days[6][0] == 6))
                     {
                            abbrLen = 6;
                     }
                     weekdayString[0] = abbrLen;
                     // copy the weekday name with that abbreviation length
                     ::BlockMoveData(&((*Itl1RecordHandle)->days[dateTime.dayOfWeek-1][1]),
                             &weekdayString[1] , abbrLen);
                     gotit = true;
              }
       }
       else 
       {      // cannot get itl1 resource, return with null string.
              weekdayString[0] = 0;
       }
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void CopyPascalStringToC ( StringPtr  aSrc,
char *  aDest 
) [static]

Definition at line 330 of file nsDateTimeFormatMac.cpp.

{
  int len = aSrc[0];
  ::BlockMoveData(aSrc + 1, aDest, len);
  aDest[len] = '\0';
}

Here is the caller graph for this function:

static Intl0Hndl GetItl0Resource ( short  scriptcode,
short  regioncode 
) [static]

Definition at line 94 of file nsDateTimeFormatMac.cpp.

{
       long itl0num;

       if (smRoman == scriptcode)
       {
              itl0num = regioncode;       // if smRoman, use regioncode to differenciate
       } else {
              // get itlb from currenty system script
              ItlbRecord **ItlbRecordHandle;
              ItlbRecordHandle = (ItlbRecord **)::GetResource('itlb', scriptcode);
              
              // get itl0 number from itlb resource, if possible
              // otherwise, use the one return from script manager, 
              // (Script manager won't update itl1 number when the change on the fly )
              if(ItlbRecordHandle != NULL)
              {
                     if(*ItlbRecordHandle == NULL)
                            ::LoadResource((Handle)ItlbRecordHandle);
                            
                     if(*ItlbRecordHandle != NULL)
                            itl0num = (*ItlbRecordHandle)->itlbNumber;
                     else
                            itl0num = ::GetScriptVariable(scriptcode, smScriptNumber);
              } else {      // Use this as fallback
                     itl0num = ::GetScriptVariable(scriptcode, smScriptNumber);
              }
       }
       
       // get itl0 resource 
       Intl0Hndl Itl0RecordHandle;
       Itl0RecordHandle = (Intl0Hndl)::GetResource('itl0', itl0num);
       NS_ASSERTION(Itl0RecordHandle, "failed to get itl0 handle");
       return Itl0RecordHandle;
}

Here is the caller graph for this function:

static Intl1Hndl GetItl1Resource ( short  scriptcode,
short  regioncode 
) [static]

Definition at line 58 of file nsDateTimeFormatMac.cpp.

{
       long itl1num;

       if (smRoman == scriptcode)
       {
              itl1num = regioncode;       // if smRoman, use regioncode to differenciate
       } else {
              // get itlb from currenty system script
              ItlbRecord **ItlbRecordHandle;
              ItlbRecordHandle = (ItlbRecord **)::GetResource('itlb', scriptcode);
              
              // get itl1 number from itlb resource, if possible
              // otherwise, use the one return from script manager, 
              // (Script manager won't update itl1 number when the change on the fly )
              if(ItlbRecordHandle != NULL)
              {
                     if(*ItlbRecordHandle == NULL)
                            ::LoadResource((Handle)ItlbRecordHandle);
                            
                     if(*ItlbRecordHandle != NULL)
                            itl1num = (*ItlbRecordHandle)->itlbDate;
                     else
                            itl1num = ::GetScriptVariable(scriptcode, smScriptDate);
              } else {      // Use this as fallback
                     itl1num = ::GetScriptVariable(scriptcode, smScriptDate);
              }
       }
       
       // get itl1 resource 
       Intl1Hndl Itl1RecordHandle;
       Itl1RecordHandle = (Intl1Hndl)::GetResource('itl1', itl1num);
       NS_ASSERTION(Itl1RecordHandle, "failed to get itl1 handle");
       return Itl1RecordHandle;
}

Here is the caller graph for this function: