1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
19 #ifndef INCLUDED_SVL_ZFORMAT_HXX
20 #define INCLUDED_SVL_ZFORMAT_HXX
22 #include <svl/svldllapi.h>
23 #include <svl/zforlist.hxx>
24 #include <svl/nfkeytab.hxx>
28 class DigitGroupingIterator
;
31 namespace com
{ namespace sun
{ namespace star
{ namespace i18n
{ struct NativeNumberXmlAttributes2
; } } } }
35 class ImpSvNumberformatScan
; // format code string scanner
36 class ImpSvNumberInputScan
; // input string scanner
38 enum SvNumberformatLimitOps
40 NUMBERFORMAT_OP_NO
= 0, // Undefined, no OP
41 NUMBERFORMAT_OP_EQ
= 1, // Operator =
42 NUMBERFORMAT_OP_NE
= 2, // Operator <>
43 NUMBERFORMAT_OP_LT
= 3, // Operator <
44 NUMBERFORMAT_OP_LE
= 4, // Operator <=
45 NUMBERFORMAT_OP_GT
= 5, // Operator >
46 NUMBERFORMAT_OP_GE
= 6 // Operator >=
49 struct ImpSvNumberformatInfo
// Struct for FormatInfo
51 std::vector
<OUString
> sStrArray
; // Array of symbols
52 std::vector
<short> nTypeArray
; // Array of infos
53 sal_uInt16 nThousand
; // Count of group separator sequences
54 sal_uInt16 nCntPre
; // Count of digits before decimal point
55 sal_uInt16 nCntPost
; // Count of digits after decimal point
56 sal_uInt16 nCntExp
; // Count of exponent digits, or AM/PM
57 SvNumFormatType eScannedType
; // Type determined by scan
58 bool bThousand
; // Has group (AKA thousand) separator
60 void Copy( const ImpSvNumberformatInfo
& rNumFor
, sal_uInt16 nCount
);
63 // NativeNumber, represent numbers using CJK or other digits if nNum>0,
64 // eLang specifies the Locale to use.
67 OUString sParams
; // For [NatNum12 ordinal-number]-like syntax
70 bool bDBNum
:1; // DBNum, to be converted to NatNum
71 bool bDate
:1; // Used in date? (needed for DBNum/NatNum mapping)
72 bool bSet
:1; // If set, since NatNum0 is possible
76 static sal_uInt8
MapDBNumToNatNum( sal_uInt8 nDBNum
, LanguageType eLang
, bool bDate
);
77 static sal_uInt8
MapNatNumToDBNum( sal_uInt8 nNatNum
, LanguageType eLang
, bool bDate
);
79 SvNumberNatNum() : eLang( LANGUAGE_DONTKNOW
), nNum(0),
80 bDBNum(false), bDate(false), bSet(false) {}
81 bool IsComplete() const { return bSet
&& eLang
!= LANGUAGE_DONTKNOW
; }
82 sal_uInt8
GetNatNum() const { return bDBNum
? MapDBNumToNatNum( nNum
, eLang
, bDate
) : nNum
; }
83 sal_uInt8
GetDBNum() const { return bDBNum
? nNum
: MapNatNumToDBNum( nNum
, eLang
, bDate
); }
84 LanguageType
GetLang() const { return eLang
; }
85 void SetLang( LanguageType e
) { eLang
= e
; }
86 void SetNum( sal_uInt8 nNumber
, bool bDBNumber
)
92 bool IsSet() const { return bSet
; }
93 void SetDate( bool bDateP
) { bDate
= bDateP
; }
94 void SetParams(const OUString
& s
) { sParams
= s
; }
95 OUString
const & GetParams() const { return sParams
; }
100 class ImpSvNumFor
// One of four subformats of the format code string
103 ImpSvNumFor(); // Ctor without filling the Info
106 void Enlarge(sal_uInt16 nCount
); // Init of arrays to the right size
108 // if pSc is set, it is used to get the Color pointer
109 void Copy( const ImpSvNumFor
& rNumFor
, ImpSvNumberformatScan
* pSc
);
111 // Access to Info; call Enlarge before!
112 ImpSvNumberformatInfo
& Info() { return aI
;}
113 const ImpSvNumberformatInfo
& Info() const { return aI
; }
115 // Get count of substrings (symbols)
116 sal_uInt16
GetCount() const { return nStringsCnt
;}
118 Color
* GetColor() const { return pColor
; }
119 void SetColor( Color
* pCol
, OUString
const & rName
)
120 { pColor
= pCol
; sColorName
= rName
; }
121 const OUString
& GetColorName() const { return sColorName
; }
123 // new SYMBOLTYPE_CURRENCY in subformat?
124 bool HasNewCurrency() const;
125 bool GetNewCurrencySymbol( OUString
& rSymbol
, OUString
& rExtension
) const;
127 // [NatNum1], [NatNum2], ...
128 void SetNatNumNum( sal_uInt8 nNum
, bool bDBNum
) { aNatNum
.SetNum( nNum
, bDBNum
); }
129 void SetNatNumLang( LanguageType eLang
) { aNatNum
.SetLang( eLang
); }
130 void SetNatNumDate( bool bDate
) { aNatNum
.SetDate( bDate
); }
131 void SetNatNumParams(const OUString
& sParams
) { aNatNum
.SetParams(sParams
); }
132 const SvNumberNatNum
& GetNatNum() const { return aNatNum
; }
135 ImpSvNumberformatInfo aI
; // helper struct for remaining information
136 OUString sColorName
; // color name
137 Color
* pColor
; // pointer to color of subformat
138 sal_uInt16 nStringsCnt
; // count of symbols
139 SvNumberNatNum aNatNum
; // DoubleByteNumber
143 class SVL_DLLPUBLIC SvNumberformat
147 enum class Substitute
: sal_uInt8
154 LanguageType meLanguage
;
155 LanguageType meLanguageWithoutLocaleData
;
156 Substitute meSubstitute
;
157 sal_uInt8 mnNumeralShape
;
158 sal_uInt8 mnCalendarType
;
160 OUString
generateCode() const;
163 LocaleType(sal_uInt32 nRawCode
);
165 bool isPlainLocale() const;
170 SvNumberformat( OUString
& rString
,
171 ImpSvNumberformatScan
* pSc
,
172 ImpSvNumberInputScan
* pISc
,
173 sal_Int32
& nCheckPos
,
174 LanguageType
& eLan
);
177 SvNumberformat( SvNumberformat
const & rFormat
);
179 // Copy ctor with exchange of format code string scanner (used in merge)
180 SvNumberformat( SvNumberformat
const & rFormat
, ImpSvNumberformatScan
& rSc
);
184 /// Get type of format, may include css::util::NumberFormat::DEFINED bit
185 SvNumFormatType
GetType() const { return eType
; }
187 /// Get type of format, does not include css::util::NumberFormat::DEFINED
188 SvNumFormatType
GetMaskedType() const { return eType
& ~SvNumFormatType::DEFINED
; }
190 void SetType(SvNumFormatType eSetType
) { eType
= eSetType
; }
191 // Standard means the I18N defined standard format of this type
192 void SetStandard() { bStandard
= true; }
193 bool IsStandard() const { return bStandard
; }
195 // If this format is an additional built-in format defined by i18n.
196 void SetAdditionalBuiltin() { bAdditionalBuiltin
= true; }
197 bool IsAdditionalBuiltin() const { return bAdditionalBuiltin
; }
199 LanguageType
GetLanguage() const { return maLocale
.meLanguage
;}
201 /** If the format is a placeholder and needs to be substituted. */
202 bool IsSubstituted() const
204 return maLocale
.meSubstitute
!= LocaleType::Substitute::NONE
;
207 /** If the format is a placeholder for the system time format and needs to
208 be substituted during formatting time.
210 bool IsSystemTimeFormat() const
212 return maLocale
.meSubstitute
== LocaleType::Substitute::TIME
&& maLocale
.meLanguage
== LANGUAGE_SYSTEM
;
215 /** If the format is a placeholder for the system long date format and needs
216 to be substituted during formatting time.
218 bool IsSystemLongDateFormat() const
220 return maLocale
.meSubstitute
== LocaleType::Substitute::LONGDATE
&& maLocale
.meLanguage
== LANGUAGE_SYSTEM
;
223 /** If the format is a MM:SS or [MM]:SS format, or MM:[SS] (sic!) or even
224 MM:SS.00 or [MM]:SS.00 or MM:[SS].00
226 bool IsMinuteSecondFormat() const;
228 const OUString
& GetFormatstring() const { return sFormatstring
; }
230 // Build a format string of application defined keywords
231 OUString
GetMappedFormatstring( const NfKeywordTable
& rKeywords
,
232 const LocaleDataWrapper
& rLoc
,
233 LanguageType nOriginalLang
= LANGUAGE_DONTKNOW
,
234 bool bSystemLanguage
= false ) const;
236 void SetStarFormatSupport( bool b
) { bStarFlag
= b
; }
239 * Get output string from a numeric value that fits the number of
240 * characters specified.
242 bool GetOutputString( double fNumber
, sal_uInt16 nCharCount
, OUString
& rOutString
) const;
244 bool GetOutputString( double fNumber
, OUString
& OutString
, Color
** ppColor
);
245 void GetOutputString( const OUString
& sString
, OUString
& OutString
, Color
** ppColor
);
248 bool IsTextFormat() const { return bool(eType
& SvNumFormatType::TEXT
); }
249 // True if 4th subformat present
250 bool HasTextFormat() const
252 return (NumFor
[3].GetCount() > 0) ||
253 (NumFor
[3].Info().eScannedType
== SvNumFormatType::TEXT
);
256 void GetFormatSpecialInfo(bool& bThousand
,
258 sal_uInt16
& nPrecision
,
259 sal_uInt16
& nLeadingCnt
) const;
261 /// Get index of subformat (0..3) according to conditions and fNumber value
262 sal_uInt16
GetSubformatIndex( double fNumber
) const;
264 /// Count of decimal precision
265 sal_uInt16
GetFormatPrecision( sal_uInt16 nIx
= 0 ) const
266 { return NumFor
[nIx
].Info().nCntPost
; }
268 /// Count of integer digits
269 sal_uInt16
GetFormatIntegerDigits( sal_uInt16 nIx
= 0 ) const
270 { return NumFor
[nIx
].Info().nCntPre
; }
272 /** Count of hidden integer digits with thousands divisor:
273 * formats like "0," to show only thousands
275 sal_uInt16
GetThousandDivisorPrecision( sal_uInt16 nIx
= 0 ) const
276 { return NumFor
[nIx
].Info().nThousand
* 3; }
278 //! Read/write access on a special sal_uInt16 component, may only be used on the
279 //! standard format 0, 10000, ... and only by the number formatter!
280 struct FormatterPrivateAccess
{ friend SvNumberFormatter
; private: FormatterPrivateAccess() {} };
281 sal_uInt16
GetLastInsertKey( const FormatterPrivateAccess
& ) const
282 { return NumFor
[0].Info().nThousand
; }
283 void SetLastInsertKey( sal_uInt16 nKey
, const FormatterPrivateAccess
& )
284 { NumFor
[0].Info().nThousand
= nKey
; }
286 //! Only onLoad: convert from stored to current system language/country
287 void ConvertLanguage( SvNumberFormatter
& rConverter
,
288 LanguageType eConvertFrom
, LanguageType eConvertTo
);
290 // Substring of a subformat code nNumFor (0..3)
291 // nPos == 0xFFFF => last substring
292 // bString==true: first/last SYMBOLTYPE_STRING or SYMBOLTYPE_CURRENCY
293 const OUString
* GetNumForString( sal_uInt16 nNumFor
, sal_uInt16 nPos
,
294 bool bString
= false ) const;
296 // Subtype of a subformat code nNumFor (0..3)
297 // nPos == 0xFFFF => last substring
298 short GetNumForType( sal_uInt16 nNumFor
, sal_uInt16 nPos
) const;
300 OUString
GetDenominatorString( sal_uInt16 nNumFor
) const;
301 OUString
GetNumeratorString( sal_uInt16 nNumFor
) const;
302 OUString
GetIntegerFractionDelimiterString( sal_uInt16 nNumFor
) const;
303 /// Round fNumber to its fraction representation
304 double GetRoundFractionValue ( double fNumber
) const;
306 /** If the count of string elements (substrings, ignoring [modifiers] and
307 so on) in a subformat code nNumFor (0..3) is equal to the given number.
308 Used by ImpSvNumberInputScan::IsNumberFormatMain() to detect a matched
310 bool IsNumForStringElementCountEqual( sal_uInt16 nNumFor
, sal_uInt16 nAllCount
,
311 sal_uInt16 nNumCount
) const
315 // First try a simple approach. Note that this is called only
316 // if all MidStrings did match so far, to verify that all
317 // strings of the format were matched and not just the starting
318 // sequence, so we don't have to check if GetCount() includes
319 // [modifiers] or anything else if both counts are equal.
320 sal_uInt16 nCnt
= NumFor
[nNumFor
].GetCount();
321 if ( nAllCount
== nCnt
)
323 if ( nAllCount
< nCnt
) // check ignoring [modifiers] and so on
324 return ImpGetNumForStringElementCount( nNumFor
) ==
325 (nAllCount
- nNumCount
);
329 /** Get the count of numbers among string elements **/
330 sal_uInt16
GetNumForNumberElementCount( sal_uInt16 nNumFor
) const;
332 /** Get the scanned type of the specified subformat. */
333 SvNumFormatType
GetNumForInfoScannedType( sal_uInt16 nNumFor
) const
335 return (nNumFor
< 4) ? NumFor
[nNumFor
].Info().eScannedType
: SvNumFormatType::UNDEFINED
;
338 // Whether the second subformat code is really for negative numbers
339 // or another limit set.
340 bool IsSecondSubformatRealNegative() const
342 return fLimit1
== 0.0 && fLimit2
== 0.0 &&
343 ( (eOp1
== NUMBERFORMAT_OP_GE
&& eOp2
== NUMBERFORMAT_OP_NO
) ||
344 (eOp1
== NUMBERFORMAT_OP_GT
&& eOp2
== NUMBERFORMAT_OP_LT
) ||
345 (eOp1
== NUMBERFORMAT_OP_NO
&& eOp2
== NUMBERFORMAT_OP_NO
) );
348 // Whether the first subformat code is really for negative numbers
349 // or another limit set.
350 bool IsFirstSubformatRealNegative() const
352 return fLimit1
== 0.0 && fLimit2
== 0.0 &&
353 ((eOp1
== NUMBERFORMAT_OP_LT
&&
354 (eOp2
== NUMBERFORMAT_OP_GT
|| eOp2
== NUMBERFORMAT_OP_EQ
||
355 eOp2
== NUMBERFORMAT_OP_GE
|| eOp2
== NUMBERFORMAT_OP_NO
)) ||
356 (eOp1
== NUMBERFORMAT_OP_LE
&&
357 (eOp2
== NUMBERFORMAT_OP_NO
|| eOp2
== NUMBERFORMAT_OP_GT
)));
360 // Whether the negative format is without a sign or not
361 bool IsNegativeWithoutSign() const;
363 bool IsNegativeInBracket() const;
365 bool HasPositiveBracketPlaceholder() const;
367 // Whether a new SYMBOLTYPE_CURRENCY is contained in the format
368 bool HasNewCurrency() const;
370 // strip [$-yyy] from all [$xxx-yyy] leaving only xxx's,
371 static OUString
StripNewCurrencyDelimiters( const OUString
& rStr
);
373 // If a new SYMBOLTYPE_CURRENCY is contained if the format is of type
374 // css::util::NumberFormat::CURRENCY, and if so the symbol xxx and the extension nnn
375 // of [$xxx-nnn] are returned
376 bool GetNewCurrencySymbol( OUString
& rSymbol
, OUString
& rExtension
) const;
378 static bool HasStringNegativeSign( const OUString
& rStr
);
381 Whether a character at position nPos is somewhere between two matching
383 If nPos points to a cQuote, a true is returned on an opening cQuote,
384 a false is returned on a closing cQuote.
385 A cQuote between quotes may be escaped by a cEscIn, a cQuote outside of
386 quotes may be escaped by a cEscOut.
387 The default '\0' results in no escapement possible.
388 Defaults are set right according to the "unlogic" of the Numberformatter
390 static bool IsInQuote( const OUString
& rString
, sal_Int32 nPos
,
391 sal_Unicode cQuote
= '"',
392 sal_Unicode cEscIn
= '\0', sal_Unicode cEscOut
= '\\' );
395 Return the position of a matching closing cQuote if the character at
396 position nPos is between two matching cQuote, otherwise return -1.
397 If nPos points to an opening cQuote the position of the matching
398 closing cQuote is returned.
399 If nPos points to a closing cQuote nPos is returned.
400 If nPos points into a part which starts with an opening cQuote but has
401 no closing cQuote, rString.Len() is returned.
402 Uses <method>IsInQuote</method> internally, so you don't have to call
403 that prior to a call of this method.
405 static sal_Int32
GetQuoteEnd( const OUString
& rString
, sal_Int32 nPos
,
406 sal_Unicode cQuote
= '"',
407 sal_Unicode cEscIn
= '\0' );
409 void SetComment( const OUString
& rStr
)
411 const OUString
& GetComment() const { return sComment
; }
413 /** Insert the number of blanks into the string that is needed to simulate
414 the width of character c for underscore formats */
415 static sal_Int32
InsertBlanks( OUString
& r
, sal_Int32 nPos
, sal_Unicode c
)
418 OUStringBuffer
sBuff(r
);
420 result
= InsertBlanks(sBuff
, nPos
, c
);
421 r
= sBuff
.makeStringAndClear();
426 /** Insert the number of blanks into the string that is needed to simulate
427 the width of character c for underscore formats */
428 static sal_Int32
InsertBlanks( OUStringBuffer
& r
, sal_Int32 nPos
, sal_Unicode c
);
430 /// One of YMD,DMY,MDY if date format
431 DateOrder
GetDateOrder() const;
433 /** A coded value of the exact YMD combination used, if date format.
434 For example: YYYY-MM-DD => ('Y' << 16) | ('M' << 8) | 'D'
435 or: MM/YY => ('M' << 8) | 'Y' */
436 sal_uInt32
GetExactDateOrder() const;
438 // used in XML export
439 void GetConditions( SvNumberformatLimitOps
& rOper1
, double& rVal1
,
440 SvNumberformatLimitOps
& rOper2
, double& rVal2
) const;
441 Color
* GetColor( sal_uInt16 nNumFor
) const;
442 void GetNumForInfo( sal_uInt16 nNumFor
, SvNumFormatType
& rScannedType
,
443 bool& bThousand
, sal_uInt16
& nPrecision
, sal_uInt16
& nLeadingCnt
) const;
445 // rAttr.Number not empty if NatNum attributes are to be stored
447 css::i18n::NativeNumberXmlAttributes2
& rAttr
,
448 sal_uInt16 nNumFor
) const;
450 /** Switches to the first non-"gregorian" calendar, but only if the current
451 calendar is "gregorian"; original calendar name and date/time returned,
452 but only if calendar switched and rOrgCalendar was empty. */
453 void SwitchToOtherCalendar( OUString
& rOrgCalendar
, double& fOrgDateTime
) const;
455 /** Switches to the "gregorian" calendar, but only if the current calendar
456 is non-"gregorian" and rOrgCalendar is not empty. Thus a preceding
457 ImpSwitchToOtherCalendar() call should have been placed prior to
458 calling this method. */
459 void SwitchToGregorianCalendar( const OUString
& rOrgCalendar
, double fOrgDateTime
) const;
462 /** Switches to the first specified calendar, if any, in subformat nNumFor
463 (0..3). Original calendar name and date/time returned, but only if
464 calendar switched and rOrgCalendar was empty.
467 <TRUE/> if a calendar was specified and switched to,
470 bool SwitchToSpecifiedCalendar( OUString
& rOrgCalendar
, double& fOrgDateTime
,
471 sal_uInt16 nNumFor
) const
474 return ImpSwitchToSpecifiedCalendar( rOrgCalendar
,
475 fOrgDateTime
, NumFor
[nNumFor
] );
480 /// Whether it's a (YY)YY-M(M)-D(D) format.
481 bool IsIso8601( sal_uInt16 nNumFor
) const
484 return ImpIsIso8601( NumFor
[nNumFor
]);
489 ImpSvNumFor NumFor
[4]; // Array for the 4 subformats
490 OUString sFormatstring
; // The format code string
491 OUString sComment
; // Comment, since number formatter version 6
492 double fLimit1
; // Value for first condition
493 double fLimit2
; // Value for second condition
494 ImpSvNumberformatScan
& rScan
; // Format code scanner
495 LocaleType maLocale
; // Language/country of the format, numeral shape and calendar type from Excel.
496 SvNumberformatLimitOps eOp1
; // Operator for first condition
497 SvNumberformatLimitOps eOp2
; // Operator for second condition
498 SvNumFormatType eType
; // Type of format
499 bool bAdditionalBuiltin
; // If this is an additional built-in format defined by i18n
500 bool bStarFlag
; // Take *n format as ESC n
501 bool bStandard
; // If this is a default standard format
502 bool bIsUsed
; // Flag as used for storing
504 SVL_DLLPRIVATE sal_uInt16
ImpGetNumForStringElementCount( sal_uInt16 nNumFor
) const;
506 SVL_DLLPRIVATE
bool ImpIsOtherCalendar( const ImpSvNumFor
& rNumFor
) const;
509 SVL_DLLPRIVATE
bool ImpSwitchToSpecifiedCalendar( OUString
& rOrgCalendar
,
510 double& fOrgDateTime
,
511 const ImpSvNumFor
& rNumFor
) const;
514 /** Whether to use possessive genitive case month name, or partitive case
515 month name, instead of nominative name (noun).
518 0: execute check <br>
519 set to 1 if nominative case is returned, <br>
520 set to 2 if genitive case is returned, <br>
521 set to 3 if partitive case is returned <br>
522 1: don't execute check, return nominative case <br>
523 2: don't execute check, return genitive case <br>
524 3: don't execute check, return partitive case <br>
527 a NfKeywordIndex, must designate a month type code
529 @returns one of css::i18n::CalendarDisplayCode values
530 according to eCodeType and the check executed (or passed).
532 SVL_DLLPRIVATE
static sal_Int32
ImpUseMonthCase( int & io_nState
, const ImpSvNumFor
& rNumFor
, NfKeywordIndex eCodeType
);
534 /// Whether it's a (YY)YY-M(M)-D(D) format.
535 SVL_DLLPRIVATE
bool ImpIsIso8601( const ImpSvNumFor
& rNumFor
) const;
537 const CharClass
& rChrCls() const;
538 const LocaleDataWrapper
& rLoc() const;
539 CalendarWrapper
& GetCal() const;
540 const SvNumberFormatter
& GetFormatter() const;
542 // divide in substrings and color conditions
543 SVL_DLLPRIVATE
short ImpNextSymbol( OUStringBuffer
& rString
,
545 OUString
& sSymbol
) const;
547 // read string until ']' and strip blanks (after condition)
548 SVL_DLLPRIVATE
static sal_Int32
ImpGetNumber( OUStringBuffer
& rString
,
553 * Parse the content of '[$-xxx] or '[$-xxxxxxxx]' and extract the locale
554 * type from it. Given the string, start parsing at position specified by
555 * nPos, and store the end position with nPos when the parsing is
556 * complete. The nPos should point to the '$' before the parsing, and to
557 * the closing bracket after the parsing. When the content is [$-xxx],
558 * the xxx part represents the language type (aka LCID) in hex numerals.
559 * When the content is [$-xxxxxxxx] the last 4 digits represent the LCID
560 * (again in hex), the next 2 digits represent the calendar type, and the
561 * 2 highest digits (if exists) is the numeral shape.
564 * http://office.microsoft.com/en-us/excel-help/creating-international-number-formats-HA001034635.aspx
566 * @param rString input string
567 * @param nPos position (see above).
569 * @return struct containing numeral shape, calendar type, and LCID that
570 * specifies language type. See i18nlangtag/lang.h for a complete
571 * list of language types. These numbers also correspond with the
572 * numbers used by Microsoft Office.
574 SVL_DLLPRIVATE
static LocaleType
ImpGetLocaleType( const OUString
& rString
, sal_Int32
& nPos
);
576 /** Obtain calendar and numerals from a LocaleType that was parsed from a
577 LCID with ImpGetLocaleType().
579 Inserts a NatNum modifier to rString at nPos if needed as determined
580 from the numeral code.
582 @ATTENTION: may modify <member>maLocale</member> to make it follow
583 aTmpLocale, in which case also nLang is adapted.
585 @returns a string with the calendar if one was determined from the
586 calendar code, else an empty string. The calendar string needs to be
587 inserted at a proper position to rString after all bracketed prefixes.
589 SVL_DLLPRIVATE OUString
ImpObtainCalendarAndNumerals( OUStringBuffer
& rString
,
591 LanguageType
& nLang
,
592 const LocaleType
& aTmpLocale
);
594 // standard number output
595 SVL_DLLPRIVATE
void ImpGetOutputStandard( double& fNumber
, OUString
& OutString
) const;
596 SVL_DLLPRIVATE
void ImpGetOutputStandard( double& fNumber
, OUStringBuffer
& OutString
) const;
597 SVL_DLLPRIVATE
void ImpGetOutputStdToPrecision( double& rNumber
, OUString
& rOutString
, sal_uInt16 nPrecision
) const;
598 // numbers in input line
599 SVL_DLLPRIVATE
void ImpGetOutputInputLine( double fNumber
, OUString
& OutString
) const;
601 // check subcondition
602 // OP undefined => -1
604 SVL_DLLPRIVATE
static short ImpCheckCondition(double fNumber
,
606 SvNumberformatLimitOps eOp
);
608 // Helper function for number strings
609 // append string symbols, insert leading 0 or ' ', or ...
610 SVL_DLLPRIVATE
bool ImpNumberFill( OUStringBuffer
& sStr
,
616 bool bInsertRightBlank
= false );
618 // Helper function to fill in the integer part and the group (AKA thousand) separators
619 SVL_DLLPRIVATE
bool ImpNumberFillWithThousands( OUStringBuffer
& sStr
,
625 bool bAddDecSep
= true );
627 // Helper function to fill in the group (AKA thousand) separators
628 // or to skip additional digits
629 SVL_DLLPRIVATE
void ImpDigitFill( OUStringBuffer
& sStr
,
633 sal_Int32
& nDigitCount
,
634 utl::DigitGroupingIterator
& );
636 SVL_DLLPRIVATE
bool ImpDecimalFill( OUStringBuffer
& sStr
,
643 /** Calculate each element of fraction:
644 * integer part, numerator part, denominator part
645 * @param fNumber value to be represented as fraction. Will contain absolute fractional part
646 * @param nIx subformat number 0..3
647 * @param fIntPart integral part of fraction
648 * @param nFrac numerator of fraction
649 * @param nDic denominator of fraction
651 SVL_DLLPRIVATE
void ImpGetFractionElements( double& fNumber
,
655 sal_uInt64
& nDiv
) const;
656 SVL_DLLPRIVATE
bool ImpGetFractionOutput(double fNumber
,
658 OUStringBuffer
& OutString
);
659 SVL_DLLPRIVATE
bool ImpGetScientificOutput(double fNumber
,
661 OUStringBuffer
& OutString
);
663 SVL_DLLPRIVATE
bool ImpGetDateOutput( double fNumber
,
665 OUStringBuffer
& OutString
);
666 SVL_DLLPRIVATE
bool ImpGetTimeOutput( double fNumber
,
668 OUStringBuffer
& OutString
);
669 SVL_DLLPRIVATE
bool ImpGetDateTimeOutput( double fNumber
,
671 OUStringBuffer
& OutString
);
673 // Switches to the "gregorian" calendar if the current calendar is
674 // non-"gregorian" and the era is a "Dummy" era of a calendar which doesn't
675 // know a "before" era (like zh_TW ROC or ja_JP Gengou). If switched and
676 // rOrgCalendar was "gregorian" the string is emptied. If rOrgCalendar was
677 // empty the previous calendar name and date/time are returned.
678 SVL_DLLPRIVATE
bool ImpFallBackToGregorianCalendar( OUString
& rOrgCalendar
, double& fOrgDateTime
);
680 // Append a "G" short era string of the given calendar. In the case of a
681 // Gengou calendar this is a one character abbreviation, for other
682 // calendars the XExtendedCalendar::getDisplayString() method is called.
683 SVL_DLLPRIVATE
static void ImpAppendEraG( OUStringBuffer
& OutStringBuffer
, const CalendarWrapper
& rCal
,
686 SVL_DLLPRIVATE
bool ImpGetNumberOutput( double fNumber
,
688 OUStringBuffer
& OutString
);
690 SVL_DLLPRIVATE
void ImpCopyNumberformat( const SvNumberformat
& rFormat
);
692 // normal digits or other digits, depending on ImpSvNumFor.aNatNum,
693 // [NatNum1], [NatNum2], ...
694 SVL_DLLPRIVATE OUString
ImpGetNatNumString( const SvNumberNatNum
& rNum
, sal_Int32 nVal
,
695 sal_uInt16 nMinDigits
) const;
697 OUString
ImpIntToString( sal_uInt16 nIx
, sal_Int32 nVal
, sal_uInt16 nMinDigits
= 0 ) const
699 const SvNumberNatNum
& rNum
= NumFor
[nIx
].GetNatNum();
700 if ( nMinDigits
|| rNum
.IsComplete() )
702 return ImpGetNatNumString( rNum
, nVal
, nMinDigits
);
704 return OUString::number(nVal
);
707 // Obtain the string of the fraction of second, without leading "0.",
708 // rounded to nFractionDecimals (or nFractionDecimals+1 if
709 // bAddOneRoundingDecimal==true but then truncated at nFractionDecimals,
710 // for use with the result of tools::Time::GetClock()) with the length of
711 // nFractionDecimals, unless nMinimumInputLineDecimals>0 is given for input
712 // line string where extra trailing "0" are discarded.
713 SVL_DLLPRIVATE sal_uInt16
ImpGetFractionOfSecondString( OUStringBuffer
& rBuf
, double fFractionOfSecond
,
714 int nFractionDecimals
, bool bAddOneRoundingDecimal
, sal_uInt16 nIx
, sal_uInt16 nMinimumInputLineDecimals
);
716 // transliterate according to NativeNumber
717 SVL_DLLPRIVATE OUString
impTransliterateImpl(const OUString
& rStr
, const SvNumberNatNum
& rNum
) const;
718 SVL_DLLPRIVATE
void impTransliterateImpl(OUStringBuffer
& rStr
, const SvNumberNatNum
& rNum
) const;
719 SVL_DLLPRIVATE OUString
impTransliterateImpl(const OUString
& rStr
, const SvNumberNatNum
& rNum
, sal_uInt16 nDateKey
) const;
721 OUString
impTransliterate(const OUString
& rStr
, const SvNumberNatNum
& rNum
) const
723 return rNum
.IsComplete() ? impTransliterateImpl(rStr
, rNum
) : rStr
;
726 SVL_DLLPRIVATE
void impTransliterate(OUStringBuffer
& rStr
, const SvNumberNatNum
& rNum
) const
728 if(rNum
.IsComplete())
730 impTransliterateImpl(rStr
, rNum
);
734 OUString
impTransliterate(const OUString
& rStr
, const SvNumberNatNum
& rNum
, sal_uInt16 nDateKey
) const
736 return rNum
.IsComplete() ? impTransliterateImpl(rStr
, rNum
, nDateKey
) : rStr
;
741 #endif // INCLUDED_SVL_ZFORMAT_HXX
743 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */