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