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 const OUString
& GetFormatstring() const { return sFormatstring
; }
225 // Build a format string of application defined keywords
226 OUString
GetMappedFormatstring( const NfKeywordTable
& rKeywords
,
227 const LocaleDataWrapper
& rLoc
,
228 LanguageType nOriginalLang
= LANGUAGE_DONTKNOW
,
229 bool bSystemLanguage
= false ) const;
231 void SetStarFormatSupport( bool b
) { bStarFlag
= b
; }
234 * Get output string from a numeric value that fits the number of
235 * characters specified.
237 bool GetOutputString( double fNumber
, sal_uInt16 nCharCount
, OUString
& rOutString
) const;
239 bool GetOutputString( double fNumber
, OUString
& OutString
, Color
** ppColor
);
240 void GetOutputString( const OUString
& sString
, OUString
& OutString
, Color
** ppColor
);
243 bool IsTextFormat() const { return bool(eType
& SvNumFormatType::TEXT
); }
244 // True if 4th subformat present
245 bool HasTextFormat() const
247 return (NumFor
[3].GetCount() > 0) ||
248 (NumFor
[3].Info().eScannedType
== SvNumFormatType::TEXT
);
251 void GetFormatSpecialInfo(bool& bThousand
,
253 sal_uInt16
& nPrecision
,
254 sal_uInt16
& nLeadingCnt
) const;
256 /// Get index of subformat (0..3) according to conditions and fNumber value
257 sal_uInt16
GetSubformatIndex( double fNumber
) const;
259 /// Count of decimal precision
260 sal_uInt16
GetFormatPrecision( sal_uInt16 nIx
= 0 ) const
261 { return NumFor
[nIx
].Info().nCntPost
; }
263 /// Count of integer digits
264 sal_uInt16
GetFormatIntegerDigits( sal_uInt16 nIx
= 0 ) const
265 { return NumFor
[nIx
].Info().nCntPre
; }
267 /** Count of hidden integer digits with thousands divisor:
268 * formats like "0," to show only thousands
270 sal_uInt16
GetThousandDivisorPrecision( sal_uInt16 nIx
= 0 ) const
271 { return NumFor
[nIx
].Info().nThousand
* 3; }
273 //! Read/write access on a special sal_uInt16 component, may only be used on the
274 //! standard format 0, 10000, ... and only by the number formatter!
275 struct FormatterPrivateAccess
{ friend SvNumberFormatter
; private: FormatterPrivateAccess() {} };
276 sal_uInt16
GetLastInsertKey( const FormatterPrivateAccess
& ) const
277 { return NumFor
[0].Info().nThousand
; }
278 void SetLastInsertKey( sal_uInt16 nKey
, const FormatterPrivateAccess
& )
279 { NumFor
[0].Info().nThousand
= nKey
; }
281 //! Only onLoad: convert from stored to current system language/country
282 void ConvertLanguage( SvNumberFormatter
& rConverter
,
283 LanguageType eConvertFrom
, LanguageType eConvertTo
);
285 // Substring of a subformat code nNumFor (0..3)
286 // nPos == 0xFFFF => last substring
287 // bString==true: first/last SYMBOLTYPE_STRING or SYMBOLTYPE_CURRENCY
288 const OUString
* GetNumForString( sal_uInt16 nNumFor
, sal_uInt16 nPos
,
289 bool bString
= false ) const;
291 // Subtype of a subformat code nNumFor (0..3)
292 // nPos == 0xFFFF => last substring
293 short GetNumForType( sal_uInt16 nNumFor
, sal_uInt16 nPos
) const;
295 OUString
GetDenominatorString( sal_uInt16 nNumFor
) const;
296 OUString
GetNumeratorString( sal_uInt16 nNumFor
) const;
297 OUString
GetIntegerFractionDelimiterString( sal_uInt16 nNumFor
) const;
298 /// Round fNumber to its fraction representation
299 double GetRoundFractionValue ( double fNumber
) const;
301 /** If the count of string elements (substrings, ignoring [modifiers] and
302 so on) in a subformat code nNumFor (0..3) is equal to the given number.
303 Used by ImpSvNumberInputScan::IsNumberFormatMain() to detect a matched
305 bool IsNumForStringElementCountEqual( sal_uInt16 nNumFor
, sal_uInt16 nAllCount
,
306 sal_uInt16 nNumCount
) const
310 // First try a simple approach. Note that this is called only
311 // if all MidStrings did match so far, to verify that all
312 // strings of the format were matched and not just the starting
313 // sequence, so we don't have to check if GetCount() includes
314 // [modifiers] or anything else if both counts are equal.
315 sal_uInt16 nCnt
= NumFor
[nNumFor
].GetCount();
316 if ( nAllCount
== nCnt
)
318 if ( nAllCount
< nCnt
) // check ignoring [modifiers] and so on
319 return ImpGetNumForStringElementCount( nNumFor
) ==
320 (nAllCount
- nNumCount
);
324 /** Get the count of numbers among string elements **/
325 sal_uInt16
GetNumForNumberElementCount( sal_uInt16 nNumFor
) const;
327 /** Get the scanned type of the specified subformat. */
328 SvNumFormatType
GetNumForInfoScannedType( sal_uInt16 nNumFor
) const
330 return (nNumFor
< 4) ? NumFor
[nNumFor
].Info().eScannedType
: SvNumFormatType::UNDEFINED
;
333 // Whether the second subformat code is really for negative numbers
334 // or another limit set.
335 bool IsSecondSubformatRealNegative() const
337 return fLimit1
== 0.0 && fLimit2
== 0.0 &&
338 ( (eOp1
== NUMBERFORMAT_OP_GE
&& eOp2
== NUMBERFORMAT_OP_NO
) ||
339 (eOp1
== NUMBERFORMAT_OP_GT
&& eOp2
== NUMBERFORMAT_OP_LT
) ||
340 (eOp1
== NUMBERFORMAT_OP_NO
&& eOp2
== NUMBERFORMAT_OP_NO
) );
343 // Whether the first subformat code is really for negative numbers
344 // or another limit set.
345 bool IsFirstSubformatRealNegative() const
347 return fLimit1
== 0.0 && fLimit2
== 0.0 &&
348 ((eOp1
== NUMBERFORMAT_OP_LT
&&
349 (eOp2
== NUMBERFORMAT_OP_GT
|| eOp2
== NUMBERFORMAT_OP_EQ
||
350 eOp2
== NUMBERFORMAT_OP_GE
|| eOp2
== NUMBERFORMAT_OP_NO
)) ||
351 (eOp1
== NUMBERFORMAT_OP_LE
&&
352 (eOp2
== NUMBERFORMAT_OP_NO
|| eOp2
== NUMBERFORMAT_OP_GT
)));
355 // Whether the negative format is without a sign or not
356 bool IsNegativeWithoutSign() const;
358 bool IsNegativeInBracket() const;
360 bool HasPositiveBracketPlaceholder() const;
362 // Whether a new SYMBOLTYPE_CURRENCY is contained in the format
363 bool HasNewCurrency() const;
365 // strip [$-yyy] from all [$xxx-yyy] leaving only xxx's,
366 static OUString
StripNewCurrencyDelimiters( const OUString
& rStr
);
368 // If a new SYMBOLTYPE_CURRENCY is contained if the format is of type
369 // css::util::NumberFormat::CURRENCY, and if so the symbol xxx and the extension nnn
370 // of [$xxx-nnn] are returned
371 bool GetNewCurrencySymbol( OUString
& rSymbol
, OUString
& rExtension
) const;
373 static bool HasStringNegativeSign( const OUString
& rStr
);
376 Whether a character at position nPos is somewhere between two matching
378 If nPos points to a cQuote, a true is returned on an opening cQuote,
379 a false is returned on a closing cQuote.
380 A cQuote between quotes may be escaped by a cEscIn, a cQuote outside of
381 quotes may be escaped by a cEscOut.
382 The default '\0' results in no escapement possible.
383 Defaults are set right according to the "unlogic" of the Numberformatter
385 static bool IsInQuote( const OUString
& rString
, sal_Int32 nPos
,
386 sal_Unicode cQuote
= '"',
387 sal_Unicode cEscIn
= '\0', sal_Unicode cEscOut
= '\\' );
390 Return the position of a matching closing cQuote if the character at
391 position nPos is between two matching cQuote, otherwise return -1.
392 If nPos points to an opening cQuote the position of the matching
393 closing cQuote is returned.
394 If nPos points to a closing cQuote nPos is returned.
395 If nPos points into a part which starts with an opening cQuote but has
396 no closing cQuote, rString.Len() is returned.
397 Uses <method>IsInQuote</method> internally, so you don't have to call
398 that prior to a call of this method.
400 static sal_Int32
GetQuoteEnd( const OUString
& rString
, sal_Int32 nPos
,
401 sal_Unicode cQuote
= '"',
402 sal_Unicode cEscIn
= '\0' );
404 void SetComment( const OUString
& rStr
)
406 const OUString
& GetComment() const { return sComment
; }
408 /** Insert the number of blanks into the string that is needed to simulate
409 the width of character c for underscore formats */
410 static sal_Int32
InsertBlanks( OUString
& r
, sal_Int32 nPos
, sal_Unicode c
)
413 OUStringBuffer
sBuff(r
);
415 result
= InsertBlanks(sBuff
, nPos
, c
);
416 r
= sBuff
.makeStringAndClear();
421 /** Insert the number of blanks into the string that is needed to simulate
422 the width of character c for underscore formats */
423 static sal_Int32
InsertBlanks( OUStringBuffer
& r
, sal_Int32 nPos
, sal_Unicode c
);
425 /// One of YMD,DMY,MDY if date format
426 DateOrder
GetDateOrder() const;
428 /** A coded value of the exact YMD combination used, if date format.
429 For example: YYYY-MM-DD => ('Y' << 16) | ('M' << 8) | 'D'
430 or: MM/YY => ('M' << 8) | 'Y' */
431 sal_uInt32
GetExactDateOrder() const;
433 // used in XML export
434 void GetConditions( SvNumberformatLimitOps
& rOper1
, double& rVal1
,
435 SvNumberformatLimitOps
& rOper2
, double& rVal2
) const;
436 Color
* GetColor( sal_uInt16 nNumFor
) const;
437 void GetNumForInfo( sal_uInt16 nNumFor
, SvNumFormatType
& rScannedType
,
438 bool& bThousand
, sal_uInt16
& nPrecision
, sal_uInt16
& nLeadingCnt
) const;
440 // rAttr.Number not empty if NatNum attributes are to be stored
442 css::i18n::NativeNumberXmlAttributes2
& rAttr
,
443 sal_uInt16 nNumFor
) const;
445 /** Switches to the first non-"gregorian" calendar, but only if the current
446 calendar is "gregorian"; original calendar name and date/time returned,
447 but only if calendar switched and rOrgCalendar was empty. */
448 void SwitchToOtherCalendar( OUString
& rOrgCalendar
, double& fOrgDateTime
) const;
450 /** Switches to the "gregorian" calendar, but only if the current calendar
451 is non-"gregorian" and rOrgCalendar is not empty. Thus a preceding
452 ImpSwitchToOtherCalendar() call should have been placed prior to
453 calling this method. */
454 void SwitchToGregorianCalendar( const OUString
& rOrgCalendar
, double fOrgDateTime
) const;
457 /** Switches to the first specified calendar, if any, in subformat nNumFor
458 (0..3). Original calendar name and date/time returned, but only if
459 calendar switched and rOrgCalendar was empty.
462 <TRUE/> if a calendar was specified and switched to,
465 bool SwitchToSpecifiedCalendar( OUString
& rOrgCalendar
, double& fOrgDateTime
,
466 sal_uInt16 nNumFor
) const
469 return ImpSwitchToSpecifiedCalendar( rOrgCalendar
,
470 fOrgDateTime
, NumFor
[nNumFor
] );
475 /// Whether it's a (YY)YY-M(M)-D(D) format.
476 bool IsIso8601( sal_uInt16 nNumFor
) const
479 return ImpIsIso8601( NumFor
[nNumFor
]);
484 ImpSvNumFor NumFor
[4]; // Array for the 4 subformats
485 OUString sFormatstring
; // The format code string
486 OUString sComment
; // Comment, since number formatter version 6
487 double fLimit1
; // Value for first condition
488 double fLimit2
; // Value for second condition
489 ImpSvNumberformatScan
& rScan
; // Format code scanner
490 LocaleType maLocale
; // Language/country of the format, numeral shape and calendar type from Excel.
491 SvNumberformatLimitOps eOp1
; // Operator for first condition
492 SvNumberformatLimitOps eOp2
; // Operator for second condition
493 SvNumFormatType eType
; // Type of format
494 bool bAdditionalBuiltin
; // If this is an additional built-in format defined by i18n
495 bool bStarFlag
; // Take *n format as ESC n
496 bool bStandard
; // If this is a default standard format
497 bool bIsUsed
; // Flag as used for storing
499 SVL_DLLPRIVATE sal_uInt16
ImpGetNumForStringElementCount( sal_uInt16 nNumFor
) const;
501 SVL_DLLPRIVATE
bool ImpIsOtherCalendar( const ImpSvNumFor
& rNumFor
) const;
504 SVL_DLLPRIVATE
bool ImpSwitchToSpecifiedCalendar( OUString
& rOrgCalendar
,
505 double& fOrgDateTime
,
506 const ImpSvNumFor
& rNumFor
) const;
509 /** Whether to use possessive genitive case month name, or partitive case
510 month name, instead of nominative name (noun).
513 0: execute check <br>
514 set to 1 if nominative case is returned, <br>
515 set to 2 if genitive case is returned, <br>
516 set to 3 if partitive case is returned <br>
517 1: don't execute check, return nominative case <br>
518 2: don't execute check, return genitive case <br>
519 3: don't execute check, return partitive case <br>
522 a NfKeywordIndex, must designate a month type code
524 @returns one of css::i18n::CalendarDisplayCode values
525 according to eCodeType and the check executed (or passed).
527 SVL_DLLPRIVATE
static sal_Int32
ImpUseMonthCase( int & io_nState
, const ImpSvNumFor
& rNumFor
, NfKeywordIndex eCodeType
);
529 /// Whether it's a (YY)YY-M(M)-D(D) format.
530 SVL_DLLPRIVATE
bool ImpIsIso8601( const ImpSvNumFor
& rNumFor
) const;
532 const CharClass
& rChrCls() const;
533 const LocaleDataWrapper
& rLoc() const;
534 CalendarWrapper
& GetCal() const;
535 const SvNumberFormatter
& GetFormatter() const;
537 // divide in substrings and color conditions
538 SVL_DLLPRIVATE
short ImpNextSymbol( OUStringBuffer
& rString
,
540 OUString
& sSymbol
) const;
542 // read string until ']' and strip blanks (after condition)
543 SVL_DLLPRIVATE
static sal_Int32
ImpGetNumber( OUStringBuffer
& rString
,
548 * Parse the content of '[$-xxx] or '[$-xxxxxxxx]' and extract the locale
549 * type from it. Given the string, start parsing at position specified by
550 * nPos, and store the end position with nPos when the parsing is
551 * complete. The nPos should point to the '$' before the parsing, and to
552 * the closing bracket after the parsing. When the content is [$-xxx],
553 * the xxx part represents the language type (aka LCID) in hex numerals.
554 * When the content is [$-xxxxxxxx] the last 4 digits represent the LCID
555 * (again in hex), the next 2 digits represent the calendar type, and the
556 * 2 highest digits (if exists) is the numeral shape.
559 * http://office.microsoft.com/en-us/excel-help/creating-international-number-formats-HA001034635.aspx
561 * @param rString input string
562 * @param nPos position (see above).
564 * @return struct containing numeral shape, calendar type, and LCID that
565 * specifies language type. See i18nlangtag/lang.h for a complete
566 * list of language types. These numbers also correspond with the
567 * numbers used by Microsoft Office.
569 SVL_DLLPRIVATE
static LocaleType
ImpGetLocaleType( const OUString
& rString
, sal_Int32
& nPos
);
571 /** Obtain calendar and numerals from a LocaleType that was parsed from a
572 LCID with ImpGetLocaleType().
574 Inserts a NatNum modifier to rString at nPos if needed as determined
575 from the numeral code.
577 @ATTENTION: may modify <member>maLocale</member> to make it follow
578 aTmpLocale, in which case also nLang is adapted.
580 @returns a string with the calendar if one was determined from the
581 calendar code, else an empty string. The calendar string needs to be
582 inserted at a proper position to rString after all bracketed prefixes.
584 SVL_DLLPRIVATE OUString
ImpObtainCalendarAndNumerals( OUStringBuffer
& rString
,
586 LanguageType
& nLang
,
587 const LocaleType
& aTmpLocale
);
589 // standard number output
590 SVL_DLLPRIVATE
void ImpGetOutputStandard( double& fNumber
, OUString
& OutString
) const;
591 SVL_DLLPRIVATE
void ImpGetOutputStandard( double& fNumber
, OUStringBuffer
& OutString
) const;
592 SVL_DLLPRIVATE
void ImpGetOutputStdToPrecision( double& rNumber
, OUString
& rOutString
, sal_uInt16 nPrecision
) const;
593 // numbers in input line
594 SVL_DLLPRIVATE
void ImpGetOutputInputLine( double fNumber
, OUString
& OutString
) const;
596 // check subcondition
597 // OP undefined => -1
599 SVL_DLLPRIVATE
static short ImpCheckCondition(double fNumber
,
601 SvNumberformatLimitOps eOp
);
603 // Helper function for number strings
604 // append string symbols, insert leading 0 or ' ', or ...
605 SVL_DLLPRIVATE
bool ImpNumberFill( OUStringBuffer
& sStr
,
611 bool bInsertRightBlank
= false );
613 // Helper function to fill in the integer part and the group (AKA thousand) separators
614 SVL_DLLPRIVATE
bool ImpNumberFillWithThousands( OUStringBuffer
& sStr
,
620 bool bAddDecSep
= true );
622 // Helper function to fill in the group (AKA thousand) separators
623 // or to skip additional digits
624 SVL_DLLPRIVATE
void ImpDigitFill( OUStringBuffer
& sStr
,
628 sal_Int32
& nDigitCount
,
629 utl::DigitGroupingIterator
& );
631 SVL_DLLPRIVATE
bool ImpDecimalFill( OUStringBuffer
& sStr
,
638 /** Calculate each element of fraction:
639 * integer part, numerator part, denominator part
640 * @param fNumber value to be represented as fraction. Will contain absolute fractional part
641 * @param nIx subformat number 0..3
642 * @param fIntPart integral part of fraction
643 * @param nFrac numerator of fraction
644 * @param nDic denominator of fraction
646 SVL_DLLPRIVATE
void ImpGetFractionElements( double& fNumber
,
650 sal_uInt64
& nDiv
) const;
651 SVL_DLLPRIVATE
bool ImpGetFractionOutput(double fNumber
,
653 OUStringBuffer
& OutString
);
654 SVL_DLLPRIVATE
bool ImpGetScientificOutput(double fNumber
,
656 OUStringBuffer
& OutString
);
658 SVL_DLLPRIVATE
bool ImpGetDateOutput( double fNumber
,
660 OUStringBuffer
& OutString
);
661 SVL_DLLPRIVATE
bool ImpGetTimeOutput( double fNumber
,
663 OUStringBuffer
& OutString
);
664 SVL_DLLPRIVATE
bool ImpGetDateTimeOutput( double fNumber
,
666 OUStringBuffer
& OutString
);
668 // Switches to the "gregorian" calendar if the current calendar is
669 // non-"gregorian" and the era is a "Dummy" era of a calendar which doesn't
670 // know a "before" era (like zh_TW ROC or ja_JP Gengou). If switched and
671 // rOrgCalendar was "gregorian" the string is emptied. If rOrgCalendar was
672 // empty the previous calendar name and date/time are returned.
673 SVL_DLLPRIVATE
bool ImpFallBackToGregorianCalendar( OUString
& rOrgCalendar
, double& fOrgDateTime
);
675 // Append a "G" short era string of the given calendar. In the case of a
676 // Gengou calendar this is a one character abbreviation, for other
677 // calendars the XExtendedCalendar::getDisplayString() method is called.
678 SVL_DLLPRIVATE
static void ImpAppendEraG( OUStringBuffer
& OutStringBuffer
, const CalendarWrapper
& rCal
,
681 SVL_DLLPRIVATE
bool ImpGetNumberOutput( double fNumber
,
683 OUStringBuffer
& OutString
);
685 SVL_DLLPRIVATE
void ImpCopyNumberformat( const SvNumberformat
& rFormat
);
687 // normal digits or other digits, depending on ImpSvNumFor.aNatNum,
688 // [NatNum1], [NatNum2], ...
689 SVL_DLLPRIVATE OUString
ImpGetNatNumString( const SvNumberNatNum
& rNum
, sal_Int32 nVal
,
690 sal_uInt16 nMinDigits
) const;
692 OUString
ImpIntToString( sal_uInt16 nIx
, sal_Int32 nVal
, sal_uInt16 nMinDigits
= 0 ) const
694 const SvNumberNatNum
& rNum
= NumFor
[nIx
].GetNatNum();
695 if ( nMinDigits
|| rNum
.IsComplete() )
697 return ImpGetNatNumString( rNum
, nVal
, nMinDigits
);
699 return OUString::number(nVal
);
702 // Obtain the string of the fraction of second, without leading "0.",
703 // rounded to nFractionDecimals (or nFractionDecimals+1 if
704 // bAddOneRoundingDecimal==true but then truncated at nFractionDecimals,
705 // for use with the result of tools::Time::GetClock()) with the length of
706 // nFractionDecimals, unless nMinimumInputLineDecimals>0 is given for input
707 // line string where extra trailing "0" are discarded.
708 SVL_DLLPRIVATE sal_uInt16
ImpGetFractionOfSecondString( OUStringBuffer
& rBuf
, double fFractionOfSecond
,
709 int nFractionDecimals
, bool bAddOneRoundingDecimal
, sal_uInt16 nIx
, sal_uInt16 nMinimumInputLineDecimals
);
711 // transliterate according to NativeNumber
712 SVL_DLLPRIVATE OUString
impTransliterateImpl(const OUString
& rStr
, const SvNumberNatNum
& rNum
) const;
713 SVL_DLLPRIVATE
void impTransliterateImpl(OUStringBuffer
& rStr
, const SvNumberNatNum
& rNum
) const;
714 SVL_DLLPRIVATE OUString
impTransliterateImpl(const OUString
& rStr
, const SvNumberNatNum
& rNum
, sal_uInt16 nDateKey
) const;
716 OUString
impTransliterate(const OUString
& rStr
, const SvNumberNatNum
& rNum
) const
718 return rNum
.IsComplete() ? impTransliterateImpl(rStr
, rNum
) : rStr
;
721 SVL_DLLPRIVATE
void impTransliterate(OUStringBuffer
& rStr
, const SvNumberNatNum
& rNum
) const
723 if(rNum
.IsComplete())
725 impTransliterateImpl(rStr
, rNum
);
729 OUString
impTransliterate(const OUString
& rStr
, const SvNumberNatNum
& rNum
, sal_uInt16 nDateKey
) const
731 return rNum
.IsComplete() ? impTransliterateImpl(rStr
, rNum
, nDateKey
) : rStr
;
736 #endif // INCLUDED_SVL_ZFORMAT_HXX
738 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */