PageRenderTime 55ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 1ms

/libreoffice-3.6.0.2/binfilter/bf_svtools/source/numbers/svt_zforscan.cxx

#
C++ | 2768 lines | 2547 code | 84 blank | 137 comment | 617 complexity | 20ad6b6e255dee4815d937b829cdec26 MD5 | raw file
Possible License(s): MPL-2.0-no-copyleft-exception, LGPL-2.1, AGPL-1.0, BSD-3-Clause-No-Nuclear-License-2014, GPL-3.0, LGPL-3.0

Large files files are truncated, but you can click here to view the full file

  1. /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
  2. /*************************************************************************
  3. *
  4. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  5. *
  6. * Copyright 2000, 2010 Oracle and/or its affiliates.
  7. *
  8. * OpenOffice.org - a multi-platform office productivity suite
  9. *
  10. * This file is part of OpenOffice.org.
  11. *
  12. * OpenOffice.org is free software: you can redistribute it and/or modify
  13. * it under the terms of the GNU Lesser General Public License version 3
  14. * only, as published by the Free Software Foundation.
  15. *
  16. * OpenOffice.org is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU Lesser General Public License version 3 for more details
  20. * (a copy is included in the LICENSE file that accompanied this code).
  21. *
  22. * You should have received a copy of the GNU Lesser General Public License
  23. * version 3 along with OpenOffice.org. If not, see
  24. * <http://www.openoffice.org/license.html>
  25. * for a copy of the LGPLv3 License.
  26. *
  27. ************************************************************************/
  28. #include <stdlib.h>
  29. #include <tools/debug.hxx>
  30. #include <i18npool/mslangid.hxx>
  31. #include <unotools/charclass.hxx>
  32. #include <unotools/localedatawrapper.hxx>
  33. #include <unotools/numberformatcodewrapper.hxx>
  34. #include <rtl/instance.hxx>
  35. #include <bf_svtools/zforlist.hxx>
  36. #include <bf_svtools/zformat.hxx>
  37. #define _ZFORSCAN_CXX
  38. #include "zforscan.hxx"
  39. #undef _ZFORSCAN_CXX
  40. #include "nfsymbol.hxx"
  41. namespace binfilter
  42. {
  43. const sal_Unicode cNonBreakingSpace = 0xA0;
  44. namespace
  45. {
  46. struct ImplEnglishColors
  47. {
  48. const String* operator()()
  49. {
  50. static const String aEnglishColors[NF_MAX_DEFAULT_COLORS] =
  51. {
  52. String( RTL_CONSTASCII_USTRINGPARAM( "BLACK" ) ),
  53. String( RTL_CONSTASCII_USTRINGPARAM( "BLUE" ) ),
  54. String( RTL_CONSTASCII_USTRINGPARAM( "GREEN" ) ),
  55. String( RTL_CONSTASCII_USTRINGPARAM( "CYAN" ) ),
  56. String( RTL_CONSTASCII_USTRINGPARAM( "RED" ) ),
  57. String( RTL_CONSTASCII_USTRINGPARAM( "MAGENTA" ) ),
  58. String( RTL_CONSTASCII_USTRINGPARAM( "BROWN" ) ),
  59. String( RTL_CONSTASCII_USTRINGPARAM( "GREY" ) ),
  60. String( RTL_CONSTASCII_USTRINGPARAM( "YELLOW" ) ),
  61. String( RTL_CONSTASCII_USTRINGPARAM( "WHITE" ) )
  62. };
  63. return &aEnglishColors[0];
  64. }
  65. };
  66. struct theEnglishColors
  67. : public rtl::StaticAggregate< const String, ImplEnglishColors> {};
  68. }
  69. ImpSvNumberformatScan::ImpSvNumberformatScan( SvNumberFormatter* pFormatterP )
  70. {
  71. pFormatter = pFormatterP;
  72. bConvertMode = FALSE;
  73. //! All keywords MUST be UPPERCASE!
  74. sKeyword[NF_KEY_E].AssignAscii( RTL_CONSTASCII_STRINGPARAM( "E" ) ); // Exponent
  75. sKeyword[NF_KEY_AMPM].AssignAscii( RTL_CONSTASCII_STRINGPARAM( "AM/PM" ) ); // AM/PM
  76. sKeyword[NF_KEY_AP].AssignAscii( RTL_CONSTASCII_STRINGPARAM( "A/P" ) ); // AM/PM short
  77. sKeyword[NF_KEY_MI].AssignAscii( RTL_CONSTASCII_STRINGPARAM( "M" ) ); // Minute
  78. sKeyword[NF_KEY_MMI].AssignAscii( RTL_CONSTASCII_STRINGPARAM( "MM" ) ); // Minute 02
  79. sKeyword[NF_KEY_S].AssignAscii( RTL_CONSTASCII_STRINGPARAM( "S" ) ); // Second
  80. sKeyword[NF_KEY_SS].AssignAscii( RTL_CONSTASCII_STRINGPARAM( "SS" ) ); // Second 02
  81. sKeyword[NF_KEY_Q].AssignAscii( RTL_CONSTASCII_STRINGPARAM( "Q" ) ); // Quarter short 'Q'
  82. sKeyword[NF_KEY_QQ].AssignAscii( RTL_CONSTASCII_STRINGPARAM( "QQ" ) ); // Quarter long
  83. sKeyword[NF_KEY_NN].AssignAscii( RTL_CONSTASCII_STRINGPARAM( "NN" ) ); // Day of week short
  84. sKeyword[NF_KEY_NNN].AssignAscii( RTL_CONSTASCII_STRINGPARAM( "NNN" ) ); // Day of week long
  85. sKeyword[NF_KEY_NNNN].AssignAscii( RTL_CONSTASCII_STRINGPARAM( "NNNN" ) ); // Day of week long incl. separator
  86. sKeyword[NF_KEY_WW].AssignAscii( RTL_CONSTASCII_STRINGPARAM( "WW" ) ); // Week of year
  87. sKeyword[NF_KEY_CCC].AssignAscii( RTL_CONSTASCII_STRINGPARAM( "CCC" ) ); // Currency abbreviation
  88. bKeywordsNeedInit = TRUE; // locale dependent keywords
  89. bCompatCurNeedInit = TRUE; // locale dependent compatibility currency strings
  90. StandardColor[0] = Color(COL_BLACK);
  91. StandardColor[1] = Color(COL_LIGHTBLUE);
  92. StandardColor[2] = Color(COL_LIGHTGREEN);
  93. StandardColor[3] = Color(COL_LIGHTCYAN);
  94. StandardColor[4] = Color(COL_LIGHTRED);
  95. StandardColor[5] = Color(COL_LIGHTMAGENTA);
  96. StandardColor[6] = Color(COL_BROWN);
  97. StandardColor[7] = Color(COL_GRAY);
  98. StandardColor[8] = Color(COL_YELLOW);
  99. StandardColor[9] = Color(COL_WHITE);
  100. pNullDate = new Date(30,12,1899);
  101. nStandardPrec = 2;
  102. sErrStr.AssignAscii( RTL_CONSTASCII_STRINGPARAM( "###" ) );
  103. Reset();
  104. }
  105. ImpSvNumberformatScan::~ImpSvNumberformatScan()
  106. {
  107. delete pNullDate;
  108. Reset();
  109. }
  110. void ImpSvNumberformatScan::ChangeIntl()
  111. {
  112. bKeywordsNeedInit = TRUE;
  113. bCompatCurNeedInit = TRUE;
  114. // may be initialized by InitSpecialKeyword()
  115. sKeyword[NF_KEY_TRUE].Erase();
  116. sKeyword[NF_KEY_FALSE].Erase();
  117. }
  118. void ImpSvNumberformatScan::InitSpecialKeyword( NfKeywordIndex eIdx ) const
  119. {
  120. switch ( eIdx )
  121. {
  122. case NF_KEY_TRUE :
  123. ((ImpSvNumberformatScan*)this)->sKeyword[NF_KEY_TRUE] =
  124. pFormatter->GetCharClass()->uppercase(
  125. pFormatter->GetLocaleData()->getTrueWord() );
  126. if ( !sKeyword[NF_KEY_TRUE].Len() )
  127. {
  128. DBG_ERRORFILE( "InitSpecialKeyword: TRUE_WORD?" );
  129. ((ImpSvNumberformatScan*)this)->sKeyword[NF_KEY_TRUE].AssignAscii( RTL_CONSTASCII_STRINGPARAM( "TRUE" ) );
  130. }
  131. break;
  132. case NF_KEY_FALSE :
  133. ((ImpSvNumberformatScan*)this)->sKeyword[NF_KEY_FALSE] =
  134. pFormatter->GetCharClass()->uppercase(
  135. pFormatter->GetLocaleData()->getFalseWord() );
  136. if ( !sKeyword[NF_KEY_FALSE].Len() )
  137. {
  138. DBG_ERRORFILE( "InitSpecialKeyword: FALSE_WORD?" );
  139. ((ImpSvNumberformatScan*)this)->sKeyword[NF_KEY_FALSE].AssignAscii( RTL_CONSTASCII_STRINGPARAM( "FALSE" ) );
  140. }
  141. break;
  142. default:
  143. DBG_ERRORFILE( "InitSpecialKeyword: unknown request" );
  144. }
  145. }
  146. void ImpSvNumberformatScan::InitCompatCur() const
  147. {
  148. ImpSvNumberformatScan* pThis = (ImpSvNumberformatScan*)this;
  149. // currency symbol for old style ("automatic") compatibility format codes
  150. pFormatter->GetCompatibilityCurrency( pThis->sCurSymbol, pThis->sCurAbbrev );
  151. // currency symbol upper case
  152. pThis->sCurString = pFormatter->GetCharClass()->uppercase( sCurSymbol );
  153. bCompatCurNeedInit = FALSE;
  154. }
  155. void ImpSvNumberformatScan::InitKeywords() const
  156. {
  157. if ( !bKeywordsNeedInit )
  158. return ;
  159. ((ImpSvNumberformatScan*)this)->SetDependentKeywords();
  160. bKeywordsNeedInit = FALSE;
  161. }
  162. void ImpSvNumberformatScan::SetDependentKeywords()
  163. {
  164. using namespace ::com::sun::star;
  165. using namespace ::com::sun::star::uno;
  166. const CharClass* pCharClass = pFormatter->GetCharClass();
  167. const LocaleDataWrapper* pLocaleData = pFormatter->GetLocaleData();
  168. // #80023# be sure to generate keywords for the loaded Locale, not for the
  169. // requested Locale, otherwise number format codes might not match
  170. lang::Locale aLoadedLocale = pLocaleData->getLoadedLocale();
  171. LanguageType eLang = MsLangId::convertLocaleToLanguage( aLoadedLocale );
  172. NumberFormatCodeWrapper aNumberFormatCode( pFormatter->GetServiceManager(), aLoadedLocale );
  173. i18n::NumberFormatCode aFormat = aNumberFormatCode.getFormatCode( NF_NUMBER_STANDARD );
  174. sNameStandardFormat = aFormat.Code;
  175. sKeyword[NF_KEY_GENERAL] = pCharClass->uppercase( sNameStandardFormat );
  176. // preset new calendar keywords
  177. sKeyword[NF_KEY_AAA].AssignAscii( RTL_CONSTASCII_STRINGPARAM( "AAA" ) );
  178. sKeyword[NF_KEY_AAAA].AssignAscii( RTL_CONSTASCII_STRINGPARAM( "AAAA" ) );
  179. sKeyword[NF_KEY_EC].AssignAscii( RTL_CONSTASCII_STRINGPARAM( "E" ) );
  180. sKeyword[NF_KEY_EEC].AssignAscii( RTL_CONSTASCII_STRINGPARAM( "EE" ) );
  181. sKeyword[NF_KEY_G].AssignAscii( RTL_CONSTASCII_STRINGPARAM( "G" ) );
  182. sKeyword[NF_KEY_GG].AssignAscii( RTL_CONSTASCII_STRINGPARAM( "GG" ) );
  183. sKeyword[NF_KEY_GGG].AssignAscii( RTL_CONSTASCII_STRINGPARAM( "GGG" ) );
  184. sKeyword[NF_KEY_R].AssignAscii( RTL_CONSTASCII_STRINGPARAM( "R" ) );
  185. sKeyword[NF_KEY_RR].AssignAscii( RTL_CONSTASCII_STRINGPARAM( "RR" ) );
  186. // Thai T NatNum special. Other locale's small letter 't' results in upper
  187. // case comparison not matching but length does in conversion mode. Ugly.
  188. if (eLang == LANGUAGE_THAI)
  189. sKeyword[NF_KEY_THAI_T].AssignAscii( RTL_CONSTASCII_STRINGPARAM( "T"));
  190. else
  191. sKeyword[NF_KEY_THAI_T].AssignAscii( RTL_CONSTASCII_STRINGPARAM( "t"));
  192. switch ( eLang )
  193. {
  194. case LANGUAGE_GERMAN:
  195. case LANGUAGE_GERMAN_SWISS:
  196. case LANGUAGE_GERMAN_AUSTRIAN:
  197. case LANGUAGE_GERMAN_LUXEMBOURG:
  198. case LANGUAGE_GERMAN_LIECHTENSTEIN:
  199. {
  200. //! all capital letters
  201. sKeyword[NF_KEY_M].AssignAscii( RTL_CONSTASCII_STRINGPARAM( "M" ) ); // month 1
  202. sKeyword[NF_KEY_MM].AssignAscii( RTL_CONSTASCII_STRINGPARAM( "MM" ) ); // month 01
  203. sKeyword[NF_KEY_MMM].AssignAscii( RTL_CONSTASCII_STRINGPARAM( "MMM" ) ); // month Jan
  204. sKeyword[NF_KEY_MMMM].AssignAscii( RTL_CONSTASCII_STRINGPARAM( "MMMM" ) ); // month Januar
  205. sKeyword[NF_KEY_MMMMM].AssignAscii( RTL_CONSTASCII_STRINGPARAM( "MMMMM" ) );// month J
  206. sKeyword[NF_KEY_H].AssignAscii( RTL_CONSTASCII_STRINGPARAM( "H" ) ); // hour 2
  207. sKeyword[NF_KEY_HH].AssignAscii( RTL_CONSTASCII_STRINGPARAM( "HH" ) ); // hour 02
  208. sKeyword[NF_KEY_D].AssignAscii( RTL_CONSTASCII_STRINGPARAM( "T" ) );
  209. sKeyword[NF_KEY_DD].AssignAscii( RTL_CONSTASCII_STRINGPARAM( "TT" ) );
  210. sKeyword[NF_KEY_DDD].AssignAscii( RTL_CONSTASCII_STRINGPARAM( "TTT" ) );
  211. sKeyword[NF_KEY_DDDD].AssignAscii( RTL_CONSTASCII_STRINGPARAM( "TTTT" ) );
  212. sKeyword[NF_KEY_YY].AssignAscii( RTL_CONSTASCII_STRINGPARAM( "JJ" ) );
  213. sKeyword[NF_KEY_YYYY].AssignAscii( RTL_CONSTASCII_STRINGPARAM( "JJJJ" ) );
  214. sKeyword[NF_KEY_BOOLEAN].AssignAscii( RTL_CONSTASCII_STRINGPARAM( "LOGISCH" ) );
  215. sKeyword[NF_KEY_COLOR].AssignAscii( RTL_CONSTASCII_STRINGPARAM( "FARBE" ) );
  216. sKeyword[NF_KEY_BLACK].AssignAscii( RTL_CONSTASCII_STRINGPARAM( "SCHWARZ" ) );
  217. sKeyword[NF_KEY_BLUE].AssignAscii( RTL_CONSTASCII_STRINGPARAM( "BLAU" ) );
  218. sKeyword[NF_KEY_GREEN] = UniString( "GR" "\xDC" "N", RTL_TEXTENCODING_ISO_8859_1 );
  219. sKeyword[NF_KEY_CYAN].AssignAscii( RTL_CONSTASCII_STRINGPARAM( "CYAN" ) );
  220. sKeyword[NF_KEY_RED].AssignAscii( RTL_CONSTASCII_STRINGPARAM( "ROT" ) );
  221. sKeyword[NF_KEY_MAGENTA].AssignAscii( RTL_CONSTASCII_STRINGPARAM( "MAGENTA" ) );
  222. sKeyword[NF_KEY_BROWN].AssignAscii( RTL_CONSTASCII_STRINGPARAM( "BRAUN" ) );
  223. sKeyword[NF_KEY_GREY].AssignAscii( RTL_CONSTASCII_STRINGPARAM( "GRAU" ) );
  224. sKeyword[NF_KEY_YELLOW].AssignAscii( RTL_CONSTASCII_STRINGPARAM( "GELB" ) );
  225. sKeyword[NF_KEY_WHITE].AssignAscii( RTL_CONSTASCII_STRINGPARAM( "WEISS" ) );
  226. }
  227. break;
  228. default:
  229. {
  230. // day
  231. switch ( eLang )
  232. {
  233. case LANGUAGE_ITALIAN :
  234. case LANGUAGE_ITALIAN_SWISS :
  235. sKeyword[NF_KEY_D].AssignAscii( RTL_CONSTASCII_STRINGPARAM( "G" ) );
  236. sKeyword[NF_KEY_DD].AssignAscii( RTL_CONSTASCII_STRINGPARAM( "GG" ) );
  237. sKeyword[NF_KEY_DDD].AssignAscii( RTL_CONSTASCII_STRINGPARAM( "GGG" ) );
  238. sKeyword[NF_KEY_DDDD].AssignAscii( RTL_CONSTASCII_STRINGPARAM( "GGGG" ) );
  239. // must exchange the era code, same as Xcl
  240. sKeyword[NF_KEY_G].AssignAscii( RTL_CONSTASCII_STRINGPARAM( "X" ) );
  241. sKeyword[NF_KEY_GG].AssignAscii( RTL_CONSTASCII_STRINGPARAM( "XX" ) );
  242. sKeyword[NF_KEY_GGG].AssignAscii( RTL_CONSTASCII_STRINGPARAM( "XXX" ) );
  243. break;
  244. case LANGUAGE_FRENCH :
  245. case LANGUAGE_FRENCH_BELGIAN :
  246. case LANGUAGE_FRENCH_CANADIAN :
  247. case LANGUAGE_FRENCH_SWISS :
  248. case LANGUAGE_FRENCH_LUXEMBOURG :
  249. case LANGUAGE_FRENCH_MONACO :
  250. sKeyword[NF_KEY_D].AssignAscii( RTL_CONSTASCII_STRINGPARAM( "J" ) );
  251. sKeyword[NF_KEY_DD].AssignAscii( RTL_CONSTASCII_STRINGPARAM( "JJ" ) );
  252. sKeyword[NF_KEY_DDD].AssignAscii( RTL_CONSTASCII_STRINGPARAM( "JJJ" ) );
  253. sKeyword[NF_KEY_DDDD].AssignAscii( RTL_CONSTASCII_STRINGPARAM( "JJJJ" ) );
  254. break;
  255. case LANGUAGE_FINNISH :
  256. sKeyword[NF_KEY_D].AssignAscii( RTL_CONSTASCII_STRINGPARAM( "P" ) );
  257. sKeyword[NF_KEY_DD].AssignAscii( RTL_CONSTASCII_STRINGPARAM( "PP" ) );
  258. sKeyword[NF_KEY_DDD].AssignAscii( RTL_CONSTASCII_STRINGPARAM( "PPP" ) );
  259. sKeyword[NF_KEY_DDDD].AssignAscii( RTL_CONSTASCII_STRINGPARAM( "PPPP" ) );
  260. break;
  261. default:
  262. sKeyword[NF_KEY_D].AssignAscii( RTL_CONSTASCII_STRINGPARAM( "D" ) );
  263. sKeyword[NF_KEY_DD].AssignAscii( RTL_CONSTASCII_STRINGPARAM( "DD" ) );
  264. sKeyword[NF_KEY_DDD].AssignAscii( RTL_CONSTASCII_STRINGPARAM( "DDD" ) );
  265. sKeyword[NF_KEY_DDDD].AssignAscii( RTL_CONSTASCII_STRINGPARAM( "DDDD" ) );
  266. }
  267. // month
  268. switch ( eLang )
  269. {
  270. case LANGUAGE_FINNISH :
  271. sKeyword[NF_KEY_M].AssignAscii( RTL_CONSTASCII_STRINGPARAM( "K" ) );
  272. sKeyword[NF_KEY_MM].AssignAscii( RTL_CONSTASCII_STRINGPARAM( "KK" ) );
  273. sKeyword[NF_KEY_MMM].AssignAscii( RTL_CONSTASCII_STRINGPARAM( "KKK" ) );
  274. sKeyword[NF_KEY_MMMM].AssignAscii( RTL_CONSTASCII_STRINGPARAM( "KKKK" ) );
  275. sKeyword[NF_KEY_MMMMM].AssignAscii( RTL_CONSTASCII_STRINGPARAM( "KKKKK" ) );
  276. break;
  277. default:
  278. sKeyword[NF_KEY_M].AssignAscii( RTL_CONSTASCII_STRINGPARAM( "M" ) );
  279. sKeyword[NF_KEY_MM].AssignAscii( RTL_CONSTASCII_STRINGPARAM( "MM" ) );
  280. sKeyword[NF_KEY_MMM].AssignAscii( RTL_CONSTASCII_STRINGPARAM( "MMM" ) );
  281. sKeyword[NF_KEY_MMMM].AssignAscii( RTL_CONSTASCII_STRINGPARAM( "MMMM" ) );
  282. sKeyword[NF_KEY_MMMMM].AssignAscii( RTL_CONSTASCII_STRINGPARAM( "MMMMM" ) );
  283. }
  284. // year
  285. switch ( eLang )
  286. {
  287. case LANGUAGE_ITALIAN :
  288. case LANGUAGE_ITALIAN_SWISS :
  289. case LANGUAGE_FRENCH :
  290. case LANGUAGE_FRENCH_BELGIAN :
  291. case LANGUAGE_FRENCH_CANADIAN :
  292. case LANGUAGE_FRENCH_SWISS :
  293. case LANGUAGE_FRENCH_LUXEMBOURG :
  294. case LANGUAGE_FRENCH_MONACO :
  295. case LANGUAGE_PORTUGUESE :
  296. case LANGUAGE_PORTUGUESE_BRAZILIAN :
  297. case LANGUAGE_SPANISH_MODERN :
  298. case LANGUAGE_SPANISH_DATED :
  299. case LANGUAGE_SPANISH_MEXICAN :
  300. case LANGUAGE_SPANISH_GUATEMALA :
  301. case LANGUAGE_SPANISH_COSTARICA :
  302. case LANGUAGE_SPANISH_PANAMA :
  303. case LANGUAGE_SPANISH_DOMINICAN_REPUBLIC :
  304. case LANGUAGE_SPANISH_VENEZUELA :
  305. case LANGUAGE_SPANISH_COLOMBIA :
  306. case LANGUAGE_SPANISH_PERU :
  307. case LANGUAGE_SPANISH_ARGENTINA :
  308. case LANGUAGE_SPANISH_ECUADOR :
  309. case LANGUAGE_SPANISH_CHILE :
  310. case LANGUAGE_SPANISH_URUGUAY :
  311. case LANGUAGE_SPANISH_PARAGUAY :
  312. case LANGUAGE_SPANISH_BOLIVIA :
  313. case LANGUAGE_SPANISH_EL_SALVADOR :
  314. case LANGUAGE_SPANISH_HONDURAS :
  315. case LANGUAGE_SPANISH_NICARAGUA :
  316. case LANGUAGE_SPANISH_PUERTO_RICO :
  317. sKeyword[NF_KEY_YY].AssignAscii( RTL_CONSTASCII_STRINGPARAM( "AA" ) );
  318. sKeyword[NF_KEY_YYYY].AssignAscii( RTL_CONSTASCII_STRINGPARAM( "AAAA" ) );
  319. // must exchange the day of week name code, same as Xcl
  320. sKeyword[NF_KEY_AAA].AssignAscii( RTL_CONSTASCII_STRINGPARAM( "OOO" ) );
  321. sKeyword[NF_KEY_AAAA].AssignAscii( RTL_CONSTASCII_STRINGPARAM( "OOOO" ) );
  322. break;
  323. case LANGUAGE_DUTCH :
  324. case LANGUAGE_DUTCH_BELGIAN :
  325. sKeyword[NF_KEY_YY].AssignAscii( RTL_CONSTASCII_STRINGPARAM( "JJ" ) );
  326. sKeyword[NF_KEY_YYYY].AssignAscii( RTL_CONSTASCII_STRINGPARAM( "JJJJ" ) );
  327. break;
  328. case LANGUAGE_FINNISH :
  329. sKeyword[NF_KEY_YY].AssignAscii( RTL_CONSTASCII_STRINGPARAM( "VV" ) );
  330. sKeyword[NF_KEY_YYYY].AssignAscii( RTL_CONSTASCII_STRINGPARAM( "VVVV" ) );
  331. break;
  332. default:
  333. sKeyword[NF_KEY_YY].AssignAscii( RTL_CONSTASCII_STRINGPARAM( "YY" ) );
  334. sKeyword[NF_KEY_YYYY].AssignAscii( RTL_CONSTASCII_STRINGPARAM( "YYYY" ) );
  335. }
  336. // hour
  337. switch ( eLang )
  338. {
  339. case LANGUAGE_DUTCH :
  340. case LANGUAGE_DUTCH_BELGIAN :
  341. sKeyword[NF_KEY_H].AssignAscii( RTL_CONSTASCII_STRINGPARAM( "U" ) );
  342. sKeyword[NF_KEY_HH].AssignAscii( RTL_CONSTASCII_STRINGPARAM( "UU" ) );
  343. break;
  344. case LANGUAGE_FINNISH :
  345. case LANGUAGE_SWEDISH :
  346. case LANGUAGE_SWEDISH_FINLAND :
  347. case LANGUAGE_DANISH :
  348. case LANGUAGE_NORWEGIAN :
  349. case LANGUAGE_NORWEGIAN_BOKMAL :
  350. case LANGUAGE_NORWEGIAN_NYNORSK :
  351. sKeyword[NF_KEY_H].AssignAscii( RTL_CONSTASCII_STRINGPARAM( "T" ) );
  352. sKeyword[NF_KEY_HH].AssignAscii( RTL_CONSTASCII_STRINGPARAM( "TT" ) );
  353. break;
  354. default:
  355. sKeyword[NF_KEY_H].AssignAscii( RTL_CONSTASCII_STRINGPARAM( "H" ) );
  356. sKeyword[NF_KEY_HH].AssignAscii( RTL_CONSTASCII_STRINGPARAM( "HH" ) );
  357. }
  358. // boolean
  359. sKeyword[NF_KEY_BOOLEAN].AssignAscii( RTL_CONSTASCII_STRINGPARAM( "BOOLEAN" ) );
  360. // colours
  361. sKeyword[NF_KEY_COLOR].AssignAscii( RTL_CONSTASCII_STRINGPARAM( "COLOR" ) );
  362. sKeyword[NF_KEY_BLACK].AssignAscii( RTL_CONSTASCII_STRINGPARAM( "BLACK" ) );
  363. sKeyword[NF_KEY_BLUE].AssignAscii( RTL_CONSTASCII_STRINGPARAM( "BLUE" ) );
  364. sKeyword[NF_KEY_GREEN].AssignAscii( RTL_CONSTASCII_STRINGPARAM( "GREEN" ) );
  365. sKeyword[NF_KEY_CYAN].AssignAscii( RTL_CONSTASCII_STRINGPARAM( "CYAN" ) );
  366. sKeyword[NF_KEY_RED].AssignAscii( RTL_CONSTASCII_STRINGPARAM( "RED" ) );
  367. sKeyword[NF_KEY_MAGENTA].AssignAscii( RTL_CONSTASCII_STRINGPARAM( "MAGENTA" ) );
  368. sKeyword[NF_KEY_BROWN].AssignAscii( RTL_CONSTASCII_STRINGPARAM( "BROWN" ) );
  369. sKeyword[NF_KEY_GREY].AssignAscii( RTL_CONSTASCII_STRINGPARAM( "GREY" ) );
  370. sKeyword[NF_KEY_YELLOW].AssignAscii( RTL_CONSTASCII_STRINGPARAM( "YELLOW" ) );
  371. sKeyword[NF_KEY_WHITE].AssignAscii( RTL_CONSTASCII_STRINGPARAM( "WHITE" ) );
  372. }
  373. break;
  374. }
  375. // boolean keyords
  376. InitSpecialKeyword( NF_KEY_TRUE );
  377. InitSpecialKeyword( NF_KEY_FALSE );
  378. // compatibility currency strings
  379. InitCompatCur();
  380. }
  381. void ImpSvNumberformatScan::ChangeNullDate(USHORT nDay, USHORT nMonth, USHORT nYear)
  382. {
  383. if ( pNullDate )
  384. *pNullDate = Date(nDay, nMonth, nYear);
  385. else
  386. pNullDate = new Date(nDay, nMonth, nYear);
  387. }
  388. void ImpSvNumberformatScan::ChangeStandardPrec(short nPrec)
  389. {
  390. nStandardPrec = nPrec;
  391. }
  392. Color* ImpSvNumberformatScan::GetColor(String& sStr)
  393. {
  394. String sString = pFormatter->GetCharClass()->uppercase(sStr);
  395. const String* pKeyword = GetKeywords();
  396. size_t i = 0;
  397. while (i < NF_MAX_DEFAULT_COLORS &&
  398. sString != pKeyword[NF_KEY_FIRSTCOLOR+i] )
  399. i++;
  400. if ( i >= NF_MAX_DEFAULT_COLORS )
  401. {
  402. const String* pEnglishColors = theEnglishColors::get();
  403. size_t j = 0;
  404. while ( j < NF_MAX_DEFAULT_COLORS &&
  405. sString != pEnglishColors[j] )
  406. ++j;
  407. if ( j < NF_MAX_DEFAULT_COLORS )
  408. i = j;
  409. }
  410. if (i >= NF_MAX_DEFAULT_COLORS)
  411. {
  412. const String& rColorWord = pKeyword[NF_KEY_COLOR];
  413. xub_StrLen nPos = sString.Match(rColorWord);
  414. if (nPos > 0)
  415. {
  416. sStr.Erase(0, nPos);
  417. sStr.EraseLeadingChars();
  418. sStr.EraseTrailingChars();
  419. if (bConvertMode)
  420. {
  421. pFormatter->ChangeIntl(eNewLnge);
  422. sStr.Insert( GetKeywords()[NF_KEY_COLOR], 0 ); // Color -> FARBE
  423. pFormatter->ChangeIntl(eTmpLnge);
  424. }
  425. else
  426. sStr.Insert(rColorWord,0);
  427. sString.Erase(0, nPos);
  428. sString.EraseLeadingChars();
  429. sString.EraseTrailingChars();
  430. if ( CharClass::isAsciiNumeric( sString ) )
  431. {
  432. long nIndex = sString.ToInt32();
  433. if (nIndex > 0 && nIndex <= 64)
  434. return pFormatter->GetUserDefColor((USHORT)nIndex-1);
  435. else
  436. return NULL;
  437. }
  438. else
  439. return NULL;
  440. }
  441. else
  442. return NULL;
  443. }
  444. else
  445. {
  446. sStr.Erase();
  447. if (bConvertMode)
  448. {
  449. pFormatter->ChangeIntl(eNewLnge);
  450. sStr = GetKeywords()[NF_KEY_FIRSTCOLOR+i]; // red -> rot
  451. pFormatter->ChangeIntl(eTmpLnge);
  452. }
  453. else
  454. sStr = pKeyword[NF_KEY_FIRSTCOLOR+i];
  455. return &(StandardColor[i]);
  456. }
  457. }
  458. short ImpSvNumberformatScan::GetKeyWord( const String& sSymbol, xub_StrLen nPos )
  459. {
  460. String sString = pFormatter->GetCharClass()->uppercase( sSymbol, nPos, sSymbol.Len() - nPos );
  461. const String* pKeyword = GetKeywords();
  462. // #77026# for the Xcl perverts: the GENERAL keyword is recognized anywhere
  463. if ( sString.Search( pKeyword[NF_KEY_GENERAL] ) == 0 )
  464. return NF_KEY_GENERAL;
  465. //! MUST be a reverse search to find longer strings first
  466. short i = NF_KEYWORD_ENTRIES_COUNT-1;
  467. BOOL bFound = FALSE;
  468. for ( ; i > NF_KEY_LASTKEYWORD_SO5; --i )
  469. {
  470. bFound = sString.Search(pKeyword[i]) == 0;
  471. if ( bFound )
  472. {
  473. break;
  474. }
  475. }
  476. // new keywords take precedence over old keywords
  477. if ( !bFound )
  478. { // skip the gap of colors et al between new and old keywords and search on
  479. i = NF_KEY_LASTKEYWORD;
  480. while ( i > 0 && sString.Search(pKeyword[i]) != 0 )
  481. i--;
  482. if ( i > NF_KEY_LASTOLDKEYWORD && sString != pKeyword[i] )
  483. { // found something, but maybe it's something else?
  484. // e.g. new NNN is found in NNNN, for NNNN we must search on
  485. short j = i - 1;
  486. while ( j > 0 && sString.Search(pKeyword[j]) != 0 )
  487. j--;
  488. if ( j && pKeyword[j].Len() > pKeyword[i].Len() )
  489. return j;
  490. }
  491. }
  492. // The Thai T NatNum modifier during Xcl import.
  493. if (i == 0 && bConvertMode && sString.GetChar(0) == 'T' && eTmpLnge ==
  494. LANGUAGE_ENGLISH_US && MsLangId::getRealLanguage( eNewLnge) ==
  495. LANGUAGE_THAI)
  496. i = NF_KEY_THAI_T;
  497. return i; // 0 => not found
  498. }
  499. //---------------------------------------------------------------------------
  500. // Next_Symbol
  501. //---------------------------------------------------------------------------
  502. // Zerlegt die Eingabe in Symbole fuer die weitere
  503. // Verarbeitung (Turing-Maschine).
  504. //---------------------------------------------------------------------------
  505. // Ausgangs Zustand = SsStart
  506. //---------------+-------------------+-----------------------+---------------
  507. // Alter Zustand | gelesenes Zeichen | Aktion | Neuer Zustand
  508. //---------------+-------------------+-----------------------+---------------
  509. // SsStart | Buchstabe | Symbol=Zeichen | SsGetWord
  510. // | " | Typ = String | SsGetString
  511. // | \ | Typ = String | SsGetChar
  512. // | * | Typ = Star | SsGetStar
  513. // | _ | Typ = Blank | SsGetBlank
  514. // | @ # 0 ? / . , % [ | Symbol = Zeichen; |
  515. // | ] ' Blank | Typ = Steuerzeichen | SsStop
  516. // | $ - + ( ) : | Typ = String; |
  517. // | | | Typ = Comment | SsStop
  518. // | Sonst | Symbol = Zeichen | SsStop
  519. //---------------|-------------------+-----------------------+---------------
  520. // SsGetChar | Sonst | Symbol=Zeichen | SsStop
  521. //---------------+-------------------+-----------------------+---------------
  522. // GetString | " | | SsStop
  523. // | Sonst | Symbol+=Zeichen | GetString
  524. //---------------+-------------------+-----------------------+---------------
  525. // SsGetWord | Buchstabe | Symbol += Zeichen |
  526. // | + - (E+ E-)| Symbol += Zeichen | SsStop
  527. // | / (AM/PM)| Symbol += Zeichen |
  528. // | Sonst | Pos--, if Key Typ=Word| SsStop
  529. //---------------+-------------------+-----------------------+---------------
  530. // SsGetStar | Sonst | Symbol+=Zeichen | SsStop
  531. // | | markiere Sonderfall * |
  532. //---------------+-------------------+-----------------------+---------------
  533. // SsGetBlank | Sonst | Symbol+=Zeichen | SsStop
  534. // | | markiere Sonderfall _ |
  535. //---------------+-------------------+-----------------------+---------------
  536. // Wurde im State SsGetWord ein Schluesselwort erkannt (auch als
  537. // Anfangsteilwort des Symbols)
  538. // so werden die restlichen Buchstaben zurueckgeschrieben !!
  539. enum ScanState
  540. {
  541. SsStop = 0,
  542. SsStart = 1,
  543. SsGetChar = 2,
  544. SsGetString = 3,
  545. SsGetWord = 4,
  546. SsGetStar = 5,
  547. SsGetBlank = 6
  548. };
  549. short ImpSvNumberformatScan::Next_Symbol( const String& rStr,
  550. xub_StrLen& nPos, String& sSymbol )
  551. {
  552. if ( bKeywordsNeedInit )
  553. InitKeywords();
  554. const CharClass* pChrCls = pFormatter->GetCharClass();
  555. const LocaleDataWrapper* pLoc = pFormatter->GetLocaleData();
  556. const xub_StrLen nStart = nPos;
  557. short eType = 0;
  558. ScanState eState = SsStart;
  559. sSymbol.Erase();
  560. while ( nPos < rStr.Len() && eState != SsStop )
  561. {
  562. sal_Unicode cToken = rStr.GetChar( nPos++ );
  563. switch (eState)
  564. {
  565. case SsStart:
  566. {
  567. // Fetch any currency longer than one character and don't get
  568. // confused later on by "E/" or other combinations of letters
  569. // and meaningful symbols. Necessary for old automatic currency.
  570. // #96158# But don't do it if we're starting a "[...]" section,
  571. // for example a "[$...]" new currency symbol to not parse away
  572. // "$U" (symbol) of "[$UYU]" (abbreviation).
  573. if ( nCurrPos != STRING_NOTFOUND && sCurString.Len() > 1 &&
  574. nPos-1 + sCurString.Len() <= rStr.Len() &&
  575. !(nPos > 1 && rStr.GetChar( nPos-2 ) == '[') )
  576. {
  577. String aTest( rStr.Copy( nPos-1, sCurString.Len() ) );
  578. aTest = pChrCls->uppercase( aTest );
  579. if ( aTest == sCurString )
  580. {
  581. sSymbol = rStr.Copy( --nPos, sCurString.Len() );
  582. nPos = nPos + sSymbol.Len();
  583. eState = SsStop;
  584. eType = NF_SYMBOLTYPE_STRING;
  585. return eType;
  586. }
  587. }
  588. switch (cToken)
  589. {
  590. case '#':
  591. case '0':
  592. case '?':
  593. case '%':
  594. case '@':
  595. case '[':
  596. case ']':
  597. case ',':
  598. case '.':
  599. case '/':
  600. case '\'':
  601. case ' ':
  602. case ':':
  603. case '-':
  604. {
  605. eType = NF_SYMBOLTYPE_DEL;
  606. sSymbol += cToken;
  607. eState = SsStop;
  608. }
  609. break;
  610. case '*':
  611. {
  612. eType = NF_SYMBOLTYPE_STAR;
  613. sSymbol += cToken;
  614. eState = SsGetStar;
  615. }
  616. break;
  617. case '_':
  618. {
  619. eType = NF_SYMBOLTYPE_BLANK;
  620. sSymbol += cToken;
  621. eState = SsGetBlank;
  622. }
  623. break;
  624. #if NF_COMMENT_IN_FORMATSTRING
  625. case '{':
  626. eType = NF_SYMBOLTYPE_COMMENT;
  627. eState = SsStop;
  628. sSymbol.Append( rStr.GetBuffer() + (nPos-1), rStr.Len() - (nPos-1) );
  629. nPos = rStr.Len();
  630. break;
  631. #endif
  632. case '"':
  633. eType = NF_SYMBOLTYPE_STRING;
  634. eState = SsGetString;
  635. sSymbol += cToken;
  636. break;
  637. case '\\':
  638. eType = NF_SYMBOLTYPE_STRING;
  639. eState = SsGetChar;
  640. sSymbol += cToken;
  641. break;
  642. case '$':
  643. case '+':
  644. case '(':
  645. case ')':
  646. eType = NF_SYMBOLTYPE_STRING;
  647. eState = SsStop;
  648. sSymbol += cToken;
  649. break;
  650. default :
  651. {
  652. if (StringEqualsChar( pFormatter->GetNumDecimalSep(), cToken) ||
  653. StringEqualsChar( pFormatter->GetNumThousandSep(), cToken) ||
  654. StringEqualsChar( pFormatter->GetDateSep(), cToken) ||
  655. StringEqualsChar( pLoc->getTimeSep(), cToken) ||
  656. StringEqualsChar( pLoc->getTime100SecSep(), cToken))
  657. {
  658. // Another separator than pre-known ASCII
  659. eType = NF_SYMBOLTYPE_DEL;
  660. sSymbol += cToken;
  661. eState = SsStop;
  662. }
  663. else if ( pChrCls->isLetter( rStr, nPos-1 ) )
  664. {
  665. short nTmpType = GetKeyWord( rStr, nPos-1 );
  666. if ( nTmpType )
  667. {
  668. BOOL bCurrency = FALSE;
  669. // "Automatic" currency may start with keyword,
  670. // like "R" (Rand) and 'R' (era)
  671. if ( nCurrPos != STRING_NOTFOUND &&
  672. nPos-1 + sCurString.Len() <= rStr.Len() &&
  673. sCurString.Search( sKeyword[nTmpType] ) == 0 )
  674. {
  675. String aTest( rStr.Copy( nPos-1, sCurString.Len() ) );
  676. aTest = pChrCls->uppercase( aTest );
  677. if ( aTest == sCurString )
  678. bCurrency = TRUE;
  679. }
  680. if ( bCurrency )
  681. {
  682. eState = SsGetWord;
  683. sSymbol += cToken;
  684. }
  685. else
  686. {
  687. eType = nTmpType;
  688. xub_StrLen nLen = sKeyword[eType].Len();
  689. sSymbol = rStr.Copy( nPos-1, nLen );
  690. if ( eType == NF_KEY_E || IsAmbiguousE( eType ) )
  691. {
  692. sal_Unicode cNext = rStr.GetChar(nPos);
  693. switch ( cNext )
  694. {
  695. case '+' :
  696. case '-' : // E+ E- combine to one symbol
  697. sSymbol += cNext;
  698. eType = NF_KEY_E;
  699. nPos++;
  700. break;
  701. case '0' :
  702. case '#' : // scientific E without sign
  703. eType = NF_KEY_E;
  704. break;
  705. }
  706. }
  707. nPos--;
  708. nPos = nPos + nLen;
  709. eState = SsStop;
  710. }
  711. }
  712. else
  713. {
  714. eState = SsGetWord;
  715. sSymbol += cToken;
  716. }
  717. }
  718. else
  719. {
  720. eType = NF_SYMBOLTYPE_STRING;
  721. eState = SsStop;
  722. sSymbol += cToken;
  723. }
  724. }
  725. break;
  726. }
  727. }
  728. break;
  729. case SsGetChar:
  730. {
  731. sSymbol += cToken;
  732. eState = SsStop;
  733. }
  734. break;
  735. case SsGetString:
  736. {
  737. if (cToken == '"')
  738. eState = SsStop;
  739. sSymbol += cToken;
  740. }
  741. break;
  742. case SsGetWord:
  743. {
  744. if ( pChrCls->isLetter( rStr, nPos-1 ) )
  745. {
  746. short nTmpType = GetKeyWord( rStr, nPos-1 );
  747. if ( nTmpType )
  748. { // beginning of keyword, stop scan and put back
  749. eType = NF_SYMBOLTYPE_STRING;
  750. eState = SsStop;
  751. nPos--;
  752. }
  753. else
  754. sSymbol += cToken;
  755. }
  756. else
  757. {
  758. BOOL bDontStop = FALSE;
  759. switch (cToken)
  760. {
  761. case '/': // AM/PM, A/P
  762. {
  763. sal_Unicode cNext = rStr.GetChar(nPos);
  764. if ( cNext == 'P' || cNext == 'p' )
  765. {
  766. xub_StrLen nLen = sSymbol.Len();
  767. if ( 1 <= nLen
  768. && (sSymbol.GetChar(0) == 'A' || sSymbol.GetChar(0) == 'a')
  769. && (nLen == 1 || (nLen == 2
  770. && (sSymbol.GetChar(1) == 'M' || sSymbol.GetChar(1) == 'm')
  771. && (rStr.GetChar(nPos+1) == 'M' || rStr.GetChar(nPos+1) == 'm'))) )
  772. {
  773. sSymbol += cToken;
  774. bDontStop = TRUE;
  775. }
  776. }
  777. }
  778. break;
  779. }
  780. // anything not recognized will stop the scan
  781. if ( eState != SsStop && !bDontStop )
  782. {
  783. eState = SsStop;
  784. nPos--;
  785. eType = NF_SYMBOLTYPE_STRING;
  786. }
  787. }
  788. }
  789. break;
  790. case SsGetStar:
  791. {
  792. eState = SsStop;
  793. sSymbol += cToken;
  794. nRepPos = (nPos - nStart) - 1; // everytime > 0!!
  795. }
  796. break;
  797. case SsGetBlank:
  798. {
  799. eState = SsStop;
  800. sSymbol += cToken;
  801. }
  802. break;
  803. default:
  804. break;
  805. } // of switch
  806. } // of while
  807. if (eState == SsGetWord)
  808. eType = NF_SYMBOLTYPE_STRING;
  809. return eType;
  810. }
  811. xub_StrLen ImpSvNumberformatScan::Symbol_Division(const String& rString)
  812. {
  813. nCurrPos = STRING_NOTFOUND;
  814. // Ist Waehrung im Spiel?
  815. String sString = pFormatter->GetCharClass()->uppercase(rString);
  816. xub_StrLen nCPos = 0;
  817. while (nCPos != STRING_NOTFOUND)
  818. {
  819. nCPos = sString.Search(GetCurString(),nCPos);
  820. if (nCPos != STRING_NOTFOUND)
  821. {
  822. // in Quotes?
  823. xub_StrLen nQ = SvNumberformat::GetQuoteEnd( sString, nCPos );
  824. if ( nQ == STRING_NOTFOUND )
  825. {
  826. sal_Unicode c;
  827. if ( nCPos == 0 ||
  828. ((c = sString.GetChar(xub_StrLen(nCPos-1))) != '"'
  829. && c != '\\') ) // dm kann durch "dm
  830. { // \d geschuetzt werden
  831. nCurrPos = nCPos;
  832. nCPos = STRING_NOTFOUND; // Abbruch
  833. }
  834. else
  835. nCPos++; // weitersuchen
  836. }
  837. else
  838. nCPos = nQ + 1; // weitersuchen
  839. }
  840. }
  841. nAnzStrings = 0;
  842. BOOL bStar = FALSE; // wird bei '*'Detektion gesetzt
  843. Reset();
  844. xub_StrLen nPos = 0;
  845. const xub_StrLen nLen = rString.Len();
  846. while (nPos < nLen && nAnzStrings < NF_MAX_FORMAT_SYMBOLS)
  847. {
  848. nTypeArray[nAnzStrings] = Next_Symbol(rString, nPos, sStrArray[nAnzStrings]);
  849. if (nTypeArray[nAnzStrings] == NF_SYMBOLTYPE_STAR)
  850. { // Ueberwachung des '*'
  851. if (bStar)
  852. return nPos; // Fehler: doppelter '*'
  853. else
  854. bStar = TRUE;
  855. }
  856. nAnzStrings++;
  857. }
  858. return 0; // 0 => ok
  859. }
  860. void ImpSvNumberformatScan::SkipStrings(USHORT& i, xub_StrLen& nPos)
  861. {
  862. while (i < nAnzStrings && ( nTypeArray[i] == NF_SYMBOLTYPE_STRING
  863. || nTypeArray[i] == NF_SYMBOLTYPE_BLANK
  864. || nTypeArray[i] == NF_SYMBOLTYPE_STAR) )
  865. {
  866. nPos = nPos + sStrArray[i].Len();
  867. i++;
  868. }
  869. }
  870. USHORT ImpSvNumberformatScan::PreviousKeyword(USHORT i)
  871. {
  872. short res = 0;
  873. if (i > 0 && i < nAnzStrings)
  874. {
  875. i--;
  876. while (i > 0 && nTypeArray[i] <= 0)
  877. i--;
  878. if (nTypeArray[i] > 0)
  879. res = nTypeArray[i];
  880. }
  881. return res;
  882. }
  883. USHORT ImpSvNumberformatScan::NextKeyword(USHORT i)
  884. {
  885. short res = 0;
  886. if (i < nAnzStrings-1)
  887. {
  888. i++;
  889. while (i < nAnzStrings-1 && nTypeArray[i] <= 0)
  890. i++;
  891. if (nTypeArray[i] > 0)
  892. res = nTypeArray[i];
  893. }
  894. return res;
  895. }
  896. short ImpSvNumberformatScan::PreviousType( USHORT i )
  897. {
  898. if ( i > 0 && i < nAnzStrings )
  899. {
  900. do
  901. {
  902. i--;
  903. } while ( i > 0 && nTypeArray[i] == NF_SYMBOLTYPE_EMPTY );
  904. return nTypeArray[i];
  905. }
  906. return 0;
  907. }
  908. sal_Unicode ImpSvNumberformatScan::PreviousChar(USHORT i)
  909. {
  910. sal_Unicode res = ' ';
  911. if (i > 0 && i < nAnzStrings)
  912. {
  913. i--;
  914. while (i > 0 && ( nTypeArray[i] == NF_SYMBOLTYPE_EMPTY
  915. || nTypeArray[i] == NF_SYMBOLTYPE_STRING
  916. || nTypeArray[i] == NF_SYMBOLTYPE_STAR
  917. || nTypeArray[i] == NF_SYMBOLTYPE_BLANK ) )
  918. i--;
  919. if (sStrArray[i].Len() > 0)
  920. res = sStrArray[i].GetChar(xub_StrLen(sStrArray[i].Len()-1));
  921. }
  922. return res;
  923. }
  924. sal_Unicode ImpSvNumberformatScan::NextChar(USHORT i)
  925. {
  926. sal_Unicode res = ' ';
  927. if (i < nAnzStrings-1)
  928. {
  929. i++;
  930. while (i < nAnzStrings-1 &&
  931. ( nTypeArray[i] == NF_SYMBOLTYPE_EMPTY
  932. || nTypeArray[i] == NF_SYMBOLTYPE_STRING
  933. || nTypeArray[i] == NF_SYMBOLTYPE_STAR
  934. || nTypeArray[i] == NF_SYMBOLTYPE_BLANK))
  935. i++;
  936. if (sStrArray[i].Len() > 0)
  937. res = sStrArray[i].GetChar(0);
  938. }
  939. return res;
  940. }
  941. BOOL ImpSvNumberformatScan::IsLastBlankBeforeFrac(USHORT i)
  942. {
  943. BOOL res = TRUE;
  944. if (i < nAnzStrings-1)
  945. {
  946. BOOL bStop = FALSE;
  947. i++;
  948. while (i < nAnzStrings-1 && !bStop)
  949. {
  950. i++;
  951. if ( nTypeArray[i] == NF_SYMBOLTYPE_DEL &&
  952. sStrArray[i].GetChar(0) == '/')
  953. bStop = TRUE;
  954. else if ( nTypeArray[i] == NF_SYMBOLTYPE_DEL &&
  955. sStrArray[i].GetChar(0) == ' ')
  956. res = FALSE;
  957. }
  958. if (!bStop) // kein '/'
  959. res = FALSE;
  960. }
  961. else
  962. res = FALSE; // kein '/' mehr
  963. return res;
  964. }
  965. void ImpSvNumberformatScan::Reset()
  966. {
  967. nAnzStrings = 0;
  968. nAnzResStrings = 0;
  969. eScannedType = NUMBERFORMAT_UNDEFINED;
  970. nRepPos = 0;
  971. bExp = FALSE;
  972. bThousand = FALSE;
  973. nThousand = 0;
  974. bDecSep = FALSE;
  975. nDecPos = -1;
  976. nExpPos = (USHORT) -1;
  977. nBlankPos = (USHORT) -1;
  978. nCntPre = 0;
  979. nCntPost = 0;
  980. nCntExp = 0;
  981. bFrac = FALSE;
  982. bBlank = FALSE;
  983. nNatNumModifier = 0;
  984. }
  985. BOOL ImpSvNumberformatScan::Is100SecZero( USHORT i, BOOL bHadDecSep )
  986. {
  987. USHORT nIndexPre = PreviousKeyword( i );
  988. return (nIndexPre == NF_KEY_S || nIndexPre == NF_KEY_SS)
  989. && (bHadDecSep // S, SS ','
  990. || (i>0 && nTypeArray[i-1] == NF_SYMBOLTYPE_STRING));
  991. // SS"any"00 take "any" as a valid decimal separator
  992. }
  993. xub_StrLen ImpSvNumberformatScan::ScanType(const String&)
  994. {
  995. const LocaleDataWrapper* pLoc = pFormatter->GetLocaleData();
  996. xub_StrLen nPos = 0;
  997. USHORT i = 0;
  998. short eNewType;
  999. BOOL bMatchBracket = FALSE;
  1000. SkipStrings(i, nPos);
  1001. while (i < nAnzStrings)
  1002. {
  1003. if (nTypeArray[i] > 0)
  1004. { // keyword
  1005. switch (nTypeArray[i])
  1006. {
  1007. case NF_KEY_E: // E
  1008. eNewType = NUMBERFORMAT_SCIENTIFIC;
  1009. break;
  1010. case NF_KEY_AMPM: // AM,A,PM,P
  1011. case NF_KEY_AP:
  1012. case NF_KEY_H: // H
  1013. case NF_KEY_HH: // HH
  1014. case NF_KEY_S: // S
  1015. case NF_KEY_SS: // SS
  1016. eNewType = NUMBERFORMAT_TIME;
  1017. break;
  1018. case NF_KEY_M: // M
  1019. case NF_KEY_MM: // MM
  1020. { // minute or month
  1021. USHORT nIndexPre = PreviousKeyword(i);
  1022. USHORT nIndexNex = NextKeyword(i);
  1023. sal_Unicode cChar = PreviousChar(i);
  1024. if (nIndexPre == NF_KEY_H || // H
  1025. nIndexPre == NF_KEY_HH || // HH
  1026. nIndexNex == NF_KEY_S || // S
  1027. nIndexNex == NF_KEY_SS || // SS
  1028. cChar == '[' ) // [M
  1029. {
  1030. eNewType = NUMBERFORMAT_TIME;
  1031. nTypeArray[i] -= 2; // 6 -> 4, 7 -> 5
  1032. }
  1033. else
  1034. eNewType = NUMBERFORMAT_DATE;
  1035. }
  1036. break;
  1037. case NF_KEY_MMM: // MMM
  1038. case NF_KEY_MMMM: // MMMM
  1039. case NF_KEY_MMMMM: // MMMMM
  1040. case NF_KEY_Q: // Q
  1041. case NF_KEY_QQ: // QQ
  1042. case NF_KEY_D: // D
  1043. case NF_KEY_DD: // DD
  1044. case NF_KEY_DDD: // DDD
  1045. case NF_KEY_DDDD: // DDDD
  1046. case NF_KEY_YY: // YY
  1047. case NF_KEY_YYYY: // YYYY
  1048. case NF_KEY_NN: // NN
  1049. case NF_KEY_NNN: // NNN
  1050. case NF_KEY_NNNN: // NNNN
  1051. case NF_KEY_WW : // WW
  1052. case NF_KEY_AAA : // AAA
  1053. case NF_KEY_AAAA : // AAAA
  1054. case NF_KEY_EC : // E
  1055. case NF_KEY_EEC : // EE
  1056. case NF_KEY_G : // G
  1057. case NF_KEY_GG : // GG
  1058. case NF_KEY_GGG : // GGG
  1059. case NF_KEY_R : // R
  1060. case NF_KEY_RR : // RR
  1061. eNewType = NUMBERFORMAT_DATE;
  1062. break;
  1063. case NF_KEY_CCC: // CCC
  1064. eNewType = NUMBERFORMAT_CURRENCY;
  1065. break;
  1066. case NF_KEY_GENERAL: // Standard
  1067. eNewType = NUMBERFORMAT_NUMBER;
  1068. break;
  1069. default:
  1070. eNewType = NUMBERFORMAT_UNDEFINED;
  1071. break;
  1072. }
  1073. }
  1074. else
  1075. { // control character
  1076. switch ( sStrArray[i].GetChar(0) )
  1077. {
  1078. case '#':
  1079. case '?':
  1080. eNewType = NUMBERFORMAT_NUMBER;
  1081. break;
  1082. case '0':
  1083. {
  1084. if ( (eScannedType & NUMBERFORMAT_TIME) == NUMBERFORMAT_TIME )
  1085. {
  1086. if ( Is100SecZero( i, bDecSep ) )
  1087. {
  1088. bDecSep = TRUE; // subsequent 0's
  1089. eNewType = NUMBERFORMAT_TIME;
  1090. }
  1091. else
  1092. return nPos; // Error
  1093. }
  1094. else
  1095. eNewType = NUMBERFORMAT_NUMBER;
  1096. }
  1097. break;
  1098. case '%':
  1099. eNewType = NUMBERFORMAT_PERCENT;
  1100. break;
  1101. case '/':
  1102. eNewType = NUMBERFORMAT_FRACTION;
  1103. break;
  1104. case '[':
  1105. {
  1106. if ( i < nAnzStrings-1 &&
  1107. nTypeArray[i+1] == NF_SYMBOLTYPE_STRING &&
  1108. sStrArray[i+1].GetChar(0) == '$' )
  1109. { // as of SV_NUMBERFORMATTER_VERSION_NEW_CURR
  1110. eNewType = NUMBERFORMAT_CURRENCY;
  1111. bMatchBracket = TRUE;
  1112. }
  1113. else if ( i < nAnzStrings-1 &&
  1114. nTypeArray[i+1] == NF_SYMBOLTYPE_STRING &&
  1115. sStrArray[i+1].GetChar(0) == '~' )
  1116. { // as of SV_NUMBERFORMATTER_VERSION_CALENDAR
  1117. eNewType = NUMBERFORMAT_DATE;
  1118. bMatchBracket = TRUE;
  1119. }
  1120. else
  1121. {
  1122. USHORT nIndexNex = NextKeyword(i);
  1123. if (nIndexNex == NF_KEY_H || // H

Large files files are truncated, but you can click here to view the full file