src/corelib/tools/qlocale.cpp File Reference

#include "qplatformdefs.h"
#include "qdatastream.h"
#include "qstring.h"
#include "qlocale.h"
#include "qlocale_p.h"
#include "qnamespace.h"
#include "qdatetime.h"
#include "qstringlist.h"
#include "qvariant.h"
#include "private/qnumeric_p.h"
#include <ctype.h>
#include <float.h>
#include <limits.h>
#include <math.h>
#include <stdlib.h>
#include <qdebug.h>
#include "qlocale_data_p.h"

Include dependency graph for qlocale.cpp:

Go to the source code of this file.

Classes

struct  Bigint

Defines

#define NEEDS_VOLATILE
#define LLONG_MAX   Q_INT64_C(0x7fffffffffffffff)
#define LLONG_MIN   (-LLONG_MAX - Q_INT64_C(1))
#define ULLONG_MAX   Q_UINT64_C(0xffffffffffffffff)
#define CONVERSION_BUFF_SIZE   255
#define QT_MAX_FLOAT   3.4028234663852886e+38
#define IEEE_BIG_OR_LITTLE_ENDIAN   1
#define Long   qint32
#define ULong   quint32
#define MALLOC   malloc
#define Sign_Extend(a, b)
#define Exp_shift   20
#define Exp_shift1   20
#define Exp_msk1   0x100000
#define Exp_msk11   0x100000
#define Exp_mask   0x7ff00000
#define P   53
#define Bias   1023
#define IEEE_Arith
#define Emin   (-1022)
#define Exp_1   0x3ff00000
#define Exp_11   0x3ff00000
#define Ebits   11
#define Frac_mask   0xfffff
#define Frac_mask1   0xfffff
#define Ten_pmax   22
#define Bletch   0x10
#define Bndry_mask   0xfffff
#define Bndry_mask1   0xfffff
#define LSB   1
#define Sign_bit   0x80000000
#define Log2P   1
#define Tiny0   0
#define Tiny1   1
#define Quick_max   14
#define Int_max   14
#define Infinite(x)   (getWord0(x) == 0x7ff00000)
#define rounded_product(a, b)   a *= b
#define rounded_quotient(a, b)   a /= b
#define Big0   (Frac_mask1 | Exp_msk1*(DBL_MAX_EXP+Bias-1))
#define Big1   0xffffffff
#define Kmax   15
#define Bcopy(x, y)
#define n_bigtens   5

Typedefs

typedef Bigint Bigint

Enumerations

enum  PrecisionMode

Functions

static char * qdtoa (double d, int mode, int ndigits, int *decpt, int *sign, char **rve, char **digits_str)
static char * _qdtoa (NEEDS_VOLATILE double d, int mode, int ndigits, int *decpt, int *sign, char **rve, char **digits_str)
static double qstrtod (const char *s00, char const **se, bool *ok)
static qlonglong qstrtoll (const char *nptr, const char **endptr, register int base, bool *ok)
static qulonglong qstrtoull (const char *nptr, const char **endptr, register int base, bool *ok)
static QLocale::Language codeToLanguage (const QChar *code)
static QLocale::Country codeToCountry (const QChar *code)
static QString languageToCode (QLocale::Language language)
static QString countryToCode (QLocale::Country country)
static const QLocalePrivatefindLocale (QLocale::Language language, QLocale::Country country)
static void getLangAndCountry (const QString &name, QLocale::Language &lang, QLocale::Country &cntry)
static const QLocalePrivatefindLocale (const QString &name)
static QString readEscapedFormatString (const QString &format, int *idx)
static int repeatCount (const QString &s, int i)
static QByteArray envVarLocale ()
static const QSystemLocalesystemLocale ()
static const QLocalePrivatesystemPrivate ()
static const QLocalePrivatedefaultPrivate ()
static QString getLocaleListData (const char *data, int index)
QDataStreamoperator<< (QDataStream &ds, const QLocale &l)
QDataStreamoperator>> (QDataStream &ds, QLocale &l)
static const QLocalePrivatedataPointer (void *v)
static int numberOptions (void *v)
static void setDataPointer (void **v, const QLocalePrivate *p)
static void setNumberOptions (void **v, int _opts)
static bool timeFormatContainsAP (const QString &format)
static QString timeZone ()
static bool qIsUpper (char c)
static char qToLower (char c)
static QString qulltoa (qulonglong l, int base, const QLocalePrivate &locale)
static QString qlltoa (qlonglong l, int base, const QLocalePrivate &locale)
static QStringdecimalForm (QString &digits, int decpt, uint precision, PrecisionMode pm, bool always_show_decpt, bool thousands_group, const QLocalePrivate &locale)
static QStringexponentForm (QString &digits, int decpt, uint precision, PrecisionMode pm, bool always_show_decpt, const QLocalePrivate &locale)
static bool isZero (double d)
static bool removeGroupSeparators (QLocalePrivate::CharBuff *num)
static ULong getWord0 (const NEEDS_VOLATILE double x)
static void setWord0 (NEEDS_VOLATILE double *x, ULong l)
static ULong getWord1 (const NEEDS_VOLATILE double x)
static void setWord1 (NEEDS_VOLATILE double *x, ULong l)
static void Storeinc (ULong *&a, const ULong &b, const ULong &c)
static BigintBalloc (int k)
static void Bfree (Bigint *v)
static Bigintmultadd (Bigint *b, int m, int a)
static Bigints2b (const char *s, int nd0, int nd, ULong y9)
static int hi0bits (ULong x)
static int lo0bits (ULong *y)
static Biginti2b (int i)
static Bigintmult (Bigint *a, Bigint *b)
static Bigintpow5mult (Bigint *b, int k)
static Bigintlshift (Bigint *b, int k)
static int cmp (Bigint *a, Bigint *b)
static Bigintdiff (Bigint *a, Bigint *b)
static double ulp (double x)
static double b2d (Bigint *a, int *e)
static Bigintd2b (double d, int *e, int *bits)
static double ratio (Bigint *a, Bigint *b)
static int quorem (Bigint *b, Bigint *S)

Variables

static const QLocalePrivatedefault_lp = 0
static QSystemLocale_systemLocale = 0
static QLocalePrivatesystem_lp = 0
static const int locale_data_size = sizeof(locale_data)/sizeof(QLocalePrivate) - 1
static Bigintp5s
static const double tens []
static const double bigtens [] = { 1e16, 1e32, 1e64, 1e128, 1e256 }
static const double tinytens [] = { 1e-16, 1e-32, 1e-64, 1e-128, 1e-256 }
static double g_double_zero = 0.0


Define Documentation

#define Bcopy ( x,
 ) 

Value:

memcpy(reinterpret_cast<char *>(&x->sign), reinterpret_cast<char *>(&y->sign), \
y->wds*sizeof(Long) + 2*sizeof(int))

Definition at line 4237 of file qlocale.cpp.

Referenced by _qdtoa(), multadd(), and qstrtod().

#define Bias   1023

Definition at line 4107 of file qlocale.cpp.

Referenced by _qdtoa(), d2b(), and qstrtod().

#define Big0   (Frac_mask1 | Exp_msk1*(DBL_MAX_EXP+Bias-1))

Definition at line 4194 of file qlocale.cpp.

Referenced by qstrtod().

#define Big1   0xffffffff

Definition at line 4195 of file qlocale.cpp.

Referenced by qstrtod().

#define Bletch   0x10

Definition at line 4116 of file qlocale.cpp.

Referenced by _qdtoa().

#define Bndry_mask   0xfffff

Definition at line 4117 of file qlocale.cpp.

Referenced by _qdtoa(), and qstrtod().

#define Bndry_mask1   0xfffff

Definition at line 4118 of file qlocale.cpp.

Referenced by qstrtod().

#define CONVERSION_BUFF_SIZE   255

Definition at line 81 of file qlocale.cpp.

#define Ebits   11

Definition at line 4112 of file qlocale.cpp.

Referenced by b2d().

#define Emin   (-1022)

Definition at line 4109 of file qlocale.cpp.

Referenced by qstrtod().

#define Exp_1   0x3ff00000

Definition at line 4110 of file qlocale.cpp.

Referenced by b2d().

#define Exp_11   0x3ff00000

Definition at line 4111 of file qlocale.cpp.

Referenced by _qdtoa().

#define Exp_mask   0x7ff00000

Definition at line 4105 of file qlocale.cpp.

Referenced by _qdtoa(), qstrtod(), and ulp().

#define Exp_msk1   0x100000

Definition at line 4103 of file qlocale.cpp.

Referenced by _qdtoa(), d2b(), qstrtod(), ratio(), and ulp().

#define Exp_msk11   0x100000

Definition at line 4104 of file qlocale.cpp.

Referenced by d2b().

#define Exp_shift   20

Definition at line 4101 of file qlocale.cpp.

Referenced by d2b(), and ulp().

#define Exp_shift1   20

Definition at line 4102 of file qlocale.cpp.

Referenced by _qdtoa().

#define Frac_mask   0xfffff

Definition at line 4113 of file qlocale.cpp.

Referenced by _qdtoa(), and d2b().

#define Frac_mask1   0xfffff

Definition at line 4114 of file qlocale.cpp.

Referenced by _qdtoa().

#define IEEE_Arith

Definition at line 4108 of file qlocale.cpp.

#define IEEE_BIG_OR_LITTLE_ENDIAN   1

Definition at line 4001 of file qlocale.cpp.

#define Infinite (  )     (getWord0(x) == 0x7ff00000)

Definition at line 4126 of file qlocale.cpp.

#define Int_max   14

Definition at line 4125 of file qlocale.cpp.

Referenced by _qdtoa().

#define Kmax   15

Definition at line 4208 of file qlocale.cpp.

#define LLONG_MAX   Q_INT64_C(0x7fffffffffffffff)

Definition at line 72 of file qlocale.cpp.

Referenced by qstrtoll().

#define LLONG_MIN   (-LLONG_MAX - Q_INT64_C(1))

Definition at line 75 of file qlocale.cpp.

Referenced by qstrtoll().

#define Log2P   1

Definition at line 4121 of file qlocale.cpp.

Referenced by _qdtoa(), and qstrtod().

#define Long   qint32

Definition at line 4016 of file qlocale.cpp.

Referenced by _qdtoa(), Balloc(), diff(), qstrtod(), quorem(), s2b(), and ulp().

#define LSB   1

Definition at line 4119 of file qlocale.cpp.

Referenced by qstrtod().

#define MALLOC   malloc

Definition at line 4019 of file qlocale.cpp.

Referenced by Balloc().

#define n_bigtens   5

Definition at line 4918 of file qlocale.cpp.

Referenced by _qdtoa(), and qstrtod().

#define NEEDS_VOLATILE

Definition at line 67 of file qlocale.cpp.

Referenced by getWord0(), getWord1(), setWord0(), and setWord1().

#define P   53

Definition at line 4106 of file qlocale.cpp.

Referenced by _qdtoa(), d2b(), QFragmentMapData::erase_single(), QFragmentMapData::insert_single(), qdesigner_internal::merge(), qstrtod(), QFragmentMapData::rebalance(), QFragmentMapData::rotateLeft(), QFragmentMapData::rotateRight(), and ulp().

#define QT_MAX_FLOAT   3.4028234663852886e+38

Returns the float represented by the localized string s, or 0.0 if the conversion failed.

If ok is not 0, reports failure by setting ok to false and success by setting *ok to true.

This function ignores leading and trailing whitespace.

See also:
toDouble(), toInt(), toString()

Definition at line 2307 of file qlocale.cpp.

Referenced by QString::toFloat(), and QLocale::toFloat().

#define Quick_max   14

Definition at line 4124 of file qlocale.cpp.

Referenced by _qdtoa().

#define rounded_product ( a,
 )     a *= b

Definition at line 4190 of file qlocale.cpp.

Referenced by qstrtod().

#define rounded_quotient ( a,
 )     a /= b

Definition at line 4191 of file qlocale.cpp.

Referenced by qstrtod().

#define Sign_bit   0x80000000

Definition at line 4120 of file qlocale.cpp.

Referenced by _qdtoa().

#define Sign_Extend ( a,
 ) 

Definition at line 4029 of file qlocale.cpp.

Referenced by diff(), and quorem().

#define Ten_pmax   22

Definition at line 4115 of file qlocale.cpp.

Referenced by _qdtoa(), and qstrtod().

#define Tiny0   0

Definition at line 4122 of file qlocale.cpp.

Referenced by qstrtod().

#define Tiny1   1

Definition at line 4123 of file qlocale.cpp.

Referenced by qstrtod().

#define ULLONG_MAX   Q_UINT64_C(0xffffffffffffffff)

Definition at line 78 of file qlocale.cpp.

Referenced by qstrtoull().

#define ULong   quint32

Definition at line 4017 of file qlocale.cpp.

Referenced by _qdtoa(), b2d(), cmp(), d2b(), diff(), lo0bits(), lshift(), mult(), multadd(), qstrtod(), and quorem().


Typedef Documentation

typedef struct Bigint Bigint

Definition at line 4217 of file qlocale.cpp.


Enumeration Type Documentation

enum PrecisionMode

Definition at line 3062 of file qlocale.cpp.

03062                    {
03063     PMDecimalDigits =             0x01,
03064     PMSignificantDigits =   0x02,
03065     PMChopTrailingZeros =   0x03
03066 };


Function Documentation

static char * _qdtoa ( NEEDS_VOLATILE double  d,
int  mode,
int  ndigits,
int *  decpt,
int *  sign,
char **  rve,
char **  digits_str 
) [static]

Definition at line 5676 of file qlocale.cpp.

References b, Balloc(), Bcopy, Bfree(), Bias, Bletch, Bndry_mask, cmp(), d2b(), diff(), Exp_11, Exp_mask, Exp_msk1, Exp_shift1, Frac_mask, Frac_mask1, getWord0(), getWord1(), hi0bits(), i2b(), int, Int_max, j, Bigint::k, L, Log2P, Long, lshift(), mult(), multadd(), n_bigtens, NULL, P, pow5mult(), Quick_max, quorem(), s, QCss::S, s2, setWord0(), Bigint::sign, Sign_bit, t, Ten_pmax, ULong, and x.

Referenced by qdtoa().

05677 {
05678     /*
05679       Arguments ndigits, decpt, sign are similar to those
05680       of ecvt and fcvt; trailing zeros are suppressed from
05681       the returned string.  If not null, *rve is set to point
05682       to the end of the return value.  If d is +-Infinity or NaN,
05683       then *decpt is set to 9999.
05684 
05685       mode:
05686       0 ==> shortest string that yields d when read in
05687       and rounded to nearest.
05688       1 ==> like 0, but with Steele & White stopping rule;
05689       e.g. with IEEE P754 arithmetic , mode 0 gives
05690       1e23 whereas mode 1 gives 9.999999999999999e22.
05691       2 ==> max(1,ndigits) significant digits.  This gives a
05692       return value similar to that of ecvt, except
05693       that trailing zeros are suppressed.
05694       3 ==> through ndigits past the decimal point.  This
05695       gives a return value similar to that from fcvt,
05696       except that trailing zeros are suppressed, and
05697       ndigits can be negative.
05698       4-9 should give the same return values as 2-3, i.e.,
05699       4 <= mode <= 9 ==> same return as mode
05700       2 + (mode & 1).  These modes are mainly for
05701       debugging; often they run slower but sometimes
05702       faster than modes 2-3.
05703       4,5,8,9 ==> left-to-right digit generation.
05704       6-9 ==> don't try fast floating-point estimate
05705       (if applicable).
05706 
05707       Values of mode other than 0-9 are treated as mode 0.
05708 
05709       Sufficient space is allocated to the return value
05710       to hold the suppressed trailing zeros.
05711     */
05712 
05713     int bbits, b2, b5, be, dig, i, ieps, ilim0,
05714         j, j1, k, k0, k_check, leftright, m2, m5, s2, s5,
05715         try_quick;
05716     int ilim = 0, ilim1 = 0, spec_case = 0;        /* pacify gcc */
05717     Long L;
05718 #ifndef Sudden_Underflow
05719     int denorm;
05720     ULong x;
05721 #endif
05722     Bigint *b, *b1, *delta, *mhi, *S;
05723     Bigint *mlo = NULL; /* pacify gcc */
05724     double d2;
05725     double ds, eps;
05726     char *s, *s0;
05727 
05728     if (getWord0(d) & Sign_bit) {
05729         /* set sign for everything, including 0's and NaNs */
05730         *sign = 1;
05731         setWord0(&d, getWord0(d) & ~Sign_bit);        /* clear sign bit */
05732     }
05733     else
05734         *sign = 0;
05735 
05736 #if defined(IEEE_Arith) + defined(VAX)
05737 #ifdef IEEE_Arith
05738     if ((getWord0(d) & Exp_mask) == Exp_mask)
05739 #else
05740         if (getWord0(d)  == 0x8000)
05741 #endif
05742             {
05743                 /* Infinity or NaN */
05744                 *decpt = 9999;
05745                 s =
05746 #ifdef IEEE_Arith
05747                     !getWord1(d) && !(getWord0(d) & 0xfffff) ? const_cast<char*>("Infinity") :
05748 #endif
05749                     const_cast<char*>("NaN");
05750                 if (rve)
05751                     *rve =
05752 #ifdef IEEE_Arith
05753                         s[3] ? s + 8 :
05754 #endif
05755                         s + 3;
05756                 return s;
05757             }
05758 #endif
05759 #ifdef IBM
05760     d += 0; /* normalize */
05761 #endif
05762     if (d == g_double_zero)
05763         {
05764             *decpt = 1;
05765             s = const_cast<char*>("0");
05766             if (rve)
05767                 *rve = s + 1;
05768             return s;
05769         }
05770 
05771     b = d2b(d, &be, &bbits);
05772 #ifdef Sudden_Underflow
05773     i = (int)(getWord0(d) >> Exp_shift1 & (Exp_mask>>Exp_shift1));
05774 #else
05775     if ((i = int(getWord0(d) >> Exp_shift1 & (Exp_mask>>Exp_shift1))) != 0) {
05776 #endif
05777         d2 = d;
05778         setWord0(&d2, getWord0(d2) & Frac_mask1);
05779         setWord0(&d2, getWord0(d2) | Exp_11);
05780 #ifdef IBM
05781         if (j = 11 - hi0bits(getWord0(d2) & Frac_mask))
05782             d2 /= 1 << j;
05783 #endif
05784 
05785         /* log(x)        ~=~ log(1.5) + (x-1.5)/1.5
05786          * log10(x)         =  log(x) / log(10)
05787          *                ~=~ log(1.5)/log(10) + (x-1.5)/(1.5*log(10))
05788          * log10(d) = (i-Bias)*log(2)/log(10) + log10(d2)
05789          *
05790          * This suggests computing an approximation k to log10(d) by
05791          *
05792          * k = (i - Bias)*0.301029995663981
05793          *        + ( (d2-1.5)*0.289529654602168 + 0.176091259055681 );
05794          *
05795          * We want k to be too large rather than too small.
05796          * The error in the first-order Taylor series approximation
05797          * is in our favor, so we just round up the constant enough
05798          * to compensate for any error in the multiplication of
05799          * (i - Bias) by 0.301029995663981; since |i - Bias| <= 1077,
05800          * and 1077 * 0.30103 * 2^-52 ~=~ 7.2e-14,
05801          * adding 1e-13 to the constant term more than suffices.
05802          * Hence we adjust the constant term to 0.1760912590558.
05803          * (We could get a more accurate k by invoking log10,
05804          *  but this is probably not worthwhile.)
05805          */
05806 
05807         i -= Bias;
05808 #ifdef IBM
05809         i <<= 2;
05810         i += j;
05811 #endif
05812 #ifndef Sudden_Underflow
05813         denorm = 0;
05814     }
05815     else {
05816         /* d is denormalized */
05817 
05818         i = bbits + be + (Bias + (P-1) - 1);
05819         x = i > 32  ? getWord0(d) << (64 - i) | getWord1(d) >> (i - 32)
05820             : getWord1(d) << (32 - i);
05821         d2 = x;
05822         setWord0(&d2, getWord0(d2) - 31*Exp_msk1); /* adjust exponent */
05823         i -= (Bias + (P-1) - 1) + 1;
05824         denorm = 1;
05825     }
05826 #endif
05827     ds = (d2-1.5)*0.289529654602168 + 0.1760912590558 + i*0.301029995663981;
05828     k = int(ds);
05829     if (ds < 0. && ds != k)
05830         k--;        /* want k = floor(ds) */
05831     k_check = 1;
05832     if (k >= 0 && k <= Ten_pmax) {
05833         if (d < tens[k])
05834             k--;
05835         k_check = 0;
05836     }
05837     j = bbits - i - 1;
05838     if (j >= 0) {
05839         b2 = 0;
05840         s2 = j;
05841     }
05842     else {
05843         b2 = -j;
05844         s2 = 0;
05845     }
05846     if (k >= 0) {
05847         b5 = 0;
05848         s5 = k;
05849         s2 += k;
05850     }
05851     else {
05852         b2 -= k;
05853         b5 = -k;
05854         s5 = 0;
05855     }
05856     if (mode < 0 || mode > 9)
05857         mode = 0;
05858     try_quick = 1;
05859     if (mode > 5) {
05860         mode -= 4;
05861         try_quick = 0;
05862     }
05863     leftright = 1;
05864     switch(mode) {
05865     case 0:
05866     case 1:
05867         ilim = ilim1 = -1;
05868         i = 18;
05869         ndigits = 0;
05870         break;
05871     case 2:
05872         leftright = 0;
05873         /* no break */
05874     case 4:
05875         if (ndigits <= 0)
05876             ndigits = 1;
05877         ilim = ilim1 = i = ndigits;
05878         break;
05879     case 3:
05880         leftright = 0;
05881         /* no break */
05882     case 5:
05883         i = ndigits + k + 1;
05884         ilim = i;
05885         ilim1 = i - 1;
05886         if (i <= 0)
05887             i = 1;
05888     }
05889     *resultp = static_cast<char *>(malloc(i + 1));
05890     s = s0 = *resultp;
05891 
05892     if (ilim >= 0 && ilim <= Quick_max && try_quick) {
05893 
05894         /* Try to get by with floating-point arithmetic. */
05895 
05896         i = 0;
05897         d2 = d;
05898         k0 = k;
05899         ilim0 = ilim;
05900         ieps = 2; /* conservative */
05901         if (k > 0) {
05902             ds = tens[k&0xf];
05903             j = k >> 4;
05904             if (j & Bletch) {
05905                 /* prevent overflows */
05906                 j &= Bletch - 1;
05907                 d /= bigtens[n_bigtens-1];
05908                 ieps++;
05909             }
05910             for(; j; j >>= 1, i++)
05911                 if (j & 1) {
05912                     ieps++;
05913                     ds *= bigtens[i];
05914                 }
05915             d /= ds;
05916         }
05917         else if ((j1 = -k) != 0) {
05918             d *= tens[j1 & 0xf];
05919             for(j = j1 >> 4; j; j >>= 1, i++)
05920                 if (j & 1) {
05921                     ieps++;
05922                     d *= bigtens[i];
05923                 }
05924         }
05925         if (k_check && d < 1. && ilim > 0) {
05926             if (ilim1 <= 0)
05927                 goto fast_failed;
05928             ilim = ilim1;
05929             k--;
05930             d *= 10.;
05931             ieps++;
05932         }
05933         eps = ieps*d + 7.;
05934         setWord0(&eps, getWord0(eps) - (P-1)*Exp_msk1);
05935         if (ilim == 0) {
05936             S = mhi = 0;
05937             d -= 5.;
05938             if (d > eps)
05939                 goto one_digit;
05940             if (d < -eps)
05941                 goto no_digits;
05942             goto fast_failed;
05943         }
05944 #ifndef No_leftright
05945         if (leftright) {
05946             /* Use Steele & White method of only
05947              * generating digits needed.
05948              */
05949             eps = 0.5/tens[ilim-1] - eps;
05950             for(i = 0;;) {
05951                 L = Long(d);
05952                 d -= L;
05953                 *s++ = '0' + int(L);
05954                 if (d < eps)
05955                     goto ret1;
05956                 if (1. - d < eps)
05957                     goto bump_up;
05958                 if (++i >= ilim)
05959                     break;
05960                 eps *= 10.;
05961                 d *= 10.;
05962             }
05963         }
05964         else {
05965 #endif
05966             /* Generate ilim digits, then fix them up. */
05967 #if defined(Q_OS_IRIX) && defined(Q_CC_GNU)
05968             // work around a bug on 64 bit IRIX gcc
05969             double *t = (double *) tens;
05970             eps *= t[ilim-1];
05971 #else
05972             eps *= tens[ilim-1];
05973 #endif
05974             for(i = 1;; i++, d *= 10.) {
05975                 L = Long(d);
05976                 d -= L;
05977                 *s++ = '0' + int(L);
05978                 if (i == ilim) {
05979                     if (d > 0.5 + eps)
05980                         goto bump_up;
05981                     else if (d < 0.5 - eps) {
05982                         while(*--s == '0');
05983                         s++;
05984                         goto ret1;
05985                     }
05986                     break;
05987                 }
05988             }
05989 #ifndef No_leftright
05990         }
05991 #endif
05992     fast_failed:
05993         s = s0;
05994         d = d2;
05995         k = k0;
05996         ilim = ilim0;
05997     }
05998 
05999     /* Do we have a "small" integer? */
06000 
06001     if (be >= 0 && k <= Int_max) {
06002         /* Yes. */
06003         ds = tens[k];
06004         if (ndigits < 0 && ilim <= 0) {
06005             S = mhi = 0;
06006             if (ilim < 0 || d <= 5*ds)
06007                 goto no_digits;
06008             goto one_digit;
06009         }
06010         for(i = 1;; i++) {
06011             L = Long(d / ds);
06012             d -= L*ds;
06013 #ifdef Check_FLT_ROUNDS
06014             /* If FLT_ROUNDS == 2, L will usually be high by 1 */
06015             if (d < 0) {
06016                 L--;
06017                 d += ds;
06018             }
06019 #endif
06020             *s++ = '0' + int(L);
06021             if (i == ilim) {
06022                 d += d;
06023                 if (d > ds || (d == ds && L & 1)) {
06024                 bump_up:
06025                     while(*--s == '9')
06026                         if (s == s0) {
06027                             k++;
06028                             *s = '0';
06029                             break;
06030                         }
06031                     ++*s++;
06032                 }
06033                 break;
06034             }
06035             if ((d *= 10.) == g_double_zero)
06036                 break;
06037         }
06038         goto ret1;
06039     }
06040 
06041     m2 = b2;
06042     m5 = b5;
06043     mhi = mlo = 0;
06044     if (leftright) {
06045         if (mode < 2) {
06046             i =
06047 #ifndef Sudden_Underflow
06048                 denorm ? be + (Bias + (P-1) - 1 + 1) :
06049 #endif
06050 #ifdef IBM
06051                 1 + 4*P - 3 - bbits + ((bbits + be - 1) & 3);
06052 #else
06053             1 + P - bbits;
06054 #endif
06055         }
06056         else {
06057             j = ilim - 1;
06058             if (m5 >= j)
06059                 m5 -= j;
06060             else {
06061                 s5 += j -= m5;
06062                 b5 += j;
06063                 m5 = 0;
06064             }
06065             if ((i = ilim) < 0) {
06066                 m2 -= i;
06067                 i = 0;
06068             }
06069         }
06070         b2 += i;
06071         s2 += i;
06072         mhi = i2b(1);
06073     }
06074     if (m2 > 0 && s2 > 0) {
06075         i = m2 < s2 ? m2 : s2;
06076         b2 -= i;
06077         m2 -= i;
06078         s2 -= i;
06079     }
06080     if (b5 > 0) {
06081         if (leftright) {
06082             if (m5 > 0) {
06083                 mhi = pow5mult(mhi, m5);
06084                 b1 = mult(mhi, b);
06085                 Bfree(b);
06086                 b = b1;
06087             }
06088             if ((j = b5 - m5) != 0)
06089                 b = pow5mult(b, j);
06090         }
06091         else
06092             b = pow5mult(b, b5);
06093     }
06094     S = i2b(1);
06095     if (s5 > 0)
06096         S = pow5mult(S, s5);
06097 
06098     /* Check for special case that d is a normalized power of 2. */
06099 
06100     if (mode < 2) {
06101         if (!getWord1(d) && !(getWord0(d) & Bndry_mask)
06102 #ifndef Sudden_Underflow
06103             && getWord0(d) & Exp_mask
06104 #endif
06105             ) {
06106             /* The special case */
06107             b2 += Log2P;
06108             s2 += Log2P;
06109             spec_case = 1;
06110         }
06111         else
06112             spec_case = 0;
06113     }
06114 
06115     /* Arrange for convenient computation of quotients:
06116      * shift left if necessary so divisor has 4 leading 0 bits.
06117      *
06118      * Perhaps we should just compute leading 28 bits of S once
06119      * and for all and pass them and a shift to quorem, so it
06120      * can do shifts and ors to compute the numerator for q.
06121      */
06122 #ifdef Pack_32
06123     if ((i = ((s5 ? 32 - hi0bits(S->x[S->wds-1]) : 1) + s2) & 0x1f) != 0)
06124         i = 32 - i;
06125 #else
06126     if (i = ((s5 ? 32 - hi0bits(S->x[S->wds-1]) : 1) + s2) & 0xf)
06127         i = 16 - i;
06128 #endif
06129     if (i > 4) {
06130         i -= 4;
06131         b2 += i;
06132         m2 += i;
06133         s2 += i;
06134     }
06135     else if (i < 4) {
06136         i += 28;
06137         b2 += i;
06138         m2 += i;
06139         s2 += i;
06140     }
06141     if (b2 > 0)
06142         b = lshift(b, b2);
06143     if (s2 > 0)
06144         S = lshift(S, s2);
06145     if (k_check) {
06146         if (cmp(b,S) < 0) {
06147             k--;
06148             b = multadd(b, 10, 0);        /* we botched the k estimate */
06149             if (leftright)
06150                 mhi = multadd(mhi, 10, 0);
06151             ilim = ilim1;
06152         }
06153     }
06154     if (ilim <= 0 && mode > 2) {
06155         if (ilim < 0 || cmp(b,S = multadd(S,5,0)) <= 0) {
06156             /* no digits, fcvt style */
06157         no_digits:
06158             k = -1 - ndigits;
06159             goto ret;
06160         }
06161     one_digit:
06162         *s++ = '1';
06163         k++;
06164         goto ret;
06165     }
06166     if (leftright) {
06167         if (m2 > 0)
06168             mhi = lshift(mhi, m2);
06169 
06170         /* Compute mlo -- check for special case
06171          * that d is a normalized power of 2.
06172          */
06173 
06174         mlo = mhi;
06175         if (spec_case) {
06176             mhi = Balloc(mhi->k);
06177             Bcopy(mhi, mlo);
06178             mhi = lshift(mhi, Log2P);
06179         }
06180 
06181         for(i = 1;;i++) {
06182             dig = quorem(b,S) + '0';
06183             /* Do we yet have the shortest decimal string
06184              * that will round to d?
06185              */
06186             j = cmp(b, mlo);
06187             delta = diff(S, mhi);
06188             j1 = delta->sign ? 1 : cmp(b, delta);
06189             Bfree(delta);
06190 #ifndef ROUND_BIASED
06191             if (j1 == 0 && !mode && !(getWord1(d) & 1)) {
06192                 if (dig == '9')
06193                     goto round_9_up;
06194                 if (j > 0)
06195                     dig++;
06196                 *s++ = dig;
06197                 goto ret;
06198             }
06199 #endif
06200             if (j < 0 || (j == 0 && !mode
06201 #ifndef ROUND_BIASED
06202                           && !(getWord1(d) & 1)
06203 #endif
06204                           )) {
06205                 if (j1 > 0) {
06206                     b = lshift(b, 1);
06207                     j1 = cmp(b, S);
06208                     if ((j1 > 0 || (j1 == 0 && dig & 1))
06209                         && dig++ == '9')
06210                         goto round_9_up;
06211                 }
06212                 *s++ = dig;
06213                 goto ret;
06214             }
06215             if (j1 > 0) {
06216                 if (dig == '9') { /* possible if i == 1 */
06217                 round_9_up:
06218                     *s++ = '9';
06219                     goto roundoff;
06220                 }
06221                 *s++ = dig + 1;
06222                 goto ret;
06223             }
06224             *s++ = dig;
06225             if (i == ilim)
06226                 break;
06227             b = multadd(b, 10, 0);
06228             if (mlo == mhi)
06229                 mlo = mhi = multadd(mhi, 10, 0);
06230             else {
06231                 mlo = multadd(mlo, 10, 0);
06232                 mhi = multadd(mhi, 10, 0);
06233             }
06234         }
06235     }
06236     else
06237         for(i = 1;; i++) {
06238             *s++ = dig = quorem(b,S) + '0';
06239             if (i >= ilim)
06240                 break;
06241             b = multadd(b, 10, 0);
06242         }
06243 
06244     /* Round off last digit */
06245 
06246     b = lshift(b, 1);
06247     j = cmp(b, S);
06248     if (j > 0 || (j == 0 && dig & 1)) {
06249     roundoff:
06250         while(*--s == '9')
06251             if (s == s0) {
06252                 k++;
06253                 *s++ = '1';
06254                 goto ret;
06255             }
06256         ++*s++;
06257     }
06258     else {
06259         while(*--s == '0');
06260         s++;
06261     }
06262  ret:
06263     Bfree(S);
06264     if (mhi) {
06265         if (mlo && mlo != mhi)
06266             Bfree(mlo);
06267         Bfree(mhi);
06268     }
06269  ret1:
06270     Bfree(b);
06271     if (s == s0) {                                /* don't return empty string */
06272         *s++ = '0';
06273         k = 0;
06274     }
06275     *s = 0;
06276     *decpt = k + 1;
06277     if (rve)
06278         *rve = s;
06279     return s0;
06280 }

Here is the call graph for this function:

static double b2d ( Bigint a,
int *  e 
) [static]

Definition at line 4707 of file qlocale.cpp.

References a, d, Ebits, Exp_1, hi0bits(), Bigint::k, setWord0(), setWord1(), ULong, w, and y.

Referenced by ratio().

04708 {
04709     ULong *xa, *xa0, w, y, z;
04710     int k;
04711     double d;
04712 
04713     xa0 = a->x;
04714     xa = xa0 + a->wds;
04715     y = *--xa;
04716 #ifdef BSD_QDTOA_DEBUG
04717     if (!y) Bug("zero y in b2d");
04718 #endif
04719     k = hi0bits(y);
04720     *e = 32 - k;
04721 #ifdef Pack_32
04722     if (k < Ebits) {
04723         setWord0(&d, Exp_1 | y >> (Ebits - k));
04724         w = xa > xa0 ? *--xa : 0;
04725         setWord1(&d, y << ((32-Ebits) + k) | w >> (Ebits - k));
04726         goto ret_d;
04727     }
04728     z = xa > xa0 ? *--xa : 0;
04729     if (k -= Ebits) {
04730         setWord0(&d, Exp_1 | y << k | z >> (32 - k));
04731         y = xa > xa0 ? *--xa : 0;
04732         setWord1(&d, z << k | y >> (32 - k));
04733     }
04734     else {
04735         setWord0(&d, Exp_1 | y);
04736         setWord1(&d, z);
04737     }
04738 #else
04739     if (k < Ebits + 16) {
04740         z = xa > xa0 ? *--xa : 0;
04741         setWord0(&d, Exp_1 | y << k - Ebits | z >> Ebits + 16 - k);
04742         w = xa > xa0 ? *--xa : 0;
04743         y = xa > xa0 ? *--xa : 0;
04744         setWord1(&d, z << k + 16 - Ebits | w << k - Ebits | y >> 16 + Ebits - k);
04745         goto ret_d;
04746     }
04747     z = xa > xa0 ? *--xa : 0;
04748     w = xa > xa0 ? *--xa : 0;
04749     k -= Ebits + 16;
04750     setWord0(&d, Exp_1 | y << k + 16 | z << k | w >> 16 - k);
04751     y = xa > xa0 ? *--xa : 0;
04752     setWord1(&d, w << k + 16 | y << k);
04753 #endif
04754  ret_d:
04755     return d;
04756 }

Here is the call graph for this function:

static Bigint* Balloc ( int  k  )  [static]

Definition at line 4219 of file qlocale.cpp.

References Bigint::k, Long, MALLOC, Bigint::maxwds, Bigint::sign, Bigint::wds, and x.

Referenced by _qdtoa(), d2b(), diff(), i2b(), lshift(), mult(), multadd(), qstrtod(), and s2b().

04220 {
04221     int x;
04222     Bigint *rv;
04223 
04224     x = 1 << k;
04225     rv = static_cast<Bigint *>(MALLOC(sizeof(Bigint) + (x-1)*sizeof(Long)));
04226     rv->k = k;
04227     rv->maxwds = x;
04228     rv->sign = rv->wds = 0;
04229     return rv;
04230 }

static void Bfree ( Bigint v  )  [static]

Definition at line 4232 of file qlocale.cpp.

Referenced by _qdtoa(), lshift(), multadd(), pow5mult(), and qstrtod().

04233 {
04234     free(v);
04235 }

static int cmp ( Bigint a,
Bigint b 
) [static]

Definition at line 4571 of file qlocale.cpp.

References a, b, j, and ULong.

04572 {
04573     ULong *xa, *xa0, *xb, *xb0;
04574     int i, j;
04575 
04576     i = a->wds;
04577     j = b->wds;
04578 #ifdef BSD_QDTOA_DEBUG
04579     if (i > 1 && !a->x[i-1])
04580         Bug("cmp called with a->x[a->wds-1] == 0");
04581     if (j > 1 && !b->x[j-1])
04582         Bug("cmp called with b->x[b->wds-1] == 0");
04583 #endif
04584     if (i -= j)
04585         return i;
04586     xa0 = a->x;
04587     xa = xa0 + j;
04588     xb0 = b->x;
04589     xb = xb0 + j;
04590     for(;;) {
04591         if (*--xa != *--xb)
04592             return *xa < *xb ? -1 : 1;
04593         if (xa <= xa0)
04594             break;
04595     }
04596     return 0;
04597 }

static QLocale::Country codeToCountry ( const QChar code  )  [static]

Definition at line 113 of file qlocale.cpp.

References QLocale::AnyCountry, c, code, and country_code_list.

Referenced by getLangAndCountry().

00114 {
00115     ushort uc1 = code[0].unicode();
00116     ushort uc2 = code[1].unicode();
00117 
00118     const unsigned char *c = country_code_list;
00119     for (; *c != 0; c += 2) {
00120         if (uc1 == c[0] && uc2 == c[1])
00121             return QLocale::Country((c - country_code_list)/2);
00122     }
00123 
00124     return QLocale::AnyCountry;
00125 }

static QLocale::Language codeToLanguage ( const QChar code  )  [static]

Definition at line 99 of file qlocale.cpp.

References c, QLocale::C, code, and language_code_list.

Referenced by getLangAndCountry().

00100 {
00101     ushort uc1 = code[0].unicode();
00102     ushort uc2 = code[1].unicode();
00103 
00104     const unsigned char *c = language_code_list;
00105     for (; *c != 0; c += 2) {
00106         if (uc1 == c[0] && uc2 == c[1])
00107             return QLocale::Language((c - language_code_list)/2);
00108     }
00109 
00110     return QLocale::C;
00111 }

static QString countryToCode ( QLocale::Country  country  )  [static]

Definition at line 140 of file qlocale.cpp.

References QLocale::AnyCountry, c, code, and country_code_list.

Referenced by QLocale::name().

00141 {
00142     if (country == QLocale::AnyCountry)
00143         return QString();
00144 
00145     QString code;
00146     code.resize(2);
00147     const unsigned char *c = country_code_list + 2*(uint(country));
00148     code[0] = ushort(c[0]);
00149     code[1] = ushort(c[1]);
00150     return code;
00151 }

static Bigint* d2b ( double  d,
int *  e,
int *  bits 
) [static]

Definition at line 4758 of file qlocale.cpp.

References b, Balloc(), Bias, Exp_msk1, Exp_msk11, Exp_shift, Frac_mask, getWord0(), getWord1(), hi0bits(), int, Bigint::k, lo0bits(), P, setWord0(), ULong, x, and y.

Referenced by _qdtoa(), and qstrtod().

04759 {
04760     Bigint *b;
04761     int de, i, k;
04762     ULong *x, y, z;
04763 
04764 #ifdef Pack_32
04765     b = Balloc(1);
04766 #else
04767     b = Balloc(2);
04768 #endif
04769     x = b->x;
04770 
04771     z = getWord0(d) & Frac_mask;
04772     setWord0(&d, getWord0(d) & 0x7fffffff);        /* clear sign bit, which we ignore */
04773 #ifdef Sudden_Underflow
04774     de = (int)(getWord0(d) >> Exp_shift);
04775 #ifndef IBM
04776     z |= Exp_msk11;
04777 #endif
04778 #else
04779     if ((de = int(getWord0(d) >> Exp_shift)) != 0)
04780         z |= Exp_msk1;
04781 #endif
04782 #ifdef Pack_32
04783     if ((y = getWord1(d)) != 0) {
04784         if ((k = lo0bits(&y)) != 0) {
04785             x[0] = y | z << (32 - k);
04786             z >>= k;
04787         }
04788         else
04789             x[0] = y;
04790         i = b->wds = (x[1] = z) ? 2 : 1;
04791     }
04792     else {
04793 #ifdef BSD_QDTOA_DEBUG
04794         if (!z)
04795             Bug("Zero passed to d2b");
04796 #endif
04797         k = lo0bits(&z);
04798         x[0] = z;
04799         i = b->wds = 1;
04800         k += 32;
04801     }
04802 #else
04803     if (y = getWord1(d)) {
04804         if (k = lo0bits(&y))
04805             if (k >= 16) {
04806                 x[0] = y | z << 32 - k & 0xffff;
04807                 x[1] = z >> k - 16 & 0xffff;
04808                 x[2] = z >> k;
04809                 i = 2;
04810             }
04811             else {
04812                 x[0] = y & 0xffff;
04813                 x[1] = y >> 16 | z << 16 - k & 0xffff;
04814                 x[2] = z >> k & 0xffff;
04815                 x[3] = z >> k+16;
04816                 i = 3;
04817             }
04818         else {
04819             x[0] = y & 0xffff;
04820             x[1] = y >> 16;
04821             x[2] = z & 0xffff;
04822             x[3] = z >> 16;
04823             i = 3;
04824         }
04825     }
04826     else {
04827 #ifdef BSD_QDTOA_DEBUG
04828         if (!z)
04829             Bug("Zero passed to d2b");
04830 #endif
04831         k = lo0bits(&z);
04832         if (k >= 16) {
04833             x[0] = z;
04834             i = 0;
04835         }
04836         else {
04837             x[0] = z & 0xffff;
04838             x[1] = z >> 16;
04839             i = 1;
04840         }
04841         k += 32;
04842     }
04843     while(!x[i])
04844         --i;
04845     b->wds = i + 1;
04846 #endif
04847 #ifndef Sudden_Underflow
04848     if (de) {
04849 #endif
04850 #ifdef IBM
04851         *e = (de - Bias - (P-1) << 2) + k;
04852         *bits = 4*P + 8 - k - hi0bits(getWord0(d) & Frac_mask);
04853 #else
04854         *e = de - Bias - (P-1) + k;
04855         *bits = P - k;
04856 #endif
04857 #ifndef Sudden_Underflow
04858     }
04859     else {
04860         *e = de - Bias - (P-1) + 1 + k;
04861 #ifdef Pack_32
04862         *bits = 32*i - hi0bits(x[i-1]);
04863 #else
04864         *bits = (i+2)*16 - hi0bits(x[i]);
04865 #endif
04866     }
04867 #endif
04868     return b;
04869 }

Here is the call graph for this function:

static const QLocalePrivate* dataPointer ( void *  v  )  [static]

Definition at line 1855 of file qlocale.cpp.

References index, locale_data, and system_lp.

Referenced by QLocale::d().

01856 {
01857     quint16 index = reinterpret_cast<quintptr>(v) & 0xFFFF;
01858 
01859 #ifndef QT_NO_SYSTEMLOCALE
01860     Q_ASSERT(index <= locale_data_size);
01861     if (index == locale_data_size)
01862         return system_lp;
01863 #else
01864     Q_ASSERT(index < locale_data_size);
01865 #endif
01866 
01867     return &locale_data[index];
01868 }

static QString& decimalForm ( QString digits,
int  decpt,
uint  precision,
PrecisionMode  pm,
bool  always_show_decpt,
bool  thousands_group,
const QLocalePrivate locale 
) [static]

Definition at line 3068 of file qlocale.cpp.

References QString::append(), QLocalePrivate::decimal(), QLocalePrivate::group(), QString::insert(), QString::length(), PMDecimalDigits, PMSignificantDigits, QString::prepend(), and QLocalePrivate::zero().

Referenced by QLocalePrivate::doubleToString().

03073 {
03074     if (decpt < 0) {
03075         for (int i = 0; i < -decpt; ++i)
03076             digits.prepend(locale.zero());
03077         decpt = 0;
03078     }
03079     else if (decpt > digits.length()) {
03080         for (int i = digits.length(); i < decpt; ++i)
03081             digits.append(locale.zero());
03082     }
03083 
03084     if (pm == PMDecimalDigits) {
03085         uint decimal_digits = digits.length() - decpt;
03086         for (uint i = decimal_digits; i < precision; ++i)
03087             digits.append(locale.zero());
03088     }
03089     else if (pm == PMSignificantDigits) {
03090         for (uint i = digits.length(); i < precision; ++i)
03091             digits.append(locale.zero());
03092     }
03093     else { // pm == PMChopTrailingZeros
03094     }
03095 
03096     if (always_show_decpt || decpt < digits.length())
03097         digits.insert(decpt, locale.decimal());
03098 
03099     if (thousands_group) {
03100         for (int i = decpt - 3; i > 0; i -= 3)
03101             digits.insert(i, locale.group());
03102     }
03103 
03104     if (decpt == 0)
03105         digits.prepend(locale.zero());
03106 
03107     return digits;
03108 }

Here is the call graph for this function:

static const QLocalePrivate* defaultPrivate (  )  [static]

Definition at line 1247 of file qlocale.cpp.

References default_lp, and systemPrivate().

Referenced by QLocale::QLocale().

01248 {
01249     if (!default_lp)
01250         default_lp = systemPrivate();
01251     return default_lp;
01252 }

Here is the call graph for this function:

static Bigint* diff ( Bigint a,
Bigint b 
) [static]

Definition at line 4599 of file qlocale.cpp.

References a, b, Balloc(), c, cmp(), Long, Sign_Extend, Storeinc(), ULong, and y.

Referenced by _qdtoa(), QTextDocumentPrivate::adjustDocumentChangesAndCursors(), QAnimationWriter::appendFrame(), QKeySequence::assign(), Q3ListViewPrivate::SortableItem::cmp(), cmp(), QTextDocumentPrivate::documentChange(), QTextHtmlExporter::emitBlock(), QTextHtmlExporter::emitBlockAttributes(), Q3TextCursor::fixCursorPosition(), formatDifference(), QGradientCache::generateGradientColorTable(), Q3TextEdit::handleMouseMove(), Q3MainWindowLayout::layoutItems(), Q3DockArea::maxSpace(), Q3MainWindowLayout::minimumSize(), GLWidget::mouseMoveEvent(), QGraphicsItem::mouseMoveEvent(), QApplication::notify(), QDateTimeParser::parse(), Q3TextCursor::place(), qstrtod(), QDesignerActions::readInForm(), QRectF::setLeft(), QFragmentMapData::setSize(), QRectF::setTop(), qdesigner_internal::setTopMinMaxSize(), QComboBox::showPopup(), Q3MainWindowLayout::sizeHint(), qdesigner_internal::SetFormPropertyCommand::updateFormWindowGeometry(), SvgNativeView::wheelEvent(), SvgGLView::wheelEvent(), and SvgRasterView::wheelEvent().

04600 {
04601     Bigint *c;
04602     int i, wa, wb;
04603     Long borrow, y;        /* We need signed shifts here. */
04604     ULong *xa, *xae, *xb, *xbe, *xc;
04605 #ifdef Pack_32
04606     Long z;
04607 #endif
04608 
04609     i = cmp(a,b);
04610     if (!i) {
04611         c = Balloc(0);
04612         c->wds = 1;
04613         c->x[0] = 0;
04614         return c;
04615     }
04616     if (i < 0) {
04617         c = a;
04618         a = b;
04619         b = c;
04620         i = 1;
04621     }
04622     else
04623         i = 0;
04624     c = Balloc(a->k);
04625     c->sign = i;
04626     wa = a->wds;
04627     xa = a->x;
04628     xae = xa + wa;
04629     wb = b->wds;
04630     xb = b->x;
04631     xbe = xb + wb;
04632     xc = c->x;
04633     borrow = 0;
04634 #ifdef Pack_32
04635     do {
04636         y = (*xa & 0xffff) - (*xb & 0xffff) + borrow;
04637         borrow = y >> 16;
04638         Sign_Extend(borrow, y);
04639         z = (*xa++ >> 16) - (*xb++ >> 16) + borrow;
04640         borrow = z >> 16;
04641         Sign_Extend(borrow, z);
04642         Storeinc(xc, z, y);
04643     }
04644     while(xb < xbe);
04645     while(xa < xae) {
04646         y = (*xa & 0xffff) + borrow;
04647         borrow = y >> 16;
04648         Sign_Extend(borrow, y);
04649         z = (*xa++ >> 16) + borrow;
04650         borrow = z >> 16;
04651         Sign_Extend(borrow, z);
04652         Storeinc(xc, z, y);
04653     }
04654 #else
04655     do {
04656         y = *xa++ - *xb++ + borrow;
04657         borrow = y >> 16;
04658         Sign_Extend(borrow, y);
04659         *xc++ = y & 0xffff;
04660     }
04661     while(xb < xbe);
04662     while(xa < xae) {
04663         y = *xa++ + borrow;
04664         borrow = y >> 16;
04665         Sign_Extend(borrow, y);
04666         *xc++ = y & 0xffff;
04667     }
04668 #endif
04669     while(!*--xc)
04670         wa--;
04671     c->wds = wa;
04672     return c;
04673 }

Here is the call graph for this function:

static QByteArray envVarLocale (  )  [static]

Definition at line 279 of file qlocale.cpp.

References QByteArray::isNull(), and qgetenv().

Referenced by QSystemLocale::fallbackLocale().

00280 {
00281     static QByteArray lang = 0;
00282 #ifdef Q_OS_UNIX
00283     lang = qgetenv("LC_ALL");
00284     if (lang.isNull())
00285         lang = qgetenv("LC_NUMERIC");
00286     if (lang.isNull())
00287 #endif
00288         lang = qgetenv("LANG");
00289     return lang;
00290 }

Here is the call graph for this function:

static QString& exponentForm ( QString digits,
int  decpt,
uint  precision,
PrecisionMode  pm,
bool  always_show_decpt,
const QLocalePrivate locale 
) [static]

Definition at line 3110 of file qlocale.cpp.

References QLocalePrivate::AlwaysShowSign, QString::append(), QLocalePrivate::decimal(), QLocalePrivate::exponential(), QString::insert(), QString::length(), QLocalePrivate::longLongToString(), PMDecimalDigits, PMSignificantDigits, and QLocalePrivate::zero().

Referenced by QLocalePrivate::doubleToString().

03114 {
03115     int exp = decpt - 1;
03116 
03117     if (pm == PMDecimalDigits) {
03118         for (uint i = digits.length(); i < precision + 1; ++i)
03119             digits.append(locale.zero());
03120     }
03121     else if (pm == PMSignificantDigits) {
03122         for (uint i = digits.length(); i < precision; ++i)
03123             digits.append(locale.zero());
03124     }
03125     else { // pm == PMChopTrailingZeros
03126     }
03127 
03128     if (always_show_decpt || digits.length() > 1)
03129         digits.insert(1, locale.decimal());
03130 
03131     digits.append(locale.exponential());
03132     digits.append(locale.longLongToString(exp, 2, 10,
03133                     -1, QLocalePrivate::AlwaysShowSign));
03134 
03135     return digits;
03136 }

Here is the call graph for this function:

static const QLocalePrivate* findLocale ( const QString name  )  [static]

Definition at line 225 of file qlocale.cpp.

References findLocale(), getLangAndCountry(), and name.

00226 {
00227     QLocale::Language lang;
00228     QLocale::Country cntry;
00229     getLangAndCountry(name, lang, cntry);
00230 
00231     return findLocale(lang, cntry);
00232 }

Here is the call graph for this function:

static const QLocalePrivate* findLocale ( QLocale::Language  language,
QLocale::Country  country 
) [static]

Definition at line 153 of file qlocale.cpp.

References QLocale::AnyCountry, d, locale_data, and locale_index.

Referenced by findLocale(), and QLocale::QLocale().

00154 {
00155     unsigned language_id = language;
00156     unsigned country_id = country;
00157 
00158     uint idx = locale_index[language_id];
00159 
00160     const QLocalePrivate *d = locale_data + idx;
00161 
00162     if (idx == 0) // default language has no associated country
00163         return d;
00164 
00165     if (country == QLocale::AnyCountry)
00166         return d;
00167 
00168     Q_ASSERT(d->languageId() == language_id);
00169 
00170     while (d->languageId() == language_id
00171                 && d->countryId() != country_id)
00172         ++d;
00173 
00174     if (d->countryId() == country_id
00175             && d->languageId() == language_id)
00176         return d;
00177 
00178     return locale_data + idx;
00179 }

static void getLangAndCountry ( const QString name,
QLocale::Language lang,
QLocale::Country cntry 
) [static]

Definition at line 181 of file qlocale.cpp.

References QLocale::AnyCountry, QLocale::C, codeToCountry(), codeToLanguage(), l, and name.

Referenced by findLocale().

00182 {
00183     lang = QLocale::C;
00184     cntry = QLocale::AnyCountry;
00185 
00186     uint l = name.length();
00187 
00188     do {
00189         if (l < 2)
00190             break;
00191 
00192         const QChar *uc = name.unicode();
00193         if (l > 2
00194                 && uc[2] != QLatin1Char('_')
00195                 && uc[2] != QLatin1Char('.')
00196                 && uc[2] != QLatin1Char('@'))
00197             break;
00198 
00199         QChar lang_code[2];
00200         lang_code[0] = uc[0];
00201         lang_code[1] = uc[1];
00202         // CLDR has changed the code for Bokmal from "no" to "nb". We want to support
00203         // both, but we have no alias mechanism in the database.
00204         if (lang_code[0] == QLatin1Char('n') && lang_code[1] == QLatin1Char('b'))
00205             lang_code[1] = QLatin1Char('o');
00206         lang = codeToLanguage(lang_code);
00207         if (lang == QLocale::C)
00208             break;
00209 
00210         if (l == 2 || uc[2] == QLatin1Char('.') || uc[2] == QLatin1Char('@'))
00211             break;
00212 
00213         // we have uc[2] == '_'
00214         if (l < 5)
00215             break;
00216 
00217         if (l > 5 && uc[5] != QLatin1Char('.') && uc[5] != QLatin1Char('@'))
00218             break;
00219 
00220         cntry = codeToCountry(uc + 3);
00221     } while (false);
00222 
00223 }

Here is the call graph for this function:

static QString getLocaleListData ( const char *  data,
int  index 
) [static]

Definition at line 1254 of file qlocale.cpp.

References QString::fromUtf8().

Referenced by QLocale::dayName(), and QLocale::monthName().

01255 {
01256     while (index) {
01257         while (*data != ';')
01258             ++data;
01259         --index;
01260         ++data;
01261     }
01262     const char *end = data;
01263     while (*end != '\0' && *end != ';')
01264         ++end;
01265     return QString::fromUtf8(data, end - data);
01266 }

Here is the call graph for this function:

static ULong getWord0 ( const NEEDS_VOLATILE double  x  )  [inline, static]

Definition at line 4036 of file qlocale.cpp.

References NEEDS_VOLATILE, and ptr.

Referenced by _qdtoa(), d2b(), qstrtod(), ratio(), and ulp().

04037 {
04038     const NEEDS_VOLATILE uchar *ptr = reinterpret_cast<const NEEDS_VOLATILE uchar *>(&x);
04039     if (QSysInfo::ByteOrder == QSysInfo::BigEndian) {
04040         return (ptr[0]<<24) + (ptr[1]<<16) + (ptr[2]<<8) + ptr[3];
04041     } else {
04042         return (ptr[7]<<24) + (ptr[6]<<16) + (ptr[5]<<8) + ptr[4];
04043     }
04044 }

static ULong getWord1 ( const NEEDS_VOLATILE double  x  )  [inline, static]

Definition at line 4062 of file qlocale.cpp.

References NEEDS_VOLATILE, and ptr.

Referenced by _qdtoa(), d2b(), and qstrtod().

04063 {
04064     const NEEDS_VOLATILE uchar *ptr = reinterpret_cast<const NEEDS_VOLATILE uchar *>(&x);
04065     if (QSysInfo::ByteOrder == QSysInfo::BigEndian) {
04066         return (ptr[4]<<24) + (ptr[5]<<16) + (ptr[6]<<8) + ptr[7];
04067     } else {
04068         return (ptr[3]<<24) + (ptr[2]<<16) + (ptr[1]<<8) + ptr[0];
04069     }
04070 }

static int hi0bits ( ULong  x  )  [static]

Definition at line 4312 of file qlocale.cpp.

References Bigint::k.

Referenced by _qdtoa(), b2d(), and d2b().

04313 {
04314     int k = 0;
04315 
04316     if (!(x & 0xffff0000)) {
04317         k = 16;
04318         x <<= 16;
04319     }
04320     if (!(x & 0xff000000)) {
04321         k += 8;
04322         x <<= 8;
04323     }
04324     if (!(x & 0xf0000000)) {
04325         k += 4;
04326         x <<= 4;
04327     }
04328     if (!(x & 0xc0000000)) {
04329         k += 2;
04330         x <<= 2;
04331     }
04332     if (!(x & 0x80000000)) {
04333         k++;
04334         if (!(x & 0x40000000))
04335             return 32;
04336     }
04337     return k;
04338 }

static Bigint* i2b ( int  i  )  [static]

Definition at line 4382 of file qlocale.cpp.

References b, and Balloc().

Referenced by _qdtoa(), pow5mult(), and qstrtod().

04383 {
04384     Bigint *b;
04385 
04386     b = Balloc(1);
04387     b->x[0] = i;
04388     b->wds = 1;
04389     return b;
04390 }

Here is the call graph for this function:

static bool isZero ( double  d  )  [static]

Definition at line 3138 of file qlocale.cpp.

Referenced by QLocalePrivate::doubleToString(), isScalable(), and isSmoothlyScalable().

03139 {
03140     uchar *ch = (uchar *)&d;
03141     if (QSysInfo::ByteOrder == QSysInfo::BigEndian) {
03142         return !(ch[0] & 0x7F || ch[1] || ch[2] || ch[3] || ch[4] || ch[5] || ch[6] || ch[7]);
03143     } else {
03144         return !(ch[7] & 0x7F || ch[6] || ch[5] || ch[4] || ch[3] || ch[2] || ch[1] || ch[0]);
03145     }
03146 }

static QString languageToCode ( QLocale::Language  language  )  [static]

Definition at line 127 of file qlocale.cpp.

References c, QLocale::C, code, and language_code_list.

Referenced by QLocale::name().

00128 {
00129     if (language == QLocale::C)
00130         return QLatin1String("C");
00131 
00132     QString code;
00133     code.resize(2);
00134     const unsigned char *c = language_code_list + 2*(uint(language));
00135     code[0] = ushort(c[0]);
00136     code[1] = ushort(c[1]);
00137     return code;
00138 }

static int lo0bits ( ULong *  y  )  [static]

Definition at line 4340 of file qlocale.cpp.

References Bigint::k, ULong, and x.

Referenced by d2b().

04341 {
04342     int k;
04343     ULong x = *y;
04344 
04345     if (x & 7) {
04346         if (x & 1)
04347             return 0;
04348         if (x & 2) {
04349             *y = x >> 1;
04350             return 1;
04351         }
04352         *y = x >> 2;
04353         return 2;
04354     }
04355     k = 0;
04356     if (!(x & 0xffff)) {
04357         k = 16;
04358         x >>= 16;
04359     }
04360     if (!(x & 0xff)) {
04361         k += 8;
04362         x >>= 8;
04363     }
04364     if (!(x & 0xf)) {
04365         k += 4;
04366         x >>= 4;
04367     }
04368     if (!(x & 0x3)) {
04369         k += 2;
04370         x >>= 2;
04371     }
04372     if (!(x & 1)) {
04373         k++;
04374         x >>= 1;
04375         if (!x & 1)
04376             return 32;
04377     }
04378     *y = x;
04379     return k;
04380 }

static Bigint* lshift ( Bigint b,
int  k 
) [static]

Definition at line 4517 of file qlocale.cpp.

References b, Balloc(), Bfree(), n, ULong, Bigint::wds, Bigint::x, and x.

Referenced by _qdtoa(), and qstrtod().

04518 {
04519     int i, k1, n, n1;
04520     Bigint *b1;
04521     ULong *x, *x1, *xe, z;
04522 
04523 #ifdef Pack_32
04524     n = k >> 5;
04525 #else
04526     n = k >> 4;
04527 #endif
04528     k1 = b->k;
04529     n1 = n + b->wds + 1;
04530     for(i = b->maxwds; n1 > i; i <<= 1)
04531         k1++;
04532     b1 = Balloc(k1);
04533     x1 = b1->x;
04534     for(i = 0; i < n; i++)
04535         *x1++ = 0;
04536     x = b->x;
04537     xe = x + b->wds;
04538 #ifdef Pack_32
04539     if (k &= 0x1f) {
04540         k1 = 32 - k;
04541         z = 0;
04542         do {
04543             *x1++ = *x << k | z;
04544             z = *x++ >> k1;
04545         }
04546         while(x < xe);
04547         if ((*x1 = z) != 0)
04548             ++n1;
04549     }
04550 #else
04551     if (k &= 0xf) {
04552         k1 = 16 - k;
04553         z = 0;
04554         do {
04555             *x1++ = *x << k  & 0xffff | z;
04556             z = *x++ >> k1;
04557         }
04558         while(x < xe);
04559         if (*x1 = z)
04560             ++n1;
04561     }
04562 #endif
04563     else do
04564         *x1++ = *x++;
04565     while(x < xe);
04566     b1->wds = n1 - 1;
04567     Bfree(b);
04568     return b1;
04569 }

Here is the call graph for this function:

static Bigint* mult ( Bigint a,
Bigint b 
) [static]

Definition at line 4392 of file qlocale.cpp.

References a, b, Balloc(), c, Bigint::k, Storeinc(), ULong, x, and y.

Referenced by _qdtoa(), pow5mult(), and qstrtod().

04393 {
04394     Bigint *c;
04395     int k, wa, wb, wc;
04396     ULong carry, y, z;
04397     ULong *x, *xa, *xae, *xb, *xbe, *xc, *xc0;
04398 #ifdef Pack_32
04399     ULong z2;
04400 #endif
04401 
04402     if (a->wds < b->wds) {
04403         c = a;
04404         a = b;
04405         b = c;
04406     }
04407     k = a->k;
04408     wa = a->wds;
04409     wb = b->wds;
04410     wc = wa + wb;
04411     if (wc > a->maxwds)
04412         k++;
04413     c = Balloc(k);
04414     for(x = c->x, xa = x + wc; x < xa; x++)
04415         *x = 0;
04416     xa = a->x;
04417     xae = xa + wa;
04418     xb = b->x;
04419     xbe = xb + wb;
04420     xc0 = c->x;
04421 #ifdef Pack_32
04422     for(; xb < xbe; xb++, xc0++) {
04423         if ((y = *xb & 0xffff) != 0) {
04424             x = xa;
04425             xc = xc0;
04426             carry = 0;
04427             do {
04428                 z = (*x & 0xffff) * y + (*xc & 0xffff) + carry;
04429                 carry = z >> 16;
04430                 z2 = (*x++ >> 16) * y + (*xc >> 16) + carry;
04431                 carry = z2 >> 16;
04432                 Storeinc(xc, z2, z);
04433             }
04434             while(x < xae);
04435             *xc = carry;
04436         }
04437         if ((y = *xb >> 16) != 0) {
04438             x = xa;
04439             xc = xc0;
04440             carry = 0;
04441             z2 = *xc;
04442             do {
04443                 z = (*x & 0xffff) * y + (*xc >> 16) + carry;
04444                 carry = z >> 16;
04445                 Storeinc(xc, z, z2);
04446                 z2 = (*x++ >> 16) * y + (*xc & 0xffff) + carry;
04447                 carry = z2 >> 16;
04448             }
04449             while(x < xae);
04450             *xc = z2;
04451         }
04452     }
04453 #else
04454     for(; xb < xbe; xc0++) {
04455         if (y = *xb++) {
04456             x = xa;
04457             xc = xc0;
04458             carry = 0;
04459             do {
04460                 z = *x++ * y + *xc + carry;
04461                 carry = z >> 16;
04462                 *xc++ = z & 0xffff;
04463             }
04464             while(x < xae);
04465             *xc = carry;
04466         }
04467     }
04468 #endif
04469     for(xc0 = c->x, xc = xc0 + wc; wc > 0 && !*--xc; --wc) ;
04470     c->wds = wc;
04471     return c;
04472 }

Here is the call graph for this function:

static Bigint* multadd ( Bigint b,
int  m,
int  a 
) [static]

Definition at line 4241 of file qlocale.cpp.

References b, Balloc(), Bcopy, Bfree(), ULong, Bigint::wds, x, and y.

Referenced by _qdtoa(), pow5mult(), and s2b().

04242 {
04243     int i, wds;
04244     ULong *x, y;
04245 #ifdef Pack_32
04246     ULong xi, z;
04247 #endif
04248     Bigint *b1;
04249 
04250     wds = b->wds;
04251     x = b->x;
04252     i = 0;
04253     do {
04254 #ifdef Pack_32
04255         xi = *x;
04256         y = (xi & 0xffff) * m + a;
04257         z = (xi >> 16) * m + (y >> 16);
04258         a = (z >> 16);
04259         *x++ = (z << 16) + (y & 0xffff);
04260 #else
04261         y = *x * m + a;
04262         a = (y >> 16);
04263         *x++ = y & 0xffff;
04264 #endif
04265     }
04266     while(++i < wds);
04267     if (a) {
04268         if (wds >= b->maxwds) {
04269             b1 = Balloc(b->k+1);
04270             Bcopy(b1, b);
04271             Bfree(b);
04272             b = b1;
04273         }
04274         b->x[wds++] = a;
04275         b->wds = wds;
04276     }
04277     return b;
04278 }

Here is the call graph for this function:

static int numberOptions ( void *  v  )  [static]

Definition at line 1870 of file qlocale.cpp.

01871 {
01872     quint16 opt = (reinterpret_cast<quintptr>(v) >> 16) & 0xFFFF;
01873 
01874     return opt;
01875 }

QDataStream& operator<< ( QDataStream ds,
const QLocale l 
)

Definition at line 1270 of file qlocale.cpp.

01271 {
01272     ds << l.name();
01273     return ds;
01274 }

QDataStream& operator>> ( QDataStream ds,
QLocale l 
)

Definition at line 1276 of file qlocale.cpp.

01277 {
01278     QString s;
01279     ds >> s;
01280     l = QLocale(s);
01281     return ds;
01282 }

static Bigint* pow5mult ( Bigint b,
int  k 
) [static]

Definition at line 4476 of file qlocale.cpp.

References b, Bfree(), i2b(), mult(), multadd(), Bigint::next, p, and p5s.

Referenced by _qdtoa(), and qstrtod().

04477 {
04478     Bigint *b1, *p5, *p51;
04479     int i;
04480     static const int p05[3] = { 5, 25, 125 };
04481 
04482     if ((i = k & 3) != 0)
04483 #if defined(Q_OS_IRIX) && defined(Q_CC_GNU)
04484     {
04485         // work around a bug on 64 bit IRIX gcc
04486         int *p = (int *) p05;
04487         b = multadd(b, p[i-1], 0);
04488     }
04489 #else
04490     b = multadd(b, p05[i-1], 0);
04491 #endif
04492 
04493     if (!(k >>= 2))
04494         return b;
04495     if (!(p5 = p5s)) {
04496         /* first time */
04497         p5 = p5s = i2b(625);
04498         p5->next = 0;
04499     }
04500     for(;;) {
04501         if (k & 1) {
04502             b1 = mult(b, p5);
04503             Bfree(b);
04504             b = b1;
04505         }
04506         if (!(k >>= 1))
04507             break;
04508         if (!(p51 = p5->next)) {
04509             p51 = p5->next = mult(p5,p5);
04510             p51->next = 0;
04511         }
04512         p5 = p51;
04513     }
04514     return b;
04515 }

Here is the call graph for this function:

static char * qdtoa ( double  d,
int  mode,
int  ndigits,
int *  decpt,
int *  sign,
char **  rve,
char **  digits_str 
) [static]

Definition at line 5636 of file qlocale.cpp.

References _qdtoa(), and s.

Referenced by QLocalePrivate::doubleToString().

05637 {
05638     // Some values of the floating-point control word can cause _qdtoa to crash with an underflow.
05639     // We set a safe value here.
05640 #ifdef Q_OS_WIN
05641     _clear87();
05642     unsigned int oldbits = _control87(0, 0);
05643 #ifndef MCW_EM
05644 #    ifdef _MCW_EM
05645 #        define MCW_EM _MCW_EM
05646 #    else
05647 #        define MCW_EM 0x0008001F
05648 #    endif
05649 #endif
05650     _control87(MCW_EM, MCW_EM);
05651 #endif
05652 
05653 #if defined(Q_OS_LINUX) && !defined(__UCLIBC__)
05654     fenv_t envp;
05655     feholdexcept(&envp);
05656 #endif
05657 
05658     char *s = _qdtoa(d, mode, ndigits, decpt, sign, rve, resultp);
05659 
05660 #ifdef Q_OS_WIN
05661     _clear87();
05662 #ifndef _M_X64
05663     _control87(oldbits, 0xFFFFF);
05664 #else
05665     _control87(oldbits, _MCW_EM|_MCW_DN|_MCW_RC);
05666 #endif //_M_X64
05667 #endif //Q_OS_WIN
05668 
05669 #if defined(Q_OS_LINUX) && !defined(__UCLIBC__)
05670     fesetenv(&envp);
05671 #endif
05672 
05673     return s;
05674 }

Here is the call graph for this function:

static bool qIsUpper ( char  c  )  [static]

Definition at line 2833 of file qlocale.cpp.

02834 {
02835     return c >= 'A' && c <= 'Z';
02836 }

static QString qlltoa ( qlonglong  l,
int  base,
const QLocalePrivate locale 
) [static]

Definition at line 3057 of file qlocale.cpp.

References qulltoa().

03058 {
03059     return qulltoa(l < 0 ? -l : l, base, locale);
03060 }

Here is the call graph for this function:

static double qstrtod ( const char *  s00,
char const **  se,
bool *  ok 
) [static]

Definition at line 4942 of file qlocale.cpp.

References Balloc(), Bcopy, Bfree(), Bias, Big0, Big1, Bndry_mask, Bndry_mask1, c, cmp(), d2b(), DBL_DIG, diff(), Emin, Exp_mask, Exp_msk1, getWord0(), getWord1(), i2b(), int, j, Bigint::k, L, Log2P, Long, LSB, lshift(), mult(), n_bigtens, NULL, P, pow5mult(), ratio(), rounded_product, rounded_quotient, s, s1, s2b(), setWord0(), setWord1(), sign(), t, Ten_pmax, Tiny0, Tiny1, ULong, ulp(), and y.

Referenced by QLocalePrivate::bytearrayToDouble().

04943 {
04944     int bb2, bb5, bbe, bd2, bd5, bbbits, bs2, c, dsign,
04945         e, e1, esign, i, j, k, nd, nd0, nf, nz, nz0, sign;
04946     const char *s, *s0, *s1;
04947     double aadj, aadj1, adj, rv, rv0;
04948     Long L;
04949     ULong y, z;
04950     Bigint *bb1, *bd0;
04951     Bigint *bb = NULL, *bd = NULL, *bs = NULL, *delta = NULL;/* pacify gcc */
04952 
04953     /*
04954       #ifndef KR_headers
04955       const char decimal_point = localeconv()->decimal_point[0];
04956       #else
04957       const char decimal_point = '.';
04958       #endif */
04959     if (ok != 0)
04960         *ok = true;
04961 
04962     const char decimal_point = '.';
04963 
04964     sign = nz0 = nz = 0;
04965     rv = 0.;
04966 
04967 
04968     for(s = s00; isspace(uchar(*s)); s++)
04969         ;
04970 
04971     if (*s == '-') {
04972         sign = 1;
04973         s++;
04974     } else if (*s == '+') {
04975         s++;
04976     }
04977 
04978     if (*s == '\0') {
04979         s = s00;
04980         goto ret;
04981     }
04982 
04983     if (*s == '0') {
04984         nz0 = 1;
04985         while(*++s == '0') ;
04986         if (!*s)
04987             goto ret;
04988     }
04989     s0 = s;
04990     y = z = 0;
04991     for(nd = nf = 0; (c = *s) >= '0' && c <= '9'; nd++, s++)
04992         if (nd < 9)
04993             y = 10*y + c - '0';
04994         else if (nd < 16)
04995             z = 10*z + c - '0';
04996     nd0 = nd;
04997     if (c == decimal_point) {
04998         c = *++s;
04999         if (!nd) {
05000             for(; c == '0'; c = *++s)
05001                 nz++;
05002             if (c > '0' && c <= '9') {
05003                 s0 = s;
05004                 nf += nz;
05005                 nz = 0;
05006                 goto have_dig;
05007             }
05008             goto dig_done;
05009         }
05010         for(; c >= '0' && c <= '9'; c = *++s) {
05011         have_dig:
05012             nz++;
05013             if (c -= '0') {
05014                 nf += nz;
05015                 for(i = 1; i < nz; i++)
05016                     if (nd++ < 9)
05017                         y *= 10;
05018                     else if (nd <= DBL_DIG + 1)
05019                         z *= 10;
05020                 if (nd++ < 9)
05021                     y = 10*y + c;
05022                 else if (nd <= DBL_DIG + 1)
05023                     z = 10*z + c;
05024                 nz = 0;
05025             }
05026         }
05027     }
05028  dig_done:
05029     e = 0;
05030     if (c == 'e' || c == 'E') {
05031         if (!nd && !nz && !nz0) {
05032             s = s00;
05033             goto ret;
05034         }
05035         s00 = s;
05036         esign = 0;
05037         switch(c = *++s) {
05038         case '-':
05039             esign = 1;
05040         case '+':
05041             c = *++s;
05042         }
05043         if (c >= '0' && c <= '9') {
05044             while(c == '0')
05045                 c = *++s;
05046             if (c > '0' && c <= '9') {
05047                 L = c - '0';
05048                 s1 = s;
05049                 while((c = *++s) >= '0' && c <= '9')
05050                     L = 10*L + c - '0';
05051                 if (s - s1 > 8 || L > 19999)
05052                     /* Avoid confusion from exponents
05053                      * so large that e might overflow.
05054                      */
05055                     e = 19999; /* safe for 16 bit ints */
05056                 else
05057                     e = int(L);
05058                 if (esign)
05059                     e = -e;
05060             }
05061             else
05062                 e = 0;
05063         }
05064         else
05065             s = s00;
05066     }
05067     if (!nd) {
05068         if (!nz && !nz0)
05069             s = s00;
05070         goto ret;
05071     }
05072     e1 = e -= nf;
05073 
05074     /* Now we have nd0 digits, starting at s0, followed by a
05075      * decimal point, followed by nd-nd0 digits.  The number we're
05076      * after is the integer represented by those digits times
05077      * 10**e */
05078 
05079     if (!nd0)
05080         nd0 = nd;
05081     k = nd < DBL_DIG + 1 ? nd : DBL_DIG + 1;
05082     rv = y;
05083     if (k > 9)
05084 #if defined(Q_OS_IRIX) && defined(Q_CC_GNU)
05085     {
05086         // work around a bug on 64 bit IRIX gcc
05087         double *t = (double *) tens;
05088         rv = t[k - 9] * rv + z;
05089     }
05090 #else
05091     rv = tens[k - 9] * rv + z;
05092 #endif
05093 
05094     bd0 = 0;
05095     if (nd <= DBL_DIG
05096 #ifndef RND_PRODQUOT
05097         && FLT_ROUNDS == 1
05098 #endif
05099         ) {
05100         if (!e)
05101             goto ret;
05102         if (e > 0) {
05103             if (e <= Ten_pmax) {
05104 #ifdef VAX
05105                 goto vax_ovfl_check;
05106 #else
05107                 /* rv = */ rounded_product(rv, tens[e]);
05108                 goto ret;
05109 #endif
05110             }
05111             i = DBL_DIG - nd;
05112             if (e <= Ten_pmax + i) {
05113                 /* A fancier test would sometimes let us do
05114                  * this for larger i values.
05115                  */
05116                 e -= i;
05117                 rv *= tens[i];
05118 #ifdef VAX
05119                 /* VAX exponent range is so narrow we must
05120                  * worry about overflow here...
05121                  */
05122             vax_ovfl_check:
05123                 setWord0(&rv, getWord0(rv) - P*Exp_msk1);
05124                 /* rv = */ rounded_product(rv, tens[e]);
05125                 if ((getWord0(rv) & Exp_mask)
05126                     > Exp_msk1*(DBL_MAX_EXP+Bias-1-P))
05127                     goto ovfl;
05128                 setWord0(&rv, getWord0(rv) + P*Exp_msk1);
05129 #else
05130                 /* rv = */ rounded_product(rv, tens[e]);
05131 #endif
05132                 goto ret;
05133             }
05134         }
05135 #ifndef Inaccurate_Divide
05136         else if (e >= -Ten_pmax) {
05137             /* rv = */ rounded_quotient(rv, tens[-e]);
05138             goto ret;
05139         }
05140 #endif
05141     }
05142     e1 += nd - k;
05143 
05144     /* Get starting approximation = rv * 10**e1 */
05145 
05146     if (e1 > 0) {
05147         if ((i = e1 & 15) != 0)
05148             rv *= tens[i];
05149         if (e1 &= ~15) {
05150             if (e1 > DBL_MAX_10_EXP) {
05151             ovfl:
05152                 //                                errno = ERANGE;
05153                 if (ok != 0)
05154                     *ok = false;
05155 #ifdef __STDC__
05156                 rv = HUGE_VAL;
05157 #else
05158                 /* Can't trust HUGE_VAL */
05159 #ifdef IEEE_Arith
05160                 setWord0(&rv, Exp_mask);
05161                 setWord1(&rv, 0);
05162 #else
05163                 setWord0(&rv, Big0);
05164                 setWord1(&rv, Big1);
05165 #endif
05166 #endif
05167                 if (bd0)
05168                     goto retfree;
05169                 goto ret;
05170             }
05171             if (e1 >>= 4) {
05172                 for(j = 0; e1 > 1; j++, e1 >>= 1)
05173                     if (e1 & 1)
05174                         rv *= bigtens[j];
05175                 /* The last multiplication could overflow. */
05176                 setWord0(&rv, getWord0(rv) - P*Exp_msk1);
05177                 rv *= bigtens[j];
05178                 if ((z = getWord0(rv) & Exp_mask)
05179                     > Exp_msk1*(DBL_MAX_EXP+Bias-P))
05180                     goto ovfl;
05181                 if (z > Exp_msk1*(DBL_MAX_EXP+Bias-1-P)) {
05182                     /* set to largest number */
05183                     /* (Can't trust DBL_MAX) */
05184                     setWord0(&rv, Big0);
05185                     setWord1(&rv, Big1);
05186                 }
05187                 else
05188                     setWord0(&rv, getWord0(rv) + P*Exp_msk1);
05189             }
05190 
05191         }
05192     }
05193     else if (e1 < 0) {
05194         e1 = -e1;
05195         if ((i = e1 & 15) != 0)
05196             rv /= tens[i];
05197         if (e1 &= ~15) {
05198             e1 >>= 4;
05199             if (e1 >= 1 << n_bigtens)
05200                 goto undfl;
05201             for(j = 0; e1 > 1; j++, e1 >>= 1)
05202                 if (e1 & 1)
05203                     rv *= tinytens[j];
05204             /* The last multiplication could underflow. */
05205             rv0 = rv;
05206             rv *= tinytens[j];
05207             if (rv == g_double_zero)
05208                 {
05209                     rv = 2.*rv0;
05210                     rv *= tinytens[j];
05211                     if (rv == g_double_zero)
05212                         {
05213                         undfl:
05214                             rv = 0.;
05215                             //                                        errno = ERANGE;
05216                             if (ok != 0)
05217                                 *ok = false;
05218                             if (bd0)
05219                                 goto retfree;
05220                             goto ret;
05221                         }
05222                     setWord0(&rv, Tiny0);
05223                     setWord1(&rv, Tiny1);
05224                     /* The refinement below will clean
05225                      * this approximation up.
05226                      */
05227                 }
05228         }
05229     }
05230 
05231     /* Now the hard part -- adjusting rv to the correct value.*/
05232 
05233     /* Put digits into bd: true value = bd * 10^e */
05234 
05235     bd0 = s2b(s0, nd0, nd, y);
05236 
05237     for(;;) {
05238         bd = Balloc(bd0->k);
05239         Bcopy(bd, bd0);
05240         bb = d2b(rv, &bbe, &bbbits);        /* rv = bb * 2^bbe */
05241         bs = i2b(1);
05242 
05243         if (e >= 0) {
05244             bb2 = bb5 = 0;
05245             bd2 = bd5 = e;
05246         }
05247         else {
05248             bb2 = bb5 = -e;
05249             bd2 = bd5 = 0;
05250         }
05251         if (bbe >= 0)
05252             bb2 += bbe;
05253         else
05254             bd2 -= bbe;
05255         bs2 = bb2;
05256 #ifdef Sudden_Underflow
05257 #ifdef IBM
05258         j = 1 + 4*P - 3 - bbbits + ((bbe + bbbits - 1) & 3);
05259 #else
05260         j = P + 1 - bbbits;
05261 #endif
05262 #else
05263         i = bbe + bbbits - 1;        /* logb(rv) */
05264         if (i < Emin)        /* denormal */
05265             j = bbe + (P-Emin);
05266         else
05267             j = P + 1 - bbbits;
05268 #endif
05269         bb2 += j;
05270         bd2 += j;
05271         i = bb2 < bd2 ? bb2 : bd2;
05272         if (i > bs2)
05273             i = bs2;
05274         if (i > 0) {
05275             bb2 -= i;
05276             bd2 -= i;
05277             bs2 -= i;
05278         }
05279         if (bb5 > 0) {
05280             bs = pow5mult(bs, bb5);
05281             bb1 = mult(bs, bb);
05282             Bfree(bb);
05283             bb = bb1;
05284         }
05285         if (bb2 > 0)
05286             bb = lshift(bb, bb2);
05287         if (bd5 > 0)
05288             bd = pow5mult(bd, bd5);
05289         if (bd2 > 0)
05290             bd = lshift(bd, bd2);
05291         if (bs2 > 0)
05292             bs = lshift(bs, bs2);
05293         delta = diff(bb, bd);
05294         dsign = delta->sign;
05295         delta->sign = 0;
05296         i = cmp(delta, bs);
05297         if (i < 0) {
05298             /* Error is less than half an ulp -- check for
05299              * special case of mantissa a power of two.
05300              */
05301             if (dsign || getWord1(rv) || getWord0(rv) & Bndry_mask)
05302                 break;
05303             delta = lshift(delta,Log2P);
05304             if (cmp(delta, bs) > 0)
05305                 goto drop_down;
05306             break;
05307         }
05308         if (i == 0) {
05309             /* exactly half-way between */
05310             if (dsign) {
05311                 if ((getWord0(rv) & Bndry_mask1) == Bndry_mask1
05312                     &&  getWord1(rv) == 0xffffffff) {
05313                     /*boundary case -- increment exponent*/
05314                     setWord0(&rv, (getWord0(rv) & Exp_mask)
05315                                 + Exp_msk1
05316 #ifdef IBM
05317                                 | Exp_msk1 >> 4
05318 #endif
05319                                 );
05320                     setWord1(&rv, 0);
05321                     break;
05322                 }
05323             }
05324             else if (!(getWord0(rv) & Bndry_mask) && !getWord1(rv)) {
05325             drop_down:
05326                 /* boundary case -- decrement exponent */
05327 #ifdef Sudden_Underflow
05328                 L = getWord0(rv) & Exp_mask;
05329 #ifdef IBM
05330                 if (L <  Exp_msk1)
05331 #else
05332                     if (L <= Exp_msk1)
05333 #endif
05334                         goto undfl;
05335                 L -= Exp_msk1;
05336 #else
05337                 L = (getWord0(rv) & Exp_mask) - Exp_msk1;
05338 #endif
05339                 setWord0(&rv, L | Bndry_mask1);
05340                 setWord1(&rv, 0xffffffff);
05341 #ifdef IBM
05342                 goto cont;
05343 #else
05344                 break;
05345 #endif
05346             }
05347 #ifndef ROUND_BIASED
05348             if (!(getWord1(rv) & LSB))
05349                 break;
05350 #endif
05351             if (dsign)
05352                 rv += ulp(rv);
05353 #ifndef ROUND_BIASED
05354             else {
05355                 rv -= ulp(rv);
05356 #ifndef Sudden_Underflow
05357                 if (rv == g_double_zero)
05358                     goto undfl;
05359 #endif
05360             }
05361 #endif
05362             break;
05363         }
05364         if ((aadj = ratio(delta, bs)) <= 2.) {
05365             if (dsign)
05366                 aadj = aadj1 = 1.;
05367             else if (getWord1(rv) || getWord0(rv) & Bndry_mask) {
05368 #ifndef Sudden_Underflow
05369                 if (getWord1(rv) == Tiny1 && !getWord0(rv))
05370                     goto undfl;
05371 #endif
05372                 aadj = 1.;
05373                 aadj1 = -1.;
05374             }
05375             else {
05376                 /* special case -- power of FLT_RADIX to be */
05377                 /* rounded down... */
05378 
05379                 if (aadj < 2./FLT_RADIX)
05380                     aadj = 1./FLT_RADIX;
05381                 else
05382                     aadj *= 0.5;
05383                 aadj1 = -aadj;
05384             }
05385         }
05386         else {
05387             aadj *= 0.5;
05388             aadj1 = dsign ? aadj : -aadj;
05389 #ifdef Check_FLT_ROUNDS
05390             switch(FLT_ROUNDS) {
05391             case 2: /* towards +infinity */
05392                 aadj1 -= 0.5;
05393                 break;
05394             case 0: /* towards 0 */
05395             case 3: /* towards -infinity */
05396                 aadj1 += 0.5;
05397             }
05398 #else
05399             if (FLT_ROUNDS == 0)
05400                 aadj1 += 0.5;
05401 #endif
05402         }
05403         y = getWord0(rv) & Exp_mask;
05404 
05405         /* Check for overflow */
05406 
05407         if (y == Exp_msk1*(DBL_MAX_EXP+Bias-1)) {
05408             rv0 = rv;
05409             setWord0(&rv, getWord0(rv) - P*Exp_msk1);
05410             adj = aadj1 * ulp(rv);
05411             rv += adj;
05412             if ((getWord0(rv) & Exp_mask) >=
05413                 Exp_msk1*(DBL_MAX_EXP+Bias-P)) {
05414                 if (getWord0(rv0) == Big0 && getWord1(rv0) == Big1)
05415                     goto ovfl;
05416                 setWord0(&rv, Big0);
05417                 setWord1(&rv, Big1);
05418                 goto cont;
05419             }
05420             else
05421                 setWord0(&rv, getWord0(rv) + P*Exp_msk1);
05422         }
05423         else {
05424 #ifdef Sudden_Underflow
05425             if ((getWord0(rv) & Exp_mask) <= P*Exp_msk1) {
05426                 rv0 = rv;
05427                 setWord0(&rv, getWord0(rv) + P*Exp_msk1);
05428                 adj = aadj1 * ulp(rv);
05429                 rv += adj;
05430 #ifdef IBM
05431                 if ((getWord0(rv) & Exp_mask) <  P*Exp_msk1)
05432 #else
05433                     if ((getWord0(rv) & Exp_mask) <= P*Exp_msk1)
05434 #endif
05435                         {
05436                             if (getWord0(rv0) == Tiny0
05437                                 && getWord1(rv0) == Tiny1)
05438                                 goto undfl;
05439                             setWord0(&rv, Tiny0);
05440                             setWord1(&rv, Tiny1);
05441                             goto cont;
05442                         }
05443                     else
05444                         setWord0(&rv, getWord0(rv) - P*Exp_msk1);
05445             }
05446             else {
05447                 adj = aadj1 * ulp(rv);
05448                 rv += adj;
05449             }
05450 #else
05451             /* Compute adj so that the IEEE rounding rules will
05452              * correctly round rv + adj in some half-way cases.
05453              * If rv * ulp(rv) is denormalized (i.e.,
05454              * y <= (P-1)*Exp_msk1), we must adjust aadj to avoid
05455              * trouble from bits lost to denormalization;
05456              * example: 1.2e-307 .
05457              */
05458             if (y <= (P-1)*Exp_msk1 && aadj >= 1.) {
05459                 aadj1 = int(aadj + 0.5);
05460                 if (!dsign)
05461                     aadj1 = -aadj1;
05462             }
05463             adj = aadj1 * ulp(rv);
05464             rv += adj;
05465 #endif
05466         }
05467         z = getWord0(rv) & Exp_mask;
05468         if (y == z) {
05469             /* Can we stop now? */
05470             L = Long(aadj);
05471             aadj -= L;
05472             /* The tolerances below are conservative. */
05473             if (dsign || getWord1(rv) || getWord0(rv) & Bndry_mask) {
05474                 if (aadj < .4999999 || aadj > .5000001)
05475                     break;
05476             }
05477             else if (aadj < .4999999/FLT_RADIX)
05478                 break;
05479         }
05480     cont:
05481         Bfree(bb);
05482         Bfree(bd);
05483         Bfree(bs);
05484         Bfree(delta);
05485     }
05486  retfree:
05487     Bfree(bb);
05488     Bfree(bd);
05489     Bfree(bs);
05490     Bfree(bd0);
05491     Bfree(delta);
05492  ret:
05493     if (se)
05494         *se = s;
05495     return sign ? -rv : rv;
05496 }

Here is the call graph for this function:

static qlonglong qstrtoll ( const char *  nptr,
const char **  endptr,
register int  base,
bool *  ok 
) [static]

Definition at line 3820 of file qlocale.cpp.

References c, LLONG_MAX, LLONG_MIN, and s.

Referenced by QLocalePrivate::bytearrayToLongLong().

03821 {
03822     register const char *s;
03823     register qulonglong acc;
03824     register unsigned char c;
03825     register qulonglong qbase, cutoff;
03826     register int neg, any, cutlim;
03827 
03828     if (ok != 0)
03829         *ok = true;
03830 
03831     /*
03832      * Skip white space and pick up leading +/- sign if any.
03833      * If base is 0, allow 0x for hex and 0 for octal, else
03834      * assume decimal; if base is already 16, allow 0x.
03835      */
03836     s = nptr;
03837     do {
03838         c = *s++;
03839     } while (isspace(c));
03840     if (c == '-') {
03841         neg = 1;
03842         c = *s++;
03843     } else {
03844         neg = 0;
03845         if (c == '+')
03846             c = *s++;
03847     }
03848     if ((base == 0 || base == 16) &&
03849         c == '0' && (*s == 'x' || *s == 'X')) {
03850         c = s[1];
03851         s += 2;
03852         base = 16;
03853     }
03854     if (base == 0)
03855         base = c == '0' ? 8 : 10;
03856 
03857     /*
03858      * Compute the cutoff value between legal numbers and illegal
03859      * numbers.  That is the largest legal value, divided by the
03860      * base.  An input number that is greater than this value, if
03861      * followed by a legal input character, is too big.  One that
03862      * is equal to this value may be valid or not; the limit
03863      * between valid and invalid numbers is then based on the last
03864      * digit.  For instance, if the range for quads is
03865      * [-9223372036854775808..9223372036854775807] and the input base
03866      * is 10, cutoff will be set to 922337203685477580 and cutlim to
03867      * either 7 (neg==0) or 8 (neg==1), meaning that if we have
03868      * accumulated a value > 922337203685477580, or equal but the
03869      * next digit is > 7 (or 8), the number is too big, and we will
03870      * return a range error.
03871      *
03872      * Set any if any `digits' consumed; make it negative to indicate
03873      * overflow.
03874      */
03875     qbase = unsigned(base);
03876     cutoff = neg ? qulonglong(0-(LLONG_MIN + LLONG_MAX)) + LLONG_MAX : LLONG_MAX;
03877     cutlim = cutoff % qbase;
03878     cutoff /= qbase;
03879     for (acc = 0, any = 0;; c = *s++) {
03880         if (!isascii(c))
03881             break;
03882         if (isdigit(c))
03883             c -= '0';
03884         else if (isalpha(c))
03885             c -= isupper(c) ? 'A' - 10 : 'a' - 10;
03886         else
03887             break;
03888         if (c >= base)
03889             break;
03890         if (any < 0 || acc > cutoff || (acc == cutoff && c > cutlim))
03891             any = -1;
03892         else {
03893             any = 1;
03894             acc *= qbase;
03895             acc += c;
03896         }
03897     }
03898     if (any < 0) {
03899         acc = neg ? LLONG_MIN : LLONG_MAX;
03900         if (ok != 0)
03901             *ok = false;
03902     } else if (neg) {
03903         acc = (~acc) + 1;
03904     }
03905     if (endptr != 0)
03906         *endptr = (any ? s - 1 : nptr);
03907     return acc;
03908 }

static qulonglong qstrtoull ( const char *  nptr,
const char **  endptr,
register int  base,
bool *  ok 
) [static]

Definition at line 3739 of file qlocale.cpp.

References c, s, and ULLONG_MAX.

Referenced by QLocalePrivate::bytearrayToUnsLongLong().

03740 {
03741     register const char *s = nptr;
03742     register qulonglong acc;
03743     register unsigned char c;
03744     register qulonglong qbase, cutoff;
03745     register int any, cutlim;
03746 
03747     if (ok != 0)
03748         *ok = true;
03749 
03750     /*
03751      * See strtoq for comments as to the logic used.
03752      */
03753     s = nptr;
03754     do {
03755         c = *s++;
03756     } while (isspace(c));
03757     if (c == '-') {
03758         if (ok != 0)
03759             *ok = false;
03760         if (endptr != 0)
03761             *endptr = s - 1;
03762         return 0;
03763     } else {
03764         if (c == '+')
03765             c = *s++;
03766     }
03767     if ((base == 0 || base == 16) &&
03768         c == '0' && (*s == 'x' || *s == 'X')) {
03769         c = s[1];
03770         s += 2;
03771         base = 16;
03772     }
03773     if (base == 0)
03774         base = c == '0' ? 8 : 10;
03775     qbase = unsigned(base);
03776     cutoff = qulonglong(ULLONG_MAX) / qbase;
03777     cutlim = qulonglong(ULLONG_MAX) % qbase;
03778     for (acc = 0, any = 0;; c = *s++) {
03779         if (!isascii(c))
03780             break;
03781         if (isdigit(c))
03782             c -= '0';
03783         else if (isalpha(c))
03784             c -= isupper(c) ? 'A' - 10 : 'a' - 10;
03785         else
03786             break;
03787         if (c >= base)
03788             break;
03789         if (any < 0 || acc > cutoff || (acc == cutoff && c > cutlim))
03790             any = -1;
03791         else {
03792             any = 1;
03793             acc *= qbase;
03794             acc += c;
03795         }
03796     }
03797     if (any == 0) {
03798         if (ok != 0)
03799             *ok = false;
03800     } else if (any < 0) {
03801         acc = ULLONG_MAX;
03802         if (ok != 0)
03803             *ok = false;
03804     }
03805     if (endptr != 0)
03806         *endptr = (any ? s - 1 : nptr);
03807     return acc;
03808 }

static char qToLower ( char  c  )  [static]

Definition at line 2838 of file qlocale.cpp.

02839 {
02840     if (c >= 'A' && c <= 'Z')
02841         return c - 'A' + 'a';
02842     else
02843         return c;
02844 }

static QString qulltoa ( qulonglong  l,
int  base,
const QLocalePrivate locale 
) [static]

Definition at line 3024 of file qlocale.cpp.

References c, p, QChar::unicode(), and QLocalePrivate::zero().

Referenced by qlltoa().

03025 {
03026     ushort buff[65]; // length of MAX_ULLONG in base 2
03027     ushort *p = buff + 65;
03028     const QChar _zero = locale.zero();
03029 
03030     if (base != 10 || _zero.unicode() == '0') {
03031         while (l != 0) {
03032             int c = l % base;
03033 
03034             --p;
03035 
03036             if (c < 10)
03037                 *p = '0' + c;
03038             else
03039                 *p = c - 10 + 'a';
03040 
03041             l /= base;
03042         }
03043     }
03044     else {
03045         while (l != 0) {
03046             int c = l % base;
03047 
03048             *(--p) = _zero.unicode() + c;
03049 
03050             l /= base;
03051         }
03052     }
03053 
03054     return QString(reinterpret_cast<QChar *>(p), 65 - (p - buff));
03055 }

Here is the call graph for this function:

static int quorem ( Bigint b,
Bigint S 
) [static]

Definition at line 5498 of file qlocale.cpp.

References b, cmp(), Long, n, QCss::S, Sign_Extend, Storeinc(), ULong, and y.

Referenced by _qdtoa().

05499 {
05500     int n;
05501     Long borrow, y;
05502     ULong carry, q, ys;
05503     ULong *bx, *bxe, *sx, *sxe;
05504 #ifdef Pack_32
05505     Long z;
05506     ULong si, zs;
05507 #endif
05508 
05509     n = S->wds;
05510 #ifdef BSD_QDTOA_DEBUG
05511     /*debug*/ if (b->wds > n)
05512         /*debug*/        Bug("oversize b in quorem");
05513 #endif
05514     if (b->wds < n)
05515         return 0;
05516     sx = S->x;
05517     sxe = sx + --n;
05518     bx = b->x;
05519     bxe = bx + n;
05520     q = *bxe / (*sxe + 1);        /* ensure q <= true quotient */
05521 #ifdef BSD_QDTOA_DEBUG
05522     /*debug*/ if (q > 9)
05523         /*debug*/        Bug("oversized quotient in quorem");
05524 #endif
05525     if (q) {
05526         borrow = 0;
05527         carry = 0;
05528         do {
05529 #ifdef Pack_32
05530             si = *sx++;
05531             ys = (si & 0xffff) * q + carry;
05532             zs = (si >> 16) * q + (ys >> 16);
05533             carry = zs >> 16;
05534             y = (*bx & 0xffff) - (ys & 0xffff) + borrow;
05535             borrow = y >> 16;
05536             Sign_Extend(borrow, y);
05537             z = (*bx >> 16) - (zs & 0xffff) + borrow;
05538             borrow = z >> 16;
05539             Sign_Extend(borrow, z);
05540             Storeinc(bx, z, y);
05541 #else
05542             ys = *sx++ * q + carry;
05543             carry = ys >> 16;
05544             y = *bx - (ys & 0xffff) + borrow;
05545             borrow = y >> 16;
05546             Sign_Extend(borrow, y);
05547             *bx++ = y & 0xffff;
05548 #endif
05549         }
05550         while(sx <= sxe);
05551         if (!*bxe) {
05552             bx = b->x;
05553             while(--bxe > bx && !*bxe)
05554                 --n;
05555             b->wds = n;
05556         }
05557     }
05558     if (cmp(b, S) >= 0) {
05559         q++;
05560         borrow = 0;
05561         carry = 0;
05562         bx = b->x;
05563         sx = S->x;
05564         do {
05565 #ifdef Pack_32
05566             si = *sx++;
05567             ys = (si & 0xffff) + carry;
05568             zs = (si >> 16) + (ys >> 16);
05569             carry = zs >> 16;
05570             y = (*bx & 0xffff) - (ys & 0xffff) + borrow;
05571             borrow = y >> 16;
05572             Sign_Extend(borrow, y);
05573             z = (*bx >> 16) - (zs & 0xffff) + borrow;
05574             borrow = z >> 16;
05575             Sign_Extend(borrow, z);
05576             Storeinc(bx, z, y);
05577 #else
05578             ys = *sx++ + carry;
05579             carry = ys >> 16;
05580             y = *bx - (ys & 0xffff) + borrow;
05581             borrow = y >> 16;
05582             Sign_Extend(borrow, y);
05583             *bx++ = y & 0xffff;
05584 #endif
05585         }
05586         while(sx <= sxe);
05587         bx = b->x;
05588         bxe = bx + n;
05589         if (!*bxe) {
05590             while(--bxe > bx && !*bxe)
05591                 --n;
05592             b->wds = n;
05593         }
05594     }
05595     return q;
05596 }

Here is the call graph for this function:

static double ratio ( Bigint a,
Bigint b 
) [static]

Definition at line 4871 of file qlocale.cpp.

References a, b, b2d(), Exp_msk1, getWord0(), Bigint::k, and setWord0().

Referenced by qstrtod().

04872 {
04873     double da, db;
04874     int k, ka, kb;
04875 
04876     da = b2d(a, &ka);
04877     db = b2d(b, &kb);
04878 #ifdef Pack_32
04879     k = ka - kb + 32*(a->wds - b->wds);
04880 #else
04881     k = ka - kb + 16*(a->wds - b->wds);
04882 #endif
04883 #ifdef IBM
04884     if (k > 0) {
04885         setWord0(&da, getWord0(da) + (k >> 2)*Exp_msk1);
04886         if (k &= 3)
04887             da *= 1 << k;
04888     }
04889     else {
04890         k = -k;
04891         setWord0(&db, getWord0(db) + (k >> 2)*Exp_msk1);
04892         if (k &= 3)
04893             db *= 1 << k;
04894     }
04895 #else
04896     if (k > 0)
04897         setWord0(&da, getWord0(da) + k*Exp_msk1);
04898     else {
04899         k = -k;
04900         setWord0(&db, getWord0(db) + k*Exp_msk1);
04901     }
04902 #endif
04903     return da / db;
04904 }

Here is the call graph for this function:

static QString readEscapedFormatString ( const QString format,
int *  idx 
) [static]

Definition at line 233 of file qlocale.cpp.

References QString::append(), and i.

Referenced by timeFormatContainsAP(), and QLocale::toString().

00234 {
00235     int &i = *idx;
00236 
00237     Q_ASSERT(format.at(i).unicode() == '\'');
00238     ++i;
00239     if (i == format.size())
00240         return QString();
00241     if (format.at(i).unicode() == '\'') { // "''" outside of a quoted stirng
00242         ++i;
00243         return QLatin1String("'");
00244     }
00245 
00246     QString result;
00247 
00248     while (i < format.size()) {
00249         if (format.at(i).unicode() == '\'') {
00250             if (i + 1 < format.size() && format.at(i + 1).unicode() == '\'') {
00251                 // "''" inside of a quoted string
00252                 result.append(QLatin1Char('\''));
00253                 i += 2;
00254             } else {
00255                 break;
00256             }
00257         } else {
00258             result.append(format.at(i++));
00259         }
00260     }
00261     if (i < format.size())
00262         ++i;
00263 
00264     return result;
00265 }

Here is the call graph for this function:

static bool removeGroupSeparators ( QLocalePrivate::CharBuff num  )  [static]

Definition at line 3437 of file qlocale.cpp.

References c, data, num, and QByteArray::qstrlen().

Referenced by QLocalePrivate::numberToCLocale().

03438 {
03439     int group_cnt = 0; // counts number of group chars
03440     int decpt_idx = -1;
03441 
03442     char *data = num->data();
03443     int l = qstrlen(data);
03444 
03445     // Find the decimal point and check if there are any group chars
03446     int i = 0;
03447     for (; i < l; ++i) {
03448         char c = data[i];
03449 
03450         if (c == ',') {
03451             if (i == 0 || data[i - 1] < '0' || data[i - 1] > '9')
03452                 return false;
03453             if (i == l || data[i + 1] < '0' || data[i + 1] > '9')
03454                 return false;
03455             ++group_cnt;
03456         }
03457         else if (c == '.') {
03458             // Fail if more than one decimal points
03459             if (decpt_idx != -1)
03460                 return false;
03461             decpt_idx = i;
03462         } else if (c == 'e' || c == 'E') {
03463             // an 'e' or 'E' - if we have not encountered a decimal
03464             // point, this is where it "is".
03465             if (decpt_idx == -1)
03466                 decpt_idx = i;
03467         }
03468     }
03469 
03470     // If no group chars, we're done
03471     if (group_cnt == 0)
03472         return true;
03473 
03474     // No decimal point means that it "is" at the end of the string
03475     if (decpt_idx == -1)
03476         decpt_idx = l;
03477 
03478     i = 0;
03479     while (i < l && group_cnt > 0) {
03480         char c = data[i];
03481 
03482         if (c == ',') {
03483             // Don't allow group chars after the decimal point
03484             if (i > decpt_idx)
03485                 return false;
03486 
03487             // Check that it is placed correctly relative to the decpt
03488             if ((decpt_idx - i) % 4 != 0)
03489                 return false;
03490 
03491             // Remove it
03492             memmove(data + i, data + i + 1, l - i - 1);
03493             data[--l] = '\0';
03494 
03495             --group_cnt;
03496             --decpt_idx;
03497         } else {
03498             // Check that we are not missing a separator
03499             if (i < decpt_idx
03500                     && (decpt_idx - i) % 4 == 0
03501                     && !(i == 0 && c == '-')) // check for negative sign at start of string
03502                 return false;
03503             ++i;
03504         }
03505     }
03506 
03507     return true;
03508 }

Here is the call graph for this function:

static int repeatCount ( const QString s,
int  i 
) [static]

Definition at line 267 of file qlocale.cpp.

References c, j, and s.

Referenced by QLocale::toString().

00268 {
00269     QChar c = s.at(i);
00270     int j = i + 1;
00271     while (j < s.size() && s.at(j) == c)
00272         ++j;
00273     return j - i;
00274 }

static Bigint* s2b ( const char *  s,
int  nd0,
int  nd,
ULong  y9 
) [static]

Definition at line 4280 of file qlocale.cpp.

References b, Balloc(), Bigint::k, Long, multadd(), x, and y.

Referenced by qstrtod().

04281 {
04282     Bigint *b;
04283     int i, k;
04284     Long x, y;
04285 
04286     x = (nd + 8) / 9;
04287     for(k = 0, y = 1; x > y; y <<= 1, k++) ;
04288 #ifdef Pack_32
04289     b = Balloc(k);
04290     b->x[0] = y9;
04291     b->wds = 1;
04292 #else
04293     b = Balloc(k+1);
04294     b->x[0] = y9 & 0xffff;
04295     b->wds = (b->x[1] = y9 >> 16) ? 2 : 1;
04296 #endif
04297 
04298     i = 9;
04299     if (9 < nd0) {
04300         s += 9;
04301         do b = multadd(b, 10, *s++ - '0');
04302         while(++i < nd0);
04303         s++;
04304     }
04305     else
04306         s += 10;
04307     for(; i < nd; i++)
04308         b = multadd(b, 10, *s++ - '0');
04309     return b;
04310 }

Here is the call graph for this function:

static void setDataPointer ( void **  v,
const QLocalePrivate p 
) [static]

Definition at line 1877 of file qlocale.cpp.

References index, locale_data, p, and system_lp.

Referenced by QLocale::QLocale(), and QLocale::system().

01878 {
01879     quint32 i = reinterpret_cast<quintptr>(*v);
01880 
01881 #ifndef QT_NO_SYSTEMLOCALE
01882     Q_ASSERT(p >= locale_data && p - locale_data < locale_data_size
01883                 || p != 0 && p == system_lp);
01884     quint16 index = p == system_lp ? locale_data_size : p - locale_data;
01885 #else
01886     Q_ASSERT(p >= locale_data && p - locale_data < locale_data_size);
01887     quint16 index = p - locale_data;
01888 #endif
01889 
01890     i &= 0xFFFF0000;
01891     i |= index & 0xFFFF;
01892 
01893     *v = reinterpret_cast<void*>(i);
01894 }

static void setNumberOptions ( void **  v,
int  _opts 
) [static]

Definition at line 1896 of file qlocale.cpp.

01897 {
01898     quint32 i = reinterpret_cast<quintptr>(*v);
01899 
01900     quint32 opts = quint32(_opts) << 16;
01901     i &= 0xFFFF;
01902     i |= opts & 0xFFFF0000;
01903 
01904     *v = reinterpret_cast<void*>(i);
01905 }

static void setWord0 ( NEEDS_VOLATILE double *  x,
ULong  l 
) [inline, static]

Definition at line 4046 of file qlocale.cpp.

References NEEDS_VOLATILE, and ptr.

Referenced by _qdtoa(), b2d(), d2b(), qstrtod(), ratio(), and ulp().

04047 {
04048     NEEDS_VOLATILE uchar *ptr = reinterpret_cast<NEEDS_VOLATILE uchar *>(x);
04049     if (QSysInfo::ByteOrder == QSysInfo::BigEndian) {
04050         ptr[0] = uchar(l>>24);
04051         ptr[1] = uchar(l>>16);
04052         ptr[2] = uchar(l>>8);
04053         ptr[3] = uchar(l);
04054     } else {
04055         ptr[7] = uchar(l>>24);
04056         ptr[6] = uchar(l>>16);
04057         ptr[5] = uchar(l>>8);
04058         ptr[4] = uchar(l);
04059     }
04060 }

static void setWord1 ( NEEDS_VOLATILE double *  x,
ULong  l 
) [inline, static]

Definition at line 4071 of file qlocale.cpp.

References NEEDS_VOLATILE, and ptr.

Referenced by b2d(), qstrtod(), and ulp().

04072 {
04073     NEEDS_VOLATILE uchar *ptr = reinterpret_cast<uchar NEEDS_VOLATILE *>(x);
04074     if (QSysInfo::ByteOrder == QSysInfo::BigEndian) {
04075         ptr[4] = uchar(l>>24);
04076         ptr[5] = uchar(l>>16);
04077         ptr[6] = uchar(l>>8);
04078         ptr[7] = uchar(l);
04079     } else {
04080         ptr[3] = uchar(l>>24);
04081         ptr[2] = uchar(l>>16);
04082         ptr[1] = uchar(l>>8);
04083         ptr[0] = uchar(l);
04084     }
04085 }

static void Storeinc ( ULong *&  a,
const ULong &  b,
const ULong &  c 
) [inline, static]

Definition at line 4087 of file qlocale.cpp.

Referenced by diff(), mult(), and quorem().

04088 {
04089 
04090     *a = (ushort(b) << 16) | ushort(c);
04091     ++a;
04092 }

static const QSystemLocale* systemLocale (  )  [static]

Definition at line 1195 of file qlocale.cpp.

References _systemLocale.

Referenced by QLocale::dateFormat(), QLocale::dayName(), QLocale::monthName(), systemPrivate(), QLocale::timeFormat(), and QLocale::toString().

01196 {
01197     if (!_systemLocale)
01198         _systemLocale = new QSystemLocale();
01199     return _systemLocale;
01200 }

static const QLocalePrivate* systemPrivate (  )  [static]

Definition at line 1233 of file qlocale.cpp.

References locale_data, QLocalePrivate::m_language_id, system_lp, systemLocale(), and QLocalePrivate::updateSystemPrivate().

Referenced by QLocale::dateFormat(), QLocale::dayName(), defaultPrivate(), QLocale::monthName(), QLocale::system(), QLocale::timeFormat(), and QLocale::toString().

01234 {
01235 #ifndef QT_NO_SYSTEMLOCALE
01236     // copy over the information from the fallback locale and modify
01237     if (!system_lp || system_lp->m_language_id == 0) {
01238         (void) systemLocale();
01239         QLocalePrivate::updateSystemPrivate();
01240     }
01241     return system_lp;
01242 #else
01243     return locale_data;
01244 #endif
01245 }

Here is the call graph for this function:

static bool timeFormatContainsAP ( const QString format  )  [static]

Definition at line 2509 of file qlocale.cpp.

References readEscapedFormatString(), and QChar::unicode().

Referenced by QLocale::toString().

02510 {
02511     int i = 0;
02512     while (i + 1 < format.size()) {
02513         if (format.at(i).unicode() == '\'') {
02514             readEscapedFormatString(format, &i);
02515             continue;
02516         }
02517 
02518         QChar c1 = format.at(i);
02519         QChar c2 = format.at(i + 1);
02520         if (c1.unicode() == 'a' && c2.unicode() == 'p'
02521             || c1.unicode() == 'A' && c2.unicode() == 'P')
02522             return true;
02523 
02524         ++i;
02525     }
02526     return false;
02527 }

Here is the call graph for this function:

static QString timeZone (  )  [static]

Definition at line 2529 of file qlocale.cpp.

References QString::fromLocal8Bit().

Referenced by QLocale::toString().

02530 {
02531 #ifdef Q_OS_WIN
02532     _tzset();
02533 # if defined(_MSC_VER) && _MSC_VER >= 1400
02534     size_t returnSize = 0;
02535     char timeZoneName[512];
02536     if (_get_tzname(&returnSize, timeZoneName, 512, 1))
02537         return QString();
02538     return QString::fromLocal8Bit(timeZoneName);
02539 # else
02540     return QString::fromLocal8Bit(_tzname[1]);
02541 # endif
02542 #else
02543     tzset();
02544     return QString::fromLocal8Bit(tzname[1]);
02545 #endif
02546 }

Here is the call graph for this function:

static double ulp ( double  x  )  [static]

Definition at line 4675 of file qlocale.cpp.

References