Home | All Classes | Main Classes | Annotated | Grouped Classes | Functions

TQLocale Class Reference

The TQLocale class converts between numbers and their string representations in various languages. More...

Almost all the functions in this class are reentrant when TQt is built with thread support. The exception is setDefault().

#include <ntqlocale.h>

List of all member functions.

Public Members

Static Public Members


Detailed Description

The TQLocale class converts between numbers and their string representations in various languages.

It is initialized with a country/language pair in its constructor and offers number-to-string and string-to-number conversion functions simmilar to those in TQString.

    TQLocale egyptian(TQLocale::Arabic, TQLocale::Egypt);
    TQString s1 = egyptian.toString(1.571429E+07, 'e');
    TQString s2 = egyptian.toString(10);

    double d = egyptian.toDouble(s1);
    int s2 = egyptian.toInt(s2);
    

TQLocale supports the concept of a default locale, which is determined from the system's locale settings at application startup. The default locale can be changed by calling the static member setDefault(). The default locale has the following effects:

    TQLocale::setDefault(TQLocale(TQLocale::Hebrew, TQLocale::Israel));
    TQLocale hebrew; // Constructs a default TQLocale
    TQString s1 = hebrew.toString(15714.3, 'e');

    bool ok;
    double d;

    TQLocale::setDefault(TQLocale::C);
    d = TQString( "1234,56" ).toDouble(&ok); // ok == false
    d = TQString( "1234.56" ).toDouble(&ok); // ok == true, d == 1234.56

    TQLocale::setDefault(TQLocale::German);
    d = TQString( "1234,56" ).toDouble(&ok); // ok == true, d == 1234.56
    d = TQString( "1234.56" ).toDouble(&ok); // ok == true, d == 1234.56

    TQLocale::setDefault(TQLocale(TQLocale::English, TQLocale::UnitedStates));
    str = TQString( "%1 %L2 %L3" )
            .arg( 12345 )
            .arg( 12345 )
            .arg( 12345, 0, 16 );
    // str == "12345 12,345 3039"
    

When a language/country pair is specified in the constructor, one of three things can happen:

The "C" locale is identical to English/UnitedStates.

Use language() and country() to determine the actual language and country values used.

An alternative method for constructing a TQLocale object is by specifying the locale name.

    TQLocale korean("ko");
    TQLocale swiss("de_CH");
    

This constructor converts the locale name to a language/country pair; it does not use the system locale database.

All the methods in TQLocale, with the exception of setDefault(), are reentrant.

See also TQString::toDouble(), TQString::arg(), and Text Related Classes.

The double-to-string and string-to-double conversion functions are covered by the following licenses:

Copyright (c) 1991 by AT&T.

Permission to use, copy, modify, and distribute this software for any purpose without fee is hereby granted, provided that this entire notice is included in all copies of any software which is or includes a copy or modification of this software and in all copies of the supporting documentation for such software.

THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR IMPLIED WARRANTY. IN PARTICULAR, NEITHER THE AUTHOR NOR AT&T MAKES ANY REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE MERCHANTABILITY OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE.

This product includes software developed by the University of California, Berkeley and its contributors.


Member Type Documentation

TQLocale::Country

This enumerated type is used to specify a country.

TQLocale::Language

This enumerated type is used to specify a language.


Member Function Documentation

TQLocale::TQLocale ()

Constructs a TQLocale object initialized with the default locale.

See also setDefault().

TQLocale::TQLocale ( const TQString & name )

Constructs a TQLocale object with the specified name, which has the format "language[_country][.codeset][@modifier]" or "C", where:

If the string violates the locale format, or language is not a valid ISO 369 code, the "C" locale is used instead. If country is not present, or is not a valid ISO 3166 code, the most appropriate country is chosen for the specified language.

The language and country codes are converted to their respective Language and Country enums. After this conversion is performed the constructor behaves exactly like TQLocale(Country, Language).

This constructor is much slower than TQLocale(Country, Language).

See also name().

TQLocale::TQLocale ( Language language, Country country = AnyCountry )

Constructs a TQLocale object with the specified language and country.

The language and country that are actually used can be queried using language() and country().

See also setDefault(), language(), and country().

TQLocale::TQLocale ( const TQLocale & other )

Constructs a TQLocale object as a copy of other.

TQLocale TQLocale::c () [static]

Returns a TQLocale object initialized to the "C" locale.

See also system().

Country TQLocale::country () const

Returns the country of this locale.

See also TQLocale().

TQString TQLocale::countryToString ( Country country ) [static]

Returns a TQString containing the name of country.

Language TQLocale::language () const

Returns the language of this locale.

See also TQLocale().

TQString TQLocale::languageToString ( Language language ) [static]

Returns a TQString containing the name of language.

TQString TQLocale::name () const

Returns the language and country of this locale as a string of the form "language_country", where language is a lowercase, two-letter ISO 639 language code, and country is an uppercase, two-letter ISO 3166 country code.

See also TQLocale().

TQLocale & TQLocale::operator= ( const TQLocale & other )

Assigns other to this TQLocale object and returns a reference to this TQLocale object.

void TQLocale::setDefault ( const TQLocale & locale ) [static]

Warning: This function is not reentrant.

Sets the global default locale to locale. These values are used when a TQLocale object is constructed with no arguments. If this function is not called, the system's locale is used.

Warning: In a multithreaded application, the default locale should be set at application startup, before any non-GUI threads are created.

See also system() and c().

TQLocale TQLocale::system () [static]

Returns a TQLocale object initialized to the system locale.

double TQLocale::toDouble ( const TQString & s, bool * ok = 0 ) const

Returns the double 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.

Unlike TQString::toDouble(), this function does not fall back to the "C" locale if the string cannot be interpreted in this locale.

        bool ok;
        double d;

        TQLocale c(TQLocale::C);
        d = c.toDouble( "1234.56", &ok );  // ok == true, d == 1234.56
        d = c.toDouble( "1,234.56", &ok ); // ok == true, d == 1234.56
        d = c.toDouble( "1234,56", &ok );  // ok == false

        TQLocale german(TQLocale::German);
        d = german.toDouble( "1234,56", &ok );  // ok == true, d == 1234.56
        d = german.toDouble( "1.234,56", &ok ); // ok == true, d == 1234.56
        d = german.toDouble( "1234.56", &ok );  // ok == false

        d = german.toDouble( "1.234", &ok );    // ok == true, d == 1234.0
    

Notice that the last conversion returns 1234.0, because '.' is the thousands group separator in the German locale.

This function ignores leading and trailing whitespace.

See also toString() and TQString::toDouble().

float TQLocale::toFloat ( const TQString & s, bool * ok = 0 ) const

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 toString().

int TQLocale::toInt ( const TQString & s, bool * ok = 0 ) const

Returns the int represented by the localized string s, or 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 toString().

TQ_LONG TQLocale::toLong ( const TQString & s, bool * ok = 0 ) const

Returns the long int represented by the localized string s, or 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 toString().

TQ_LLONG TQLocale::toLongLong ( const TQString & s, bool * ok = 0 ) const

Returns the long long int represented by the localized string s, or 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 toString().

short TQLocale::toShort ( const TQString & s, bool * ok = 0 ) const

Returns the short int represented by the localized string s, or 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 toString().

TQString TQLocale::toString ( TQ_LLONG i ) const

Returns a localized string representation of i.

See also toLongLong().

TQString TQLocale::toString ( short i ) const

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

See also toShort().

TQString TQLocale::toString ( ushort i ) const

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

See also toUShort().

TQString TQLocale::toString ( int i ) const

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

See also toInt().

TQString TQLocale::toString ( uint i ) const

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

See also toUInt().

TQString TQLocale::toString ( TQ_LONG i ) const

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

See also toLong().

TQString TQLocale::toString ( TQ_ULONG i ) const

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

See also toULong().

TQString TQLocale::toString ( TQ_ULLONG i ) const

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

See also toULongLong().

TQString TQLocale::toString ( float i, char f = 'g', int prec = 6 ) const

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

f and prec have the same meaning as in TQString::number(double, char, int).

See also toDouble().

TQString TQLocale::toString ( double i, char f = 'g', int prec = 6 ) const

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

f and prec have the same meaning as in TQString::number(double, char, int).

See also toDouble().

uint TQLocale::toUInt ( const TQString & s, bool * ok = 0 ) const

Returns the unsigned int represented by the localized string s, or 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 toString().

TQ_ULONG TQLocale::toULong ( const TQString & s, bool * ok = 0 ) const

Returns the unsigned long int represented by the localized string s, or 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 toString().

TQ_ULLONG TQLocale::toULongLong ( const TQString & s, bool * ok = 0 ) const

Returns the unsigned long long int represented by the localized string s, or 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 toString().

ushort TQLocale::toUShort ( const TQString & s, bool * ok = 0 ) const

Returns the unsigned short int represented by the localized string s, or 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 toString().


This file is part of the TQt toolkit. Copyright © 1995-2007 Trolltech. All Rights Reserved.


Copyright © 2007 TrolltechTrademarks
TQt 3.3.8