LCOV - code coverage report
Current view: top level - lotuswordpro/source/filter - lwptools.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 58 369 15.7 %
Date: 2014-11-03 Functions: 4 9 44.4 %
Legend: Lines: hit not hit

          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             : #include <i18nlangtag/languagetagicu.hxx>
      75             : 
      76             : #ifdef SAL_UNX
      77             : #define SEPARATOR '/'
      78             : #else
      79             : #define SEPARATOR '\\'
      80             : #endif
      81             : 
      82             : using namespace ::osl;
      83             : 
      84             : /**
      85             :  * @descr       read lwp unicode string from stream to OUString per aEncoding
      86             : */
      87        1806 : sal_uInt16 LwpTools::QuickReadUnicode(LwpObjectStream* pObjStrm,
      88             :         OUString& str, sal_uInt16 strlen, rtl_TextEncoding aEncoding)
      89             :         //strlen: length of bytes
      90             : {
      91             : 
      92        1806 :     sal_uInt16 readLen = 0;
      93        1806 :     OUStringBuffer strBuf(128);
      94             : 
      95        1806 :     if( !IsUnicodePacked(pObjStrm, strlen) )
      96             :     {
      97        1772 :         sal_uInt16 len = 0;
      98             :         sal_Char buf[1024];
      99             : 
     100        5272 :         while(strlen)
     101             :         {
     102        1728 :             strlen>1023?len=1023 :len=strlen;
     103        1728 :             len = pObjStrm->QuickRead(buf, len);
     104        1728 :             buf[len] = '\0';
     105        1728 :             strBuf.append( OUString(buf, len, aEncoding) );
     106        1728 :             strlen -= len;
     107        1728 :             readLen += len;
     108        1728 :             if(!len) break;
     109             :         }
     110        1772 :         str = strBuf.makeStringAndClear();
     111        1772 :         return readLen;
     112             :     }
     113             :     else
     114             :     {
     115             :         sal_Char buf[1024];
     116             :         sal_Unicode unibuf[1024];
     117             :         sal_uInt8 readbyte;
     118             :         sal_uInt16 readword;
     119             : 
     120          34 :         bool flag = false;  //switch if unicode part reached
     121          34 :         sal_uInt16 sublen = 0;
     122             : 
     123         982 :         while(readLen<strlen)
     124             :         {
     125         914 :             if(!flag)   //Not unicode string
     126             :             {
     127             :                 bool bFailure;
     128         784 :                 readbyte = pObjStrm->QuickReaduInt8(&bFailure);
     129         784 :                 if(bFailure) break;
     130         784 :                 readLen+=sizeof(readbyte);
     131             : 
     132         784 :                 if(readbyte == 0x00)
     133             :                 {
     134          34 :                     flag = true;
     135          34 :                     if(sublen>0)    //add it to the strBuf
     136             :                     {
     137          10 :                         strBuf.append( OUString(buf, sublen, aEncoding) ); //try the aEncoding
     138          10 :                         sublen = 0;
     139             :                     }
     140             :                 }
     141             :                 else
     142             :                 {
     143         750 :                     buf[sublen++] = readbyte;
     144             :                 }
     145         784 :                 if(sublen>=1023 || readLen==strlen) //add it to the strBuf
     146             :                 {
     147          12 :                     strBuf.append( OUString(buf, sublen, aEncoding) ); //try the aEncoding
     148          12 :                     sublen = 0;
     149             :                 }
     150             :             }
     151             :             else        //unicode string
     152             :             {
     153             :                 bool bFailure;
     154         130 :                 readword = pObjStrm->QuickReaduInt16(&bFailure);
     155         130 :                 if(bFailure) break;
     156         130 :                 readLen+=sizeof(readword);
     157             : 
     158         130 :                 if(readword == 0x0000)
     159             :                 {
     160          12 :                     flag = false;
     161          12 :                     if(sublen)
     162             :                     {
     163          12 :                         unibuf[sublen] = '\0';
     164          12 :                         strBuf.append( OUString(unibuf) );
     165          12 :                         sublen = 0;
     166             :                     }
     167             :                 }
     168             :                 else
     169             :                 {
     170         118 :                     unibuf[sublen++] = readword;
     171             :                 }
     172         130 :                 if(sublen>=1023 || readLen==strlen)
     173             :                 {
     174          22 :                     unibuf[sublen] = '\0';
     175          22 :                     strBuf.append( OUString(unibuf) );
     176          22 :                     sublen = 0;
     177             :                 }
     178             :             }
     179             :         }
     180          34 :         str = strBuf.makeStringAndClear();
     181          34 :         return readLen;
     182        1806 :     }
     183             : }
     184             : 
     185             : /**
     186             :  * @descr       Judge if the data (len) in object stream is lwp unicode packed
     187             : */
     188        1806 : bool LwpTools::IsUnicodePacked(LwpObjectStream* pObjStrm, sal_uInt16 len)
     189             : {
     190             :     sal_uInt8 byte;
     191        1806 :     sal_uInt16 oldpos = pObjStrm->GetPos();
     192             : 
     193       30534 :     for (sal_uInt16 i = 0; i < len; i++)
     194             :     {
     195       28762 :         byte = pObjStrm->QuickReaduInt8();
     196       28762 :         if (byte == 0x00)
     197             :         {
     198          34 :             pObjStrm->Seek(oldpos);
     199          34 :             return true;
     200             :         }
     201             :     }
     202        1772 :     pObjStrm->Seek(oldpos);
     203        1772 :     return false;
     204             : }
     205             : 
     206           0 : bool LwpTools::isFileUrl(const OString &fileName)
     207             : {
     208           0 :     if (fileName.startsWith("file://") )
     209           0 :         return true;
     210           0 :     return false;
     211             : }
     212             : 
     213           0 : OUString LwpTools::convertToFileUrl(const OString &fileName)
     214             : {
     215           0 :     if ( isFileUrl(fileName) )
     216             :     {
     217           0 :         return OStringToOUString(fileName, osl_getThreadTextEncoding());
     218             :     }
     219             : 
     220           0 :     OUString uUrlFileName;
     221           0 :     OUString uFileName(fileName.getStr(), fileName.getLength(), osl_getThreadTextEncoding());
     222           0 :     if ( fileName.startsWith(".") || fileName.indexOf(SEPARATOR) < 0 )
     223             :     {
     224           0 :         OUString uWorkingDir;
     225           0 :         OSL_VERIFY( osl_getProcessWorkingDir(&uWorkingDir.pData) == osl_Process_E_None );
     226           0 :         OSL_VERIFY( FileBase::getAbsoluteFileURL(uWorkingDir, uFileName, uUrlFileName) == FileBase::E_None );
     227             :     } else
     228             :     {
     229           0 :         OSL_VERIFY( FileBase::getFileURLFromSystemPath(uFileName, uUrlFileName) == FileBase::E_None );
     230             :     }
     231             : 
     232           0 :     return uUrlFileName;
     233             : }
     234             : 
     235           0 : OUString LwpTools::DateTimeToOUString(LtTm & dt)
     236             : {
     237           0 :     OUString aResult = OUString::number(dt.tm_year) + "-" + OUString::number(dt.tm_mon) + "-" + OUString::number(dt.tm_mday) +
     238           0 :         "T" + OUString::number(dt.tm_hour) + ":" + OUString::number(dt.tm_min) + ":" + OUString::number(dt.tm_sec);
     239             : 
     240           0 :     return aResult;
     241             : }
     242             : 
     243             : /**
     244             :  * @descr   get the system date format
     245             : */
     246           0 : XFDateStyle* LwpTools::GetSystemDateStyle(bool bLongFormat)
     247             : {
     248             :     icu::DateFormat::EStyle style;
     249           0 :     if (bLongFormat)
     250           0 :         style = icu::DateFormat::FULL;//system full date format
     251             :     else
     252           0 :         style = icu::DateFormat::SHORT;//system short date format
     253             : 
     254             :     //1 get locale for system
     255           0 :     icu::Locale aLocale( LanguageTagIcu::getIcuLocale( Application::GetSettings().GetLanguageTag()));
     256             :     //2 get icu format pattern by locale
     257           0 :     icu::DateFormat* fmt = icu::DateFormat::createDateInstance(style,aLocale);
     258             : 
     259           0 :     int32_t nLength = 0;
     260             :     int32_t nLengthNeed;
     261           0 :     UErrorCode status = U_ZERO_ERROR;
     262           0 :     UChar* pattern = NULL;
     263             : 
     264           0 :     nLengthNeed = udat_toPattern((void *const *)fmt,sal_False,NULL,nLength,&status);
     265           0 :     if (status == U_BUFFER_OVERFLOW_ERROR)
     266             :     {
     267           0 :         status = U_ZERO_ERROR;
     268           0 :         nLength = nLengthNeed +1;
     269           0 :         pattern = (UChar*)malloc(sizeof(UChar)*nLength);
     270           0 :         udat_toPattern((void *const *)fmt,sal_False,pattern,nLength,&status);
     271             :     }
     272           0 :     if (pattern == NULL)
     273           0 :         return NULL;
     274             :     // 3 parse pattern string,per icu date/time format syntax, there are 20 letters reserved
     275             :     // as patter letter,each represent a element in date/time and its repeat numbers represent
     276             :     // different format: for exampel: M produces '1',MM produces '01', MMM produces 'Jan', MMMM produces 'Januaray'
     277             :     // letter other than these letters is regard as text in the format, for example ','in 'Jan,2005'
     278             :     // we parse pattern string letter by letter and get the time format.
     279             :     UChar cSymbol;
     280             :     UChar cTmp;
     281           0 :     XFDateStyle* pDateStyle = new XFDateStyle;
     282             : 
     283           0 :     for (int32_t i=0;i<nLengthNeed;)
     284             :     {
     285           0 :         cSymbol = pattern[i];
     286             :         int32_t j;
     287           0 :         switch(cSymbol)
     288             :         {
     289             :             case 'G':
     290             :             {
     291           0 :                 for (j=1;;j++)
     292             :                 {
     293           0 :                     cTmp = pattern[i+j];
     294           0 :                     if (cTmp != cSymbol)
     295             :                     {
     296           0 :                         i=i+j;
     297           0 :                         break;
     298             :                     }
     299             :                 }
     300           0 :                 pDateStyle->AddEra();
     301           0 :                 break;
     302             :             }
     303             :             case 'y':
     304             :             {
     305           0 :                 for (j=1;;j++)
     306             :                 {
     307           0 :                     cTmp = pattern[i+j];
     308           0 :                     if (cTmp != cSymbol)
     309             :                     {
     310           0 :                         i=i+j;
     311           0 :                         break;
     312             :                     }
     313             :                 }
     314           0 :                 if (j <= 2)
     315           0 :                     pDateStyle->AddYear(false);
     316             :                 else
     317           0 :                     pDateStyle->AddYear();
     318           0 :                 break;
     319             :             }
     320             :             case 'M':
     321             :             {
     322           0 :                 for (j=1;;j++)
     323             :                 {
     324           0 :                     cTmp = pattern[i+j];
     325           0 :                     if (cTmp != cSymbol)
     326             :                     {
     327           0 :                         i=i+j;
     328           0 :                         break;
     329             :                     }
     330             :                 }
     331           0 :                 if (j==1)
     332           0 :                     pDateStyle->AddMonth(false,false);
     333           0 :                 else if (j==2)
     334           0 :                     pDateStyle->AddMonth(true,false);
     335           0 :                 else if (j==3)
     336           0 :                     pDateStyle->AddMonth(false,true);
     337             :                 else
     338           0 :                     pDateStyle->AddMonth(true,true);
     339           0 :                 break;
     340             :             }
     341             :             case 'd':
     342             :             {
     343           0 :                 for (j=1;;j++)
     344             :                 {
     345           0 :                     cTmp = pattern[i+j];
     346           0 :                     if (cTmp != cSymbol)
     347             :                     {
     348           0 :                         i=i+j;
     349           0 :                         break;
     350             :                     }
     351             :                 }
     352           0 :                 if (j==1)
     353           0 :                     pDateStyle->AddMonthDay(false);
     354             :                 else
     355           0 :                     pDateStyle->AddMonthDay();
     356           0 :                 break;
     357             :             }
     358             :             case 'h':
     359             :             {
     360           0 :                 for (j=1;;j++)
     361             :                 {
     362           0 :                     cTmp = pattern[i+j];
     363           0 :                     if (cTmp != cSymbol)
     364             :                     {
     365           0 :                         i=i+j;
     366           0 :                         break;
     367             :                     }
     368             :                 }
     369           0 :                 if (j==1)
     370           0 :                     pDateStyle->AddHour(false);
     371             :                 else
     372           0 :                     pDateStyle->AddHour();
     373           0 :                 break;
     374             :             }
     375             :             case 'H':
     376             :             {
     377           0 :                 for (j=1;;j++)
     378             :                 {
     379           0 :                     cTmp = pattern[i+j];
     380           0 :                     if (cTmp != cSymbol)
     381             :                     {
     382           0 :                         i=i+j;
     383           0 :                         break;
     384             :                     }
     385             :                 }
     386           0 :                 if (j==1)
     387           0 :                     pDateStyle->AddHour(false);
     388             :                 else
     389           0 :                     pDateStyle->AddHour();
     390           0 :                 break;
     391             :             }
     392             :             case 'm':
     393             :             {
     394           0 :                 for (j=1;;j++)
     395             :                 {
     396           0 :                     cTmp = pattern[i+j];
     397           0 :                     if (cTmp != cSymbol)
     398             :                     {
     399           0 :                         i=i+j;
     400           0 :                         break;
     401             :                     }
     402             :                 }
     403           0 :                 if (j==1)
     404           0 :                     pDateStyle->AddMinute(false);
     405             :                 else
     406           0 :                     pDateStyle->AddMinute();
     407           0 :                 break;
     408             :             }
     409             :             case 's':
     410             :             {
     411           0 :                 for (j=1;;j++)
     412             :                 {
     413           0 :                     cTmp = pattern[i+j];
     414           0 :                     if (cTmp != cSymbol)
     415             :                     {
     416           0 :                         i=i+j;
     417           0 :                         break;
     418             :                     }
     419             :                 }
     420           0 :                 if (j==1)
     421           0 :                     pDateStyle->AddSecond(false,0);
     422             :                 else
     423           0 :                     pDateStyle->AddSecond(true,0);
     424           0 :                 break;
     425             :             }
     426             :             case 'S':
     427             :             {
     428           0 :                 for (j=1;;j++)
     429             :                 {
     430           0 :                     cTmp = pattern[i+j];
     431           0 :                     if (cTmp != cSymbol)
     432             :                     {
     433           0 :                         i=i+j;
     434           0 :                         break;
     435             :                     }
     436             :                 }
     437             :                 /*if (j==1)
     438             :                     pDateStyle->AddSecond(sal_False);
     439             :                 else
     440             :                     pDateStyle->AddSecond();*/
     441           0 :                 break;
     442             :             }
     443             :             case 'E':
     444             :             {
     445           0 :                 for (j=1;;j++)
     446             :                 {
     447           0 :                     cTmp = pattern[i+j];
     448           0 :                     if (cTmp != cSymbol)
     449             :                     {
     450           0 :                         i=i+j;
     451           0 :                         break;
     452             :                     }
     453             :                 }
     454           0 :                 if (j<=2)
     455           0 :                     pDateStyle->AddWeekDay(false);
     456             :                 else
     457           0 :                     pDateStyle->AddWeekDay();
     458           0 :                 break;
     459             :             }
     460             :             case 'D':
     461             :             {
     462           0 :                 for (j=1;;j++)
     463             :                 {
     464           0 :                     cTmp = pattern[i+j];
     465           0 :                     if (cTmp != cSymbol)
     466             :                     {
     467           0 :                         i=i+j;
     468           0 :                         break;
     469             :                     }
     470             :                 }
     471             :                 /*if (j==1)
     472             :                     pDateStyle->AddWeekDay(sal_False);
     473             :                 else
     474             :                     pDateStyle->AddWeekDay();*/
     475           0 :                 break;
     476             :             }
     477             :             case 'F':
     478             :             {
     479           0 :                 for (j=1;;j++)
     480             :                 {
     481           0 :                     cTmp = pattern[i+j];
     482           0 :                     if (cTmp != cSymbol)
     483             :                     {
     484           0 :                         i=i+j;
     485           0 :                         break;
     486             :                     }
     487             :                 }
     488             :                 /*if (j==1)
     489             :                     pDateStyle->AddWeekDay(sal_False);
     490             :                 else
     491             :                     pDateStyle->AddWeekDay();*/
     492           0 :                 break;
     493             :             }
     494             :             case 'w':
     495             :             {
     496           0 :                 for (j=1;;j++)
     497             :                 {
     498           0 :                     cTmp = pattern[i+j];
     499           0 :                     if (cTmp != cSymbol)
     500             :                     {
     501           0 :                         i=i+j;
     502           0 :                         break;
     503             :                     }
     504             :                 }
     505             :                 /*if (j==1)
     506             :                     pDateStyle->AddWeekDay(sal_False);
     507             :                 else
     508             :                     pDateStyle->AddWeekDay();*/
     509           0 :                 break;
     510             :             }
     511             :             case 'W':
     512             :             {
     513           0 :                 for (j=1;;j++)
     514             :                 {
     515           0 :                     cTmp = pattern[i+j];
     516           0 :                     if (cTmp != cSymbol)
     517             :                     {
     518           0 :                         i=i+j;
     519           0 :                         break;
     520             :                     }
     521             :                 }
     522             :                 /*if (j==1)
     523             :                     pDateStyle->AddWeekDay(sal_False);
     524             :                 else
     525             :                     pDateStyle->AddWeekDay();*/
     526           0 :                 break;
     527             :             }
     528             :             case 'a':
     529             :             {
     530           0 :                 for (j=1;;j++)
     531             :                 {
     532           0 :                     cTmp = pattern[i+j];
     533           0 :                     if (cTmp != cSymbol)
     534             :                     {
     535           0 :                         i=i+j;
     536           0 :                         break;
     537             :                     }
     538             :                 }
     539           0 :                 pDateStyle->AddAmPm(true);
     540           0 :                 break;
     541             :             }
     542             :             case 'k':
     543             :             {
     544           0 :                 for (j=1;;j++)
     545             :                 {
     546           0 :                     cTmp = pattern[i+j];
     547           0 :                     if (cTmp != cSymbol)
     548             :                     {
     549           0 :                         i=i+j;
     550           0 :                         break;
     551             :                     }
     552             :                 }
     553           0 :                 break;
     554             :             }
     555             :             case 'K':
     556             :             {
     557           0 :                 for (j=1;;j++)
     558             :                 {
     559           0 :                     cTmp = pattern[i+j];
     560           0 :                     if (cTmp != cSymbol)
     561             :                     {
     562           0 :                         i=i+j;
     563           0 :                         break;
     564             :                     }
     565             :                 }
     566           0 :                 if (j==1)
     567           0 :                     pDateStyle->AddHour(false);
     568             :                 else
     569           0 :                     pDateStyle->AddHour();
     570           0 :                 break;
     571             :             }
     572             :             case 'Z':
     573             :             {
     574           0 :                 for (j=1;;j++)
     575             :                 {
     576           0 :                     cTmp = pattern[i+j];
     577           0 :                     if (cTmp != cSymbol)
     578             :                     {
     579           0 :                         i=i+j;
     580           0 :                         break;
     581             :                     }
     582             :                 }
     583           0 :                 break;
     584             :             }
     585             :             case '\''://'
     586             :             {
     587           0 :                 for (j=1;;j++)
     588             :                 {
     589           0 :                     cTmp = pattern[i+j];
     590           0 :                     if (cTmp != cSymbol)
     591             :                     {
     592           0 :                         i=i+j;
     593           0 :                         break;
     594             :                     }
     595             :                 }
     596           0 :                 break;
     597             :             }
     598             :             case '"':
     599             :             {
     600           0 :                 pDateStyle->AddText("'");
     601           0 :                 break;
     602             :             }
     603             :             default:
     604             :             {
     605           0 :                 if ((cSymbol>='A' && cSymbol<='Z') || (cSymbol>='a' && cSymbol<='z') )
     606             :                 {
     607           0 :                     delete pDateStyle;
     608           0 :                     return NULL;
     609             :                 }
     610             :                 else//TEXT
     611             :                 {
     612             :                     //UChar buffer[1024];
     613             :                     sal_Unicode buffer[1024];
     614           0 :                     buffer[0] = cSymbol;
     615           0 :                     for (j=1;;j++)
     616             :                     {
     617           0 :                         cTmp = pattern[i+j];
     618           0 :                         if ((cTmp>='A' && cTmp<='Z') || (cTmp>='a' && cTmp<='z') ||
     619           0 :                             cTmp=='\'' || cTmp=='"' )
     620             :                         {
     621           0 :                             i=i+j;
     622           0 :                             buffer[j]= '\0';
     623           0 :                             break;
     624             :                         }
     625             :                         else
     626           0 :                             buffer[j] = cTmp;
     627             :                     }
     628             : 
     629           0 :                     pDateStyle->AddText(OUString(buffer));//keep for all parsed
     630             :                 }
     631           0 :                 break;
     632           0 :             }
     633             :         }
     634             :     }
     635             : //  udat_close(fmt);
     636           0 :     return pDateStyle;
     637             : }
     638             : /**
     639             :  * @descr   get the system time format
     640             : */
     641           0 : XFTimeStyle* LwpTools::GetSystemTimeStyle()
     642             : {
     643             :     //1 get locale for system
     644           0 :     icu::Locale aLocale( LanguageTagIcu::getIcuLocale( Application::GetSettings().GetLanguageTag()));
     645             :     //2 get icu format pattern by locale
     646           0 :     icu::DateFormat* fmt = icu::DateFormat::createTimeInstance(icu::DateFormat::DEFAULT,aLocale);
     647             : 
     648           0 :     int32_t nLength = 0;
     649             :     int32_t nLengthNeed;
     650           0 :     UErrorCode status = U_ZERO_ERROR;
     651           0 :     UChar* pattern = NULL;
     652           0 :     nLengthNeed = udat_toPattern((void *const *)fmt,false,NULL,nLength,&status);
     653           0 :     if (status == U_BUFFER_OVERFLOW_ERROR)
     654             :     {
     655           0 :         status = U_ZERO_ERROR;
     656           0 :         nLength = nLengthNeed +1;
     657           0 :         pattern = (UChar*)malloc(sizeof(UChar)*nLength);
     658           0 :         udat_toPattern((void *const *)fmt,false,pattern,nLength,&status);
     659             :     }
     660             : 
     661           0 :     if (pattern == NULL)
     662           0 :         return NULL;
     663             :     // 3 parse pattern string,per icu date/time format syntax, there are 20 letters reserved
     664             :     // as patter letter,each represent a element in date/time and its repeat numbers represent
     665             :     // different format: for exampel: M produces '1',MM produces '01', MMM produces 'Jan', MMMM produces 'Januaray'
     666             :     // letter other than these letters is regard as text in the format, for example ','in 'Jan,2005'
     667             :     // we parse pattern string letter by letter and get the time format.
     668             :     // for time format ,for there is not date info,we can only parse the letter representing time.
     669             :     UChar cSymbol;
     670             :     UChar cTmp;
     671           0 :     XFTimeStyle* pTimeStyle = new XFTimeStyle;
     672             : 
     673           0 :     for (int32_t i=0;i<nLengthNeed;)
     674             :     {
     675           0 :         cSymbol = pattern[i];
     676             :         int32_t j;
     677           0 :         switch(cSymbol)
     678             :         {
     679             :             case 'h':
     680             :             {
     681           0 :                 for (j=1;;j++)
     682             :                 {
     683           0 :                     cTmp = pattern[i+j];
     684           0 :                     if (cTmp != cSymbol)
     685             :                     {
     686           0 :                         i=i+j;
     687           0 :                         break;
     688             :                     }
     689             :                 }
     690           0 :                 if (j==1)
     691           0 :                     pTimeStyle->AddHour(false);
     692             :                 else
     693           0 :                     pTimeStyle->AddHour();
     694           0 :                 break;
     695             :             }
     696             :             case 'H':
     697             :             {
     698           0 :                 for (j=1;;j++)
     699             :                 {
     700           0 :                     cTmp = pattern[i+j];
     701           0 :                     if (cTmp != cSymbol)
     702             :                     {
     703           0 :                         i=i+j;
     704           0 :                         break;
     705             :                     }
     706             :                 }
     707           0 :                 if (j==1)
     708           0 :                     pTimeStyle->AddHour(false);
     709             :                 else
     710           0 :                     pTimeStyle->AddHour();
     711           0 :                 break;
     712             :             }
     713             :             case 'm':
     714             :             {
     715           0 :                 for (j=1;;j++)
     716             :                 {
     717           0 :                     cTmp = pattern[i+j];
     718           0 :                     if (cTmp != cSymbol)
     719             :                     {
     720           0 :                         i=i+j;
     721           0 :                         break;
     722             :                     }
     723             :                 }
     724           0 :                 if (j==1)
     725           0 :                     pTimeStyle->AddMinute(false);
     726             :                 else
     727           0 :                     pTimeStyle->AddMinute();
     728           0 :                 break;
     729             :             }
     730             :             case 's':
     731             :             {
     732           0 :                 for (j=1;;j++)
     733             :                 {
     734           0 :                     cTmp = pattern[i+j];
     735           0 :                     if (cTmp != cSymbol)
     736             :                     {
     737           0 :                         i=i+j;
     738           0 :                         break;
     739             :                     }
     740             :                 }
     741           0 :                 if (j==1)
     742           0 :                     pTimeStyle->AddSecond(false,0);
     743             :                 else
     744           0 :                     pTimeStyle->AddSecond(true,0);
     745           0 :                 break;
     746             :             }
     747             :             case 'S':
     748             :             {
     749           0 :                 for (j=1;;j++)
     750             :                 {
     751           0 :                     cTmp = pattern[i+j];
     752           0 :                     if (cTmp != cSymbol)
     753             :                     {
     754           0 :                         i=i+j;
     755           0 :                         break;
     756             :                     }
     757             :                 }
     758             :                 /*if (j==1)
     759             :                     pDateStyle->AddSecond(sal_False);
     760             :                 else
     761             :                     pDateStyle->AddSecond();*/
     762           0 :                 break;
     763             :             }
     764             :             case 'a':
     765             :             {
     766           0 :                 for (j=1;;j++)
     767             :                 {
     768           0 :                     cTmp = pattern[i+j];
     769           0 :                     if (cTmp != cSymbol)
     770             :                     {
     771           0 :                         i=i+j;
     772           0 :                         break;
     773             :                     }
     774             :                 }
     775           0 :                 pTimeStyle->SetAmPm(true);
     776           0 :                 break;
     777             :             }
     778             :             case 'k':
     779             :             {
     780           0 :                 for (j=1;;j++)
     781             :                 {
     782           0 :                     cTmp = pattern[i+j];
     783           0 :                     if (cTmp != cSymbol)
     784             :                     {
     785           0 :                         i=i+j;
     786           0 :                         break;
     787             :                     }
     788             :                 }
     789           0 :                 break;
     790             :             }
     791             :             case 'K':
     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->AddHour(false);
     804             :                 else
     805           0 :                     pTimeStyle->AddHour();
     806           0 :                 break;
     807             :             }
     808             :             case '\''://'
     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           0 :                 break;
     820             :             }
     821             :             case '"':
     822             :             {
     823           0 :                 pTimeStyle->AddText("'");
     824           0 :                 break;
     825             :             }
     826             :             default:
     827             :             {
     828           0 :                 if ((cSymbol>='A' && cSymbol<='Z') || (cSymbol>='a' && cSymbol<='z') )
     829             :                 {
     830           0 :                     delete pTimeStyle;
     831           0 :                     return NULL;
     832             :                 }
     833             :                 else//TEXT
     834             :                 {
     835             :                     sal_Unicode buffer[1024];
     836           0 :                     buffer[0] = cSymbol;
     837             :                     //strBuffer.append(cSymbol);
     838           0 :                     for (j=1;;j++)
     839             :                     {
     840           0 :                         cTmp = pattern[i+j];
     841           0 :                         if ((cTmp>='A' && cTmp<='Z') || (cTmp>='a' && cTmp<='z') ||
     842           0 :                             cTmp=='\'' || cTmp=='"' )
     843             :                         {
     844           0 :                             i=i+j;
     845           0 :                             buffer[j]= '\0';
     846           0 :                             break;
     847             :                         }
     848             :                         else
     849           0 :                             buffer[j] = cTmp;
     850             :                     }
     851           0 :                     pTimeStyle->AddText(OUString(buffer));//keep for all parsed
     852             :                 }
     853           0 :                 break;
     854           0 :             }
     855             :         }
     856             :     }
     857             : //  udat_close(fmt);
     858           0 :     return pTimeStyle;
     859           6 : }
     860             : 
     861             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10