LCOV - code coverage report
Current view: top level - lotuswordpro/source/filter - lwptools.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 57 380 15.0 %
Date: 2012-08-25 Functions: 2 7 28.6 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 43 404 10.6 %

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*************************************************************************
       3                 :            :  *
       4                 :            :  *  The Contents of this file are made available subject to the terms of
       5                 :            :  *  either of the following licenses
       6                 :            :  *
       7                 :            :  *         - GNU Lesser General Public License Version 2.1
       8                 :            :  *         - Sun Industry Standards Source License Version 1.1
       9                 :            :  *
      10                 :            :  *  Sun Microsystems Inc., October, 2000
      11                 :            :  *
      12                 :            :  *  GNU Lesser General Public License Version 2.1
      13                 :            :  *  =============================================
      14                 :            :  *  Copyright 2000 by Sun Microsystems, Inc.
      15                 :            :  *  901 San Antonio Road, Palo Alto, CA 94303, USA
      16                 :            :  *
      17                 :            :  *  This library is free software; you can redistribute it and/or
      18                 :            :  *  modify it under the terms of the GNU Lesser General Public
      19                 :            :  *  License version 2.1, as published by the Free Software Foundation.
      20                 :            :  *
      21                 :            :  *  This library is distributed in the hope that it will be useful,
      22                 :            :  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
      23                 :            :  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      24                 :            :  *  Lesser General Public License for more details.
      25                 :            :  *
      26                 :            :  *  You should have received a copy of the GNU Lesser General Public
      27                 :            :  *  License along with this library; if not, write to the Free Software
      28                 :            :  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston,
      29                 :            :  *  MA  02111-1307  USA
      30                 :            :  *
      31                 :            :  *
      32                 :            :  *  Sun Industry Standards Source License Version 1.1
      33                 :            :  *  =================================================
      34                 :            :  *  The contents of this file are subject to the Sun Industry Standards
      35                 :            :  *  Source License Version 1.1 (the "License"); You may not use this file
      36                 :            :  *  except in compliance with the License. You may obtain a copy of the
      37                 :            :  *  License at http://www.openoffice.org/license.html.
      38                 :            :  *
      39                 :            :  *  Software provided under this License is provided on an "AS IS" basis,
      40                 :            :  *  WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
      41                 :            :  *  WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
      42                 :            :  *  MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
      43                 :            :  *  See the License for the specific provisions governing your rights and
      44                 :            :  *  obligations concerning the Software.
      45                 :            :  *
      46                 :            :  *  The Initial Developer of the Original Code is: IBM Corporation
      47                 :            :  *
      48                 :            :  *  Copyright: 2008 by IBM Corporation
      49                 :            :  *
      50                 :            :  *  All Rights Reserved.
      51                 :            :  *
      52                 :            :  *  Contributor(s): _______________________________________
      53                 :            :  *
      54                 :            :  *
      55                 :            :  ************************************************************************/
      56                 :            : /*************************************************************************
      57                 :            :  * @file
      58                 :            :  *  For LWP filter architecture prototype
      59                 :            :  ************************************************************************/
      60                 :            : /*************************************************************************
      61                 :            :  * Change History
      62                 :            :  Jan 2005           Created
      63                 :            :  ************************************************************************/
      64                 :            : 
      65                 :            : #include "lwptools.hxx"
      66                 :            : #include <rtl/ustrbuf.hxx>
      67                 :            : #include <osl/process.h>
      68                 :            : #include <osl/thread.h>
      69                 :            : #include <osl/file.hxx>
      70                 :            : #include <vcl/svapp.hxx>
      71                 :            : #include <vcl/settings.hxx>
      72                 :            : #include <unicode/datefmt.h>
      73                 :            : #include <unicode/udat.h>
      74                 :            : 
      75                 :            : #ifdef SAL_UNX
      76                 :            : #define SEPARATOR '/'
      77                 :            : #else
      78                 :            : #define SEPARATOR '\\'
      79                 :            : #endif
      80                 :            : 
      81                 :            : using namespace icu;
      82                 :            : using namespace ::rtl;
      83                 :            : using namespace ::osl;
      84                 :            : 
      85                 :            : /**
      86                 :            :  * @descr       read lwp unicode string from stream to OUString per aEncoding
      87                 :            : */
      88                 :       2724 : sal_uInt16 LwpTools::QuickReadUnicode(LwpObjectStream* pObjStrm,
      89                 :            :         OUString& str, sal_uInt16 strlen, rtl_TextEncoding aEncoding)
      90                 :            :         //strlen: length of bytes
      91                 :            : {
      92                 :            : 
      93                 :       2724 :     sal_uInt16 readLen = 0;
      94                 :       2724 :     OUStringBuffer strBuf(128);
      95                 :            : 
      96 [ +  + ][ +  - ]:       2724 :     if( !IsUnicodePacked(pObjStrm, strlen) )
      97                 :            :     {
      98                 :       2673 :         sal_uInt16 len = 0;
      99                 :            :         sal_Char buf[1024];
     100                 :            : 
     101         [ +  + ]:       5280 :         while(strlen)
     102                 :            :         {
     103         [ -  + ]:       2607 :             strlen>1023?len=1023 :len=strlen;
     104         [ +  - ]:       2607 :             len = pObjStrm->QuickRead(buf, len);
     105                 :       2607 :             buf[len] = '\0';
     106 [ +  - ][ +  - ]:       2607 :             strBuf.append( OUString(buf, len, aEncoding) );
     107                 :       2607 :             strlen -= len;
     108                 :       2607 :             readLen += len;
     109         [ -  + ]:       2607 :             if(!len) break;
     110                 :            :         }
     111         [ +  - ]:       2673 :         str = strBuf.makeStringAndClear();
     112                 :       2673 :         return readLen;
     113                 :            :     }
     114                 :            :     else
     115                 :            :     {
     116                 :            :         sal_Char buf[1024];
     117                 :            :         sal_Unicode unibuf[1024];
     118                 :            :         sal_uInt8 readbyte;
     119                 :            :         sal_uInt16 readword;
     120                 :            : 
     121                 :         51 :         sal_Bool flag = sal_False;  //switch if unicode part reached
     122                 :         51 :         sal_uInt16 sublen = 0;
     123                 :            : 
     124         [ +  + ]:       1422 :         while(readLen<strlen)
     125                 :            :         {
     126         [ +  + ]:       1371 :             if(!flag)   //Not unicode string
     127                 :            :             {
     128                 :            :                 bool bFailure;
     129         [ +  - ]:       1176 :                 readbyte = pObjStrm->QuickReaduInt8(&bFailure);
     130         [ +  - ]:       1176 :                 if(bFailure) break;
     131                 :       1176 :                 readLen+=sizeof(readbyte);
     132                 :            : 
     133         [ +  + ]:       1176 :                 if(readbyte == 0x00)
     134                 :            :                 {
     135                 :         51 :                     flag = sal_True;
     136         [ +  + ]:         51 :                     if(sublen>0)    //add it to the strBuf
     137                 :            :                     {
     138 [ +  - ][ +  - ]:         15 :                         strBuf.append( OUString(buf, sublen, aEncoding) ); //try the aEncoding
     139                 :         15 :                         sublen = 0;
     140                 :            :                     }
     141                 :            :                 }
     142                 :            :                 else
     143                 :            :                 {
     144                 :       1125 :                     buf[sublen++] = readbyte;
     145                 :            :                 }
     146 [ +  - ][ +  + ]:       1176 :                 if(sublen>=1023 || readLen==strlen) //add it to the strBuf
     147                 :            :                 {
     148 [ +  - ][ +  - ]:         18 :                     strBuf.append( OUString(buf, sublen, aEncoding) ); //try the aEncoding
     149                 :       1176 :                     sublen = 0;
     150                 :            :                 }
     151                 :            :             }
     152                 :            :             else        //unicode string
     153                 :            :             {
     154                 :            :                 bool bFailure;
     155         [ +  - ]:        195 :                 readword = pObjStrm->QuickReaduInt16(&bFailure);
     156         [ +  - ]:        195 :                 if(bFailure) break;
     157                 :        195 :                 readLen+=sizeof(readword);
     158                 :            : 
     159         [ +  + ]:        195 :                 if(readword == 0x0000)
     160                 :            :                 {
     161                 :         18 :                     flag = sal_False;
     162         [ +  - ]:         18 :                     if(sublen)
     163                 :            :                     {
     164                 :         18 :                         unibuf[sublen] = sal_Unicode('\0');
     165         [ +  - ]:         18 :                         strBuf.append( OUString(unibuf) );
     166                 :         18 :                         sublen = 0;
     167                 :            :                     }
     168                 :            :                 }
     169                 :            :                 else
     170                 :            :                 {
     171                 :        177 :                     unibuf[sublen++] = readword;
     172                 :            :                 }
     173 [ +  - ][ +  + ]:        195 :                 if(sublen>=1023 || readLen==strlen)
     174                 :            :                 {
     175                 :         33 :                     unibuf[sublen] = sal_Unicode('\0');
     176         [ +  - ]:         33 :                     strBuf.append( OUString(unibuf) );
     177                 :        195 :                     sublen = 0;
     178                 :            :                 }
     179                 :            :             }
     180                 :            :         }
     181         [ +  - ]:         51 :         str = strBuf.makeStringAndClear();
     182                 :         51 :         return readLen;
     183                 :       2724 :     }
     184                 :            : }
     185                 :            : 
     186                 :            : /**
     187                 :            :  * @descr       Judge if the data (len) in object stream is lwp unicode packed
     188                 :            : */
     189                 :       2724 : sal_Bool LwpTools::IsUnicodePacked(LwpObjectStream* pObjStrm, sal_uInt16 len)
     190                 :            : {
     191                 :            :     sal_uInt8 byte;
     192                 :       2724 :     sal_uInt16 oldpos = pObjStrm->GetPos();
     193                 :            : 
     194         [ +  + ]:      45894 :     for (sal_uInt16 i = 0; i < len; i++)
     195                 :            :     {
     196                 :      43221 :         byte = pObjStrm->QuickReaduInt8();
     197         [ +  + ]:      43221 :         if (byte == 0x00)
     198                 :            :         {
     199                 :         51 :             pObjStrm->Seek(oldpos);
     200                 :         51 :             return sal_True;
     201                 :            :         }
     202                 :            :     }
     203                 :       2673 :     pObjStrm->Seek(oldpos);
     204                 :       2724 :     return sal_False;
     205                 :            : }
     206                 :            : 
     207                 :          0 : sal_Bool LwpTools::isFileUrl(const OString &fileName)
     208                 :            : {
     209         [ #  # ]:          0 :     if (fileName.indexOf("file://") == 0 )
     210                 :          0 :         return sal_True;
     211                 :          0 :     return sal_False;
     212                 :            : }
     213                 :            : 
     214                 :          0 : OUString LwpTools::convertToFileUrl(const OString &fileName)
     215                 :            : {
     216 [ #  # ][ #  # ]:          0 :     if ( isFileUrl(fileName) )
     217                 :            :     {
     218 [ #  # ][ #  # ]:          0 :         return OStringToOUString(fileName, osl_getThreadTextEncoding());
     219                 :            :     }
     220                 :            : 
     221                 :          0 :     OUString uUrlFileName;
     222 [ #  # ][ #  # ]:          0 :     OUString uFileName(fileName.getStr(), fileName.getLength(), osl_getThreadTextEncoding());
     223 [ #  # ][ #  # ]:          0 :     if ( fileName.indexOf('.') == 0 || fileName.indexOf(SEPARATOR) < 0 )
                 [ #  # ]
     224                 :            :     {
     225                 :          0 :         OUString uWorkingDir;
     226         [ #  # ]:          0 :         OSL_VERIFY( osl_getProcessWorkingDir(&uWorkingDir.pData) == osl_Process_E_None );
     227         [ #  # ]:          0 :         OSL_VERIFY( FileBase::getAbsoluteFileURL(uWorkingDir, uFileName, uUrlFileName) == FileBase::E_None );
     228                 :            :     } else
     229                 :            :     {
     230         [ #  # ]:          0 :         OSL_VERIFY( FileBase::getFileURLFromSystemPath(uFileName, uUrlFileName) == FileBase::E_None );
     231                 :            :     }
     232                 :            : 
     233                 :          0 :     return uUrlFileName;
     234                 :            : }
     235                 :            : 
     236                 :          0 : OUString LwpTools::DateTimeToOUString(LtTm & dt)
     237                 :            : {
     238                 :          0 :     rtl::OUStringBuffer buf;
     239         [ #  # ]:          0 :     buf.append(dt.tm_year);
     240         [ #  # ]:          0 :     buf.append( A2OUSTR("-") );
     241         [ #  # ]:          0 :     buf.append(dt.tm_mon);
     242         [ #  # ]:          0 :     buf.append( A2OUSTR("-") );
     243         [ #  # ]:          0 :     buf.append(dt.tm_mday);
     244         [ #  # ]:          0 :     buf.append( A2OUSTR("T") );
     245         [ #  # ]:          0 :     buf.append(dt.tm_hour);
     246         [ #  # ]:          0 :     buf.append( A2OUSTR(":") );
     247         [ #  # ]:          0 :     buf.append(dt.tm_min);
     248         [ #  # ]:          0 :     buf.append( A2OUSTR(":") );
     249         [ #  # ]:          0 :     buf.append(dt.tm_sec);
     250                 :            : 
     251         [ #  # ]:          0 :     return buf.makeStringAndClear();
     252                 :            : }
     253                 :            : 
     254                 :            : /**
     255                 :            :  * @descr   get the system date format
     256                 :            : */
     257                 :          0 : XFDateStyle* LwpTools::GetSystemDateStyle(sal_Bool bLongFormat)
     258                 :            : {
     259                 :            :     icu::DateFormat::EStyle style;
     260         [ #  # ]:          0 :     if (bLongFormat)
     261                 :          0 :         style = icu::DateFormat::FULL;//system full date format
     262                 :            :     else
     263                 :          0 :         style = icu::DateFormat::SHORT;//system short date format
     264                 :            : /*  ::com::sun::star::lang::Locale aLocale=Application::GetSettings().GetLocale();
     265                 :            :     rtl::OUString strLang = aLocale.Language;
     266                 :            :     rtl::OUString strCountry = aLocale.Country;
     267                 :            :     strLang = strLang + A2OUSTR("_");
     268                 :            :     rtl::OUString strLocale = strLang + strCountry;
     269                 :            : 
     270                 :            :     int32_t nLength = 0;
     271                 :            :     int32_t nLengthNeed;
     272                 :            :     UErrorCode status = U_ZERO_ERROR;
     273                 :            :     UChar* pattern = NULL;
     274                 :            : 
     275                 :            :     UDateFormat* fmt= udat_open(UDAT_FULL, UDAT_FULL,
     276                 :            :         (char*)(OUStringToOString(strLocale,RTL_TEXTENCODING_MS_1252).getStr()), NULL, 0, NULL, 0, &status);
     277                 :            : 
     278                 :            :     nLengthNeed = udat_toPattern(fmt,true,NULL,nLength,&status);
     279                 :            :     if (status == U_BUFFER_OVERFLOW_ERROR)
     280                 :            :     {
     281                 :            :         status = U_ZERO_ERROR;
     282                 :            :         nLength = nLengthNeed +1;
     283                 :            :         pattern = (UChar*)malloc(sizeof(UChar)*nLength);
     284                 :            :         udat_toPattern(fmt,true,pattern,nLength,&status);
     285                 :            :     }
     286                 :            : */
     287                 :            :     //1 get locale for system
     288 [ #  # ][ #  # ]:          0 :     ::com::sun::star::lang::Locale aLocale=Application::GetSettings().GetLocale();
     289                 :          0 :     rtl::OUString strLang = aLocale.Language;
     290                 :          0 :     rtl::OUString strCountry = aLocale.Country;
     291         [ #  # ]:          0 :     icu::Locale bLocale((char*)(OUStringToOString(strLang,RTL_TEXTENCODING_MS_1252).getStr()),
     292 [ #  # ][ #  # ]:          0 :         (char*)(OUStringToOString(strCountry,RTL_TEXTENCODING_MS_1252).getStr()));
     293                 :            :     //2 get icu format pattern by locale
     294         [ #  # ]:          0 :     icu::DateFormat* fmt = icu::DateFormat::createDateInstance(style,bLocale);
     295                 :            : 
     296                 :          0 :     int32_t nLength = 0;
     297                 :            :     int32_t nLengthNeed;
     298                 :          0 :     UErrorCode status = U_ZERO_ERROR;
     299                 :          0 :     UChar* pattern = NULL;
     300                 :            : 
     301         [ #  # ]:          0 :     nLengthNeed = udat_toPattern((void *const *)fmt,sal_False,NULL,nLength,&status);
     302         [ #  # ]:          0 :     if (status == U_BUFFER_OVERFLOW_ERROR)
     303                 :            :     {
     304                 :          0 :         status = U_ZERO_ERROR;
     305                 :          0 :         nLength = nLengthNeed +1;
     306                 :          0 :         pattern = (UChar*)malloc(sizeof(UChar)*nLength);
     307         [ #  # ]:          0 :         udat_toPattern((void *const *)fmt,sal_False,pattern,nLength,&status);
     308                 :            :     }
     309         [ #  # ]:          0 :     if (pattern == NULL)
     310                 :          0 :         return NULL;
     311                 :            :     // 3 parse pattern string,per icu date/time format syntax, there are 20 letters reserved
     312                 :            :     // as patter letter,each represent a element in date/time and its repeat numbers represent
     313                 :            :     // different format: for exampel: M produces '1',MM produces '01', MMM produces 'Jan', MMMM produces 'Januaray'
     314                 :            :     // letter other than these letters is regard as text in the format, for example ','in 'Jan,2005'
     315                 :            :     // we parse pattern string letter by letter and get the time format.
     316                 :            :     UChar cSymbol;
     317                 :            :     UChar cTmp;
     318 [ #  # ][ #  # ]:          0 :     XFDateStyle* pDateStyle = new XFDateStyle;
     319                 :            : 
     320         [ #  # ]:          0 :     for (int32_t i=0;i<nLengthNeed;)
     321                 :            :     {
     322                 :          0 :         cSymbol = pattern[i];
     323                 :            :         int32_t j;
     324   [ #  #  #  #  :          0 :         switch(cSymbol)
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
                   #  # ]
     325                 :            :         {
     326                 :            :             case 'G':
     327                 :            :             {
     328                 :          0 :                 for (j=1;;j++)
     329                 :            :                 {
     330                 :          0 :                     cTmp = pattern[i+j];
     331         [ #  # ]:          0 :                     if (cTmp != cSymbol)
     332                 :            :                     {
     333                 :          0 :                         i=i+j;
     334                 :          0 :                         break;
     335                 :            :                     }
     336                 :            :                 }
     337         [ #  # ]:          0 :                 pDateStyle->AddEra();
     338                 :          0 :                 break;
     339                 :            :             }
     340                 :            :             case 'y':
     341                 :            :             {
     342                 :          0 :                 for (j=1;;j++)
     343                 :            :                 {
     344                 :          0 :                     cTmp = pattern[i+j];
     345         [ #  # ]:          0 :                     if (cTmp != cSymbol)
     346                 :            :                     {
     347                 :          0 :                         i=i+j;
     348                 :          0 :                         break;
     349                 :            :                     }
     350                 :            :                 }
     351         [ #  # ]:          0 :                 if (j <= 2)
     352         [ #  # ]:          0 :                     pDateStyle->AddYear(sal_False);
     353                 :            :                 else
     354         [ #  # ]:          0 :                     pDateStyle->AddYear();
     355                 :          0 :                 break;
     356                 :            :             }
     357                 :            :             case 'M':
     358                 :            :             {
     359                 :          0 :                 for (j=1;;j++)
     360                 :            :                 {
     361                 :          0 :                     cTmp = pattern[i+j];
     362         [ #  # ]:          0 :                     if (cTmp != cSymbol)
     363                 :            :                     {
     364                 :          0 :                         i=i+j;
     365                 :          0 :                         break;
     366                 :            :                     }
     367                 :            :                 }
     368         [ #  # ]:          0 :                 if (j==1)
     369         [ #  # ]:          0 :                     pDateStyle->AddMonth(sal_False,sal_False);
     370         [ #  # ]:          0 :                 else if (j==2)
     371         [ #  # ]:          0 :                     pDateStyle->AddMonth(sal_True,sal_False);
     372         [ #  # ]:          0 :                 else if (j==3)
     373         [ #  # ]:          0 :                     pDateStyle->AddMonth(sal_False,sal_True);
     374                 :            :                 else
     375         [ #  # ]:          0 :                     pDateStyle->AddMonth(sal_True,sal_True);
     376                 :          0 :                 break;
     377                 :            :             }
     378                 :            :             case 'd':
     379                 :            :             {
     380                 :          0 :                 for (j=1;;j++)
     381                 :            :                 {
     382                 :          0 :                     cTmp = pattern[i+j];
     383         [ #  # ]:          0 :                     if (cTmp != cSymbol)
     384                 :            :                     {
     385                 :          0 :                         i=i+j;
     386                 :          0 :                         break;
     387                 :            :                     }
     388                 :            :                 }
     389         [ #  # ]:          0 :                 if (j==1)
     390         [ #  # ]:          0 :                     pDateStyle->AddMonthDay(sal_False);
     391                 :            :                 else
     392         [ #  # ]:          0 :                     pDateStyle->AddMonthDay();
     393                 :          0 :                 break;
     394                 :            :             }
     395                 :            :             case 'h':
     396                 :            :             {
     397                 :          0 :                 for (j=1;;j++)
     398                 :            :                 {
     399                 :          0 :                     cTmp = pattern[i+j];
     400         [ #  # ]:          0 :                     if (cTmp != cSymbol)
     401                 :            :                     {
     402                 :          0 :                         i=i+j;
     403                 :          0 :                         break;
     404                 :            :                     }
     405                 :            :                 }
     406         [ #  # ]:          0 :                 if (j==1)
     407         [ #  # ]:          0 :                     pDateStyle->AddHour(sal_False);
     408                 :            :                 else
     409         [ #  # ]:          0 :                     pDateStyle->AddHour();
     410                 :          0 :                 break;
     411                 :            :             }
     412                 :            :             case 'H':
     413                 :            :             {
     414                 :          0 :                 for (j=1;;j++)
     415                 :            :                 {
     416                 :          0 :                     cTmp = pattern[i+j];
     417         [ #  # ]:          0 :                     if (cTmp != cSymbol)
     418                 :            :                     {
     419                 :          0 :                         i=i+j;
     420                 :          0 :                         break;
     421                 :            :                     }
     422                 :            :                 }
     423         [ #  # ]:          0 :                 if (j==1)
     424         [ #  # ]:          0 :                     pDateStyle->AddHour(sal_False);
     425                 :            :                 else
     426         [ #  # ]:          0 :                     pDateStyle->AddHour();
     427                 :          0 :                 break;
     428                 :            :             }
     429                 :            :             case 'm':
     430                 :            :             {
     431                 :          0 :                 for (j=1;;j++)
     432                 :            :                 {
     433                 :          0 :                     cTmp = pattern[i+j];
     434         [ #  # ]:          0 :                     if (cTmp != cSymbol)
     435                 :            :                     {
     436                 :          0 :                         i=i+j;
     437                 :          0 :                         break;
     438                 :            :                     }
     439                 :            :                 }
     440         [ #  # ]:          0 :                 if (j==1)
     441         [ #  # ]:          0 :                     pDateStyle->AddMinute(sal_False);
     442                 :            :                 else
     443         [ #  # ]:          0 :                     pDateStyle->AddMinute();
     444                 :          0 :                 break;
     445                 :            :             }
     446                 :            :             case 's':
     447                 :            :             {
     448                 :          0 :                 for (j=1;;j++)
     449                 :            :                 {
     450                 :          0 :                     cTmp = pattern[i+j];
     451         [ #  # ]:          0 :                     if (cTmp != cSymbol)
     452                 :            :                     {
     453                 :          0 :                         i=i+j;
     454                 :          0 :                         break;
     455                 :            :                     }
     456                 :            :                 }
     457         [ #  # ]:          0 :                 if (j==1)
     458         [ #  # ]:          0 :                     pDateStyle->AddSecond(sal_False,0);
     459                 :            :                 else
     460         [ #  # ]:          0 :                     pDateStyle->AddSecond(sal_True,0);
     461                 :          0 :                 break;
     462                 :            :             }
     463                 :            :             case 'S':
     464                 :            :             {
     465                 :          0 :                 for (j=1;;j++)
     466                 :            :                 {
     467                 :          0 :                     cTmp = pattern[i+j];
     468         [ #  # ]:          0 :                     if (cTmp != cSymbol)
     469                 :            :                     {
     470                 :          0 :                         i=i+j;
     471                 :          0 :                         break;
     472                 :            :                     }
     473                 :            :                 }
     474                 :            :                 /*if (j==1)
     475                 :            :                     pDateStyle->AddSecond(sal_False);
     476                 :            :                 else
     477                 :            :                     pDateStyle->AddSecond();*/
     478                 :          0 :                 break;
     479                 :            :             }
     480                 :            :             case 'E':
     481                 :            :             {
     482                 :          0 :                 for (j=1;;j++)
     483                 :            :                 {
     484                 :          0 :                     cTmp = pattern[i+j];
     485         [ #  # ]:          0 :                     if (cTmp != cSymbol)
     486                 :            :                     {
     487                 :          0 :                         i=i+j;
     488                 :          0 :                         break;
     489                 :            :                     }
     490                 :            :                 }
     491         [ #  # ]:          0 :                 if (j<=2)
     492         [ #  # ]:          0 :                     pDateStyle->AddWeekDay(sal_False);
     493                 :            :                 else
     494         [ #  # ]:          0 :                     pDateStyle->AddWeekDay();
     495                 :          0 :                 break;
     496                 :            :             }
     497                 :            :             case 'D':
     498                 :            :             {
     499                 :          0 :                 for (j=1;;j++)
     500                 :            :                 {
     501                 :          0 :                     cTmp = pattern[i+j];
     502         [ #  # ]:          0 :                     if (cTmp != cSymbol)
     503                 :            :                     {
     504                 :          0 :                         i=i+j;
     505                 :          0 :                         break;
     506                 :            :                     }
     507                 :            :                 }
     508                 :            :                 /*if (j==1)
     509                 :            :                     pDateStyle->AddWeekDay(sal_False);
     510                 :            :                 else
     511                 :            :                     pDateStyle->AddWeekDay();*/
     512                 :          0 :                 break;
     513                 :            :             }
     514                 :            :             case 'F':
     515                 :            :             {
     516                 :          0 :                 for (j=1;;j++)
     517                 :            :                 {
     518                 :          0 :                     cTmp = pattern[i+j];
     519         [ #  # ]:          0 :                     if (cTmp != cSymbol)
     520                 :            :                     {
     521                 :          0 :                         i=i+j;
     522                 :          0 :                         break;
     523                 :            :                     }
     524                 :            :                 }
     525                 :            :                 /*if (j==1)
     526                 :            :                     pDateStyle->AddWeekDay(sal_False);
     527                 :            :                 else
     528                 :            :                     pDateStyle->AddWeekDay();*/
     529                 :          0 :                 break;
     530                 :            :             }
     531                 :            :             case 'w':
     532                 :            :             {
     533                 :          0 :                 for (j=1;;j++)
     534                 :            :                 {
     535                 :          0 :                     cTmp = pattern[i+j];
     536         [ #  # ]:          0 :                     if (cTmp != cSymbol)
     537                 :            :                     {
     538                 :          0 :                         i=i+j;
     539                 :          0 :                         break;
     540                 :            :                     }
     541                 :            :                 }
     542                 :            :                 /*if (j==1)
     543                 :            :                     pDateStyle->AddWeekDay(sal_False);
     544                 :            :                 else
     545                 :            :                     pDateStyle->AddWeekDay();*/
     546                 :          0 :                 break;
     547                 :            :             }
     548                 :            :             case 'W':
     549                 :            :             {
     550                 :          0 :                 for (j=1;;j++)
     551                 :            :                 {
     552                 :          0 :                     cTmp = pattern[i+j];
     553         [ #  # ]:          0 :                     if (cTmp != cSymbol)
     554                 :            :                     {
     555                 :          0 :                         i=i+j;
     556                 :          0 :                         break;
     557                 :            :                     }
     558                 :            :                 }
     559                 :            :                 /*if (j==1)
     560                 :            :                     pDateStyle->AddWeekDay(sal_False);
     561                 :            :                 else
     562                 :            :                     pDateStyle->AddWeekDay();*/
     563                 :          0 :                 break;
     564                 :            :             }
     565                 :            :             case 'a':
     566                 :            :             {
     567                 :          0 :                 for (j=1;;j++)
     568                 :            :                 {
     569                 :          0 :                     cTmp = pattern[i+j];
     570         [ #  # ]:          0 :                     if (cTmp != cSymbol)
     571                 :            :                     {
     572                 :          0 :                         i=i+j;
     573                 :          0 :                         break;
     574                 :            :                     }
     575                 :            :                 }
     576         [ #  # ]:          0 :                 pDateStyle->AddAmPm(sal_True);
     577                 :          0 :                 break;
     578                 :            :             }
     579                 :            :             case 'k':
     580                 :            :             {
     581                 :          0 :                 for (j=1;;j++)
     582                 :            :                 {
     583                 :          0 :                     cTmp = pattern[i+j];
     584         [ #  # ]:          0 :                     if (cTmp != cSymbol)
     585                 :            :                     {
     586                 :          0 :                         i=i+j;
     587                 :          0 :                         break;
     588                 :            :                     }
     589                 :            :                 }
     590                 :          0 :                 break;
     591                 :            :             }
     592                 :            :             case 'K':
     593                 :            :             {
     594                 :          0 :                 for (j=1;;j++)
     595                 :            :                 {
     596                 :          0 :                     cTmp = pattern[i+j];
     597         [ #  # ]:          0 :                     if (cTmp != cSymbol)
     598                 :            :                     {
     599                 :          0 :                         i=i+j;
     600                 :          0 :                         break;
     601                 :            :                     }
     602                 :            :                 }
     603         [ #  # ]:          0 :                 if (j==1)
     604         [ #  # ]:          0 :                     pDateStyle->AddHour(sal_False);
     605                 :            :                 else
     606         [ #  # ]:          0 :                     pDateStyle->AddHour();
     607                 :          0 :                 break;
     608                 :            :             }
     609                 :            :             case 'Z':
     610                 :            :             {
     611                 :          0 :                 for (j=1;;j++)
     612                 :            :                 {
     613                 :          0 :                     cTmp = pattern[i+j];
     614         [ #  # ]:          0 :                     if (cTmp != cSymbol)
     615                 :            :                     {
     616                 :          0 :                         i=i+j;
     617                 :          0 :                         break;
     618                 :            :                     }
     619                 :            :                 }
     620                 :          0 :                 break;
     621                 :            :             }
     622                 :            :             case '\''://'
     623                 :            :             {
     624                 :          0 :                 for (j=1;;j++)
     625                 :            :                 {
     626                 :          0 :                     cTmp = pattern[i+j];
     627         [ #  # ]:          0 :                     if (cTmp != cSymbol)
     628                 :            :                     {
     629                 :          0 :                         i=i+j;
     630                 :          0 :                         break;
     631                 :            :                     }
     632                 :            :                 }
     633                 :          0 :                 break;
     634                 :            :             }
     635                 :            :             case '"':
     636                 :            :             {
     637         [ #  # ]:          0 :                 pDateStyle->AddText(OUString(A2OUSTR("'")));
     638                 :          0 :                 break;
     639                 :            :             }
     640                 :            :             default:
     641                 :            :             {
     642 [ #  # ][ #  # ]:          0 :                 if ((cSymbol>='A' && cSymbol<='Z') || (cSymbol>='a' && cSymbol<='z') )
         [ #  # ][ #  # ]
     643                 :          0 :                     return NULL;
     644                 :            :                 else//TEXT
     645                 :            :                 {
     646                 :            :                     //UChar buffer[1024];
     647                 :            :                     sal_Unicode buffer[1024];
     648                 :          0 :                     buffer[0] = cSymbol;
     649                 :          0 :                     for (j=1;;j++)
     650                 :            :                     {
     651                 :          0 :                         cTmp = pattern[i+j];
     652 [ #  # ][ #  # ]:          0 :                         if ((cTmp>='A' && cTmp<='Z') || (cTmp>='a' && cTmp<='z') ||
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     653                 :            :                             cTmp=='\'' || cTmp=='"' )
     654                 :            :                         {
     655                 :          0 :                             i=i+j;
     656                 :          0 :                             buffer[j]= '\0';
     657                 :          0 :                             break;
     658                 :            :                         }
     659                 :            :                         else
     660                 :          0 :                             buffer[j] = cTmp;
     661                 :            :                     }
     662                 :            : 
     663         [ #  # ]:          0 :                     pDateStyle->AddText(OUString(buffer));//keep for all parsed
     664                 :            :                 }
     665                 :          0 :                 break;
     666                 :            :             }
     667                 :            :         }
     668                 :            :     }
     669                 :            : //  udat_close(fmt);
     670         [ #  # ]:          0 :     return pDateStyle;
     671                 :            : }
     672                 :            : /**
     673                 :            :  * @descr   get the system time format
     674                 :            : */
     675                 :          0 : XFTimeStyle* LwpTools::GetSystemTimeStyle()
     676                 :            : {
     677                 :            : /*  ::com::sun::star::lang::Locale aLocale=Application::GetSettings().GetLocale();
     678                 :            :     rtl::OUString strLang = aLocale.Language;
     679                 :            :     rtl::OUString strCountry = aLocale.Country;
     680                 :            :     strLang = strLang + A2OUSTR("_");
     681                 :            :     rtl::OUString strLocale = strLang + strCountry;
     682                 :            : 
     683                 :            :     int32_t nLength = 0;
     684                 :            :     int32_t nLengthNeed;
     685                 :            :     UErrorCode status = U_ZERO_ERROR;
     686                 :            :     UChar* pattern = NULL;
     687                 :            : 
     688                 :            :     UDateFormat* fmt= udat_open(UDAT_FULL, UDAT_FULL,
     689                 :            :         (char*)(OUStringToOString(strLocale,RTL_TEXTENCODING_MS_1252).getStr()), NULL, 0, NULL, 0, &status);
     690                 :            : 
     691                 :            :     nLengthNeed = udat_toPattern(fmt,true,NULL,nLength,&status);
     692                 :            :     if (status == U_BUFFER_OVERFLOW_ERROR)
     693                 :            :     {
     694                 :            :         status = U_ZERO_ERROR;
     695                 :            :         nLength = nLengthNeed +1;
     696                 :            :         pattern = (UChar*)malloc(sizeof(UChar)*nLength);
     697                 :            :         udat_toPattern(fmt,true,pattern,nLength,&status);
     698                 :            :     }
     699                 :            : */
     700                 :            :     //1 get locale for system
     701 [ #  # ][ #  # ]:          0 :     ::com::sun::star::lang::Locale aLocale=Application::GetSettings().GetLocale();
     702                 :          0 :     rtl::OUString strLang = aLocale.Language;
     703                 :          0 :     rtl::OUString strCountry = aLocale.Country;
     704         [ #  # ]:          0 :     icu::Locale bLocale((char*)(OUStringToOString(strLang,RTL_TEXTENCODING_MS_1252).getStr()),
     705 [ #  # ][ #  # ]:          0 :         (char*)(OUStringToOString(strCountry,RTL_TEXTENCODING_MS_1252).getStr()));
     706                 :            : 
     707         [ #  # ]:          0 :     icu::DateFormat* fmt = icu::DateFormat::createTimeInstance(icu::DateFormat::DEFAULT,bLocale);
     708                 :            :     //2 get icu format pattern by locale
     709                 :          0 :     int32_t nLength = 0;
     710                 :            :     int32_t nLengthNeed;
     711                 :          0 :     UErrorCode status = U_ZERO_ERROR;
     712                 :          0 :     UChar* pattern = NULL;
     713         [ #  # ]:          0 :     nLengthNeed = udat_toPattern((void *const *)fmt,false,NULL,nLength,&status);
     714         [ #  # ]:          0 :     if (status == U_BUFFER_OVERFLOW_ERROR)
     715                 :            :     {
     716                 :          0 :         status = U_ZERO_ERROR;
     717                 :          0 :         nLength = nLengthNeed +1;
     718                 :          0 :         pattern = (UChar*)malloc(sizeof(UChar)*nLength);
     719         [ #  # ]:          0 :         udat_toPattern((void *const *)fmt,false,pattern,nLength,&status);
     720                 :            :     }
     721                 :            : 
     722         [ #  # ]:          0 :     if (pattern == NULL)
     723                 :          0 :         return NULL;
     724                 :            :     // 3 parse pattern string,per icu date/time format syntax, there are 20 letters reserved
     725                 :            :     // as patter letter,each represent a element in date/time and its repeat numbers represent
     726                 :            :     // different format: for exampel: M produces '1',MM produces '01', MMM produces 'Jan', MMMM produces 'Januaray'
     727                 :            :     // letter other than these letters is regard as text in the format, for example ','in 'Jan,2005'
     728                 :            :     // we parse pattern string letter by letter and get the time format.
     729                 :            :     // for time format ,for there is not date info,we can only parse the letter representing time.
     730                 :            :     UChar cSymbol;
     731                 :            :     UChar cTmp;
     732 [ #  # ][ #  # ]:          0 :     XFTimeStyle* pTimeStyle = new XFTimeStyle;
     733                 :            : 
     734         [ #  # ]:          0 :     for (int32_t i=0;i<nLengthNeed;)
     735                 :            :     {
     736                 :          0 :         cSymbol = pattern[i];
     737                 :            :         int32_t j;
     738   [ #  #  #  #  :          0 :         switch(cSymbol)
          #  #  #  #  #  
                   #  # ]
     739                 :            :         {
     740                 :            :             case 'h':
     741                 :            :             {
     742                 :          0 :                 for (j=1;;j++)
     743                 :            :                 {
     744                 :          0 :                     cTmp = pattern[i+j];
     745         [ #  # ]:          0 :                     if (cTmp != cSymbol)
     746                 :            :                     {
     747                 :          0 :                         i=i+j;
     748                 :          0 :                         break;
     749                 :            :                     }
     750                 :            :                 }
     751         [ #  # ]:          0 :                 if (j==1)
     752         [ #  # ]:          0 :                     pTimeStyle->AddHour(sal_False);
     753                 :            :                 else
     754         [ #  # ]:          0 :                     pTimeStyle->AddHour();
     755                 :          0 :                 break;
     756                 :            :             }
     757                 :            :             case 'H':
     758                 :            :             {
     759                 :          0 :                 for (j=1;;j++)
     760                 :            :                 {
     761                 :          0 :                     cTmp = pattern[i+j];
     762         [ #  # ]:          0 :                     if (cTmp != cSymbol)
     763                 :            :                     {
     764                 :          0 :                         i=i+j;
     765                 :          0 :                         break;
     766                 :            :                     }
     767                 :            :                 }
     768         [ #  # ]:          0 :                 if (j==1)
     769         [ #  # ]:          0 :                     pTimeStyle->AddHour(sal_False);
     770                 :            :                 else
     771         [ #  # ]:          0 :                     pTimeStyle->AddHour();
     772                 :          0 :                 break;
     773                 :            :             }
     774                 :            :             case 'm':
     775                 :            :             {
     776                 :          0 :                 for (j=1;;j++)
     777                 :            :                 {
     778                 :          0 :                     cTmp = pattern[i+j];
     779         [ #  # ]:          0 :                     if (cTmp != cSymbol)
     780                 :            :                     {
     781                 :          0 :                         i=i+j;
     782                 :          0 :                         break;
     783                 :            :                     }
     784                 :            :                 }
     785         [ #  # ]:          0 :                 if (j==1)
     786         [ #  # ]:          0 :                     pTimeStyle->AddMinute(sal_False);
     787                 :            :                 else
     788         [ #  # ]:          0 :                     pTimeStyle->AddMinute();
     789                 :          0 :                 break;
     790                 :            :             }
     791                 :            :             case 's':
     792                 :            :             {
     793                 :          0 :                 for (j=1;;j++)
     794                 :            :                 {
     795                 :          0 :                     cTmp = pattern[i+j];
     796         [ #  # ]:          0 :                     if (cTmp != cSymbol)
     797                 :            :                     {
     798                 :          0 :                         i=i+j;
     799                 :          0 :                         break;
     800                 :            :                     }
     801                 :            :                 }
     802         [ #  # ]:          0 :                 if (j==1)
     803         [ #  # ]:          0 :                     pTimeStyle->AddSecond(sal_False,0);
     804                 :            :                 else
     805         [ #  # ]:          0 :                     pTimeStyle->AddSecond(sal_True,0);
     806                 :          0 :                 break;
     807                 :            :             }
     808                 :            :             case 'S':
     809                 :            :             {
     810                 :          0 :                 for (j=1;;j++)
     811                 :            :                 {
     812                 :          0 :                     cTmp = pattern[i+j];
     813         [ #  # ]:          0 :                     if (cTmp != cSymbol)
     814                 :            :                     {
     815                 :          0 :                         i=i+j;
     816                 :          0 :                         break;
     817                 :            :                     }
     818                 :            :                 }
     819                 :            :                 /*if (j==1)
     820                 :            :                     pDateStyle->AddSecond(sal_False);
     821                 :            :                 else
     822                 :            :                     pDateStyle->AddSecond();*/
     823                 :          0 :                 break;
     824                 :            :             }
     825                 :            :             case 'a':
     826                 :            :             {
     827                 :          0 :                 for (j=1;;j++)
     828                 :            :                 {
     829                 :          0 :                     cTmp = pattern[i+j];
     830         [ #  # ]:          0 :                     if (cTmp != cSymbol)
     831                 :            :                     {
     832                 :          0 :                         i=i+j;
     833                 :          0 :                         break;
     834                 :            :                     }
     835                 :            :                 }
     836                 :          0 :                 pTimeStyle->SetAmPm(sal_True);
     837                 :          0 :                 break;
     838                 :            :             }
     839                 :            :             case 'k':
     840                 :            :             {
     841                 :          0 :                 for (j=1;;j++)
     842                 :            :                 {
     843                 :          0 :                     cTmp = pattern[i+j];
     844         [ #  # ]:          0 :                     if (cTmp != cSymbol)
     845                 :            :                     {
     846                 :          0 :                         i=i+j;
     847                 :          0 :                         break;
     848                 :            :                     }
     849                 :            :                 }
     850                 :          0 :                 break;
     851                 :            :             }
     852                 :            :             case 'K':
     853                 :            :             {
     854                 :          0 :                 for (j=1;;j++)
     855                 :            :                 {
     856                 :          0 :                     cTmp = pattern[i+j];
     857         [ #  # ]:          0 :                     if (cTmp != cSymbol)
     858                 :            :                     {
     859                 :          0 :                         i=i+j;
     860                 :          0 :                         break;
     861                 :            :                     }
     862                 :            :                 }
     863         [ #  # ]:          0 :                 if (j==1)
     864         [ #  # ]:          0 :                     pTimeStyle->AddHour(sal_False);
     865                 :            :                 else
     866         [ #  # ]:          0 :                     pTimeStyle->AddHour();
     867                 :          0 :                 break;
     868                 :            :             }
     869                 :            :             case '\''://'
     870                 :            :             {
     871                 :          0 :                 for (j=1;;j++)
     872                 :            :                 {
     873                 :          0 :                     cTmp = pattern[i+j];
     874         [ #  # ]:          0 :                     if (cTmp != cSymbol)
     875                 :            :                     {
     876                 :          0 :                         i=i+j;
     877                 :          0 :                         break;
     878                 :            :                     }
     879                 :            :                 }
     880                 :          0 :                 break;
     881                 :            :             }
     882                 :            :             case '"':
     883                 :            :             {
     884         [ #  # ]:          0 :                 pTimeStyle->AddText(OUString(A2OUSTR("'")));
     885                 :          0 :                 break;
     886                 :            :             }
     887                 :            :             default:
     888                 :            :             {
     889 [ #  # ][ #  # ]:          0 :                 if ((cSymbol>='A' && cSymbol<='Z') || (cSymbol>='a' && cSymbol<='z') )
         [ #  # ][ #  # ]
     890                 :          0 :                     return NULL;
     891                 :            :                 else//TEXT
     892                 :            :                 {
     893                 :            :                     sal_Unicode buffer[1024];
     894                 :          0 :                     buffer[0] = cSymbol;
     895                 :            :                     //strBuffer.append(cSymbol);
     896                 :          0 :                     for (j=1;;j++)
     897                 :            :                     {
     898                 :          0 :                         cTmp = pattern[i+j];
     899 [ #  # ][ #  # ]:          0 :                         if ((cTmp>='A' && cTmp<='Z') || (cTmp>='a' && cTmp<='z') ||
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     900                 :            :                             cTmp=='\'' || cTmp=='"' )
     901                 :            :                         {
     902                 :          0 :                             i=i+j;
     903                 :          0 :                             buffer[j]= '\0';
     904                 :          0 :                             break;
     905                 :            :                         }
     906                 :            :                         else
     907                 :          0 :                             buffer[j] = cTmp;
     908                 :            :                     }
     909         [ #  # ]:          0 :                     pTimeStyle->AddText(OUString(buffer));//keep for all parsed
     910                 :            :                 }
     911                 :          0 :                 break;
     912                 :            :             }
     913                 :            :         }
     914                 :            :     }
     915                 :            : //  udat_close(fmt);
     916         [ #  # ]:          0 :     return pTimeStyle;
     917                 :            : }
     918                 :            : 
     919                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10