Wt::WString Class Reference

Wt unicode String class, with support for localization. More...

#include <WString>

List of all members.

Public Member Functions

 WString (const wchar_t *value=0)
 Construct a WString from a wide C string.
 WString (const WString &other)
 Copy constructor.
 WString (const std::wstring value)
 Construct a WString from a wide C++ string.
 WString (const char *value)
 Construct a WString from a C string.
 WString (const std::string value)
 Construct a WString from a C++ string.
 ~WString ()
 Delete a WString.
WStringoperator= (const WString &rhs)
 Assignment operator.
bool operator== (const WString &rhs) const
 Comparison operator.
WStringoperator+= (const WString &rhs)
 Self-concatenation operator.
WStringoperator+= (const std::wstring rhs)
 Self-concatenation operator.
WStringoperator+= (const wchar_t *rhs)
 Self-concatenation operator.
WStringoperator+= (const std::string rhs)
 Self-concatenation operator.
WStringoperator+= (const char *rhs)
 Self-concatenation operator.
bool empty () const
 Is the string empty ?
std::string toUTF8 () const
 Get the value as a UTF8 unicode encoded string.
std::wstring value () const
 Get the value as a wide C++ string.
std::string narrow () const
 Get the value as a narrow C++ string.
 operator std::wstring () const
 Get the value as a wide C++ string.
bool literal () const
 Is this string literal or localized ?
const std::string key () const
 Get the key for this localized string.
WStringarg (const std::wstring value)
 Add a value for the next positional string argument of this localized string.
WStringarg (const std::string value)
 Add a value for the next positional string argument of this localized string.
WStringarg (int value)
 Add a value for the next positional integer argument of this localized string.
const std::vector< std::wstring > & args () const
 The list of arguments.
bool refresh ()
 Refresh the message.

Static Public Member Functions

static WString fromUTF8 (const std::string value)
 Construct a WString from a UTF8 unicode encoded string.
static WString tr (const char *key)
 Construct a localized string with the specified key.


Detailed Description

Wt unicode String class, with support for localization.

Wt offers this string to facilitate handling of unicode text through the user interface, as well as to offer support for localized text using message resource bundles.

A WString may be constructed from a std::string, std::wstring or c-style strings (const char * and const wchar_t *), and converted to each of these strings. In addition, it supports conversion from and to UTF8 unicode encoded strings.

By using the static functions WString::tr() (or WWidget::tr()), one may construct a localized string. The key is used to retrieve its current value from the application's message-resource bundles. Arguments in the message, denoted using {n} for the n'th argument, may be substituted by arguments set using arg(int) and arg(std::string).

By calling WApplication::refresh(), the contents of every WString may be refreshed by the owner (and this is done so for all Wt widgets that own a WString), by calling refresh(). In this way, the contents is adapted to a possibly changed locale.

This string class does not provide anything more than basic manipulations. Instead, you should convert to a standard library string class to manipulate the string contents.

See also:
WApplication::messageResourceBundle()

WApplication::locale()


Member Function Documentation

WString & Wt::WString::arg ( int  value  ) 

Add a value for the next positional integer argument of this localized string.

In the resource, the n-th argument is reffered to as using '{n}'. For example: a resource message '{1} bought {2} apples in the shop.' with first argument value 'Bart' and second argument value '5' becomes: 'Bart bought 5 apples in the shop.'.

WString& Wt::WString::arg ( const std::string  value  ) 

Add a value for the next positional string argument of this localized string.

In the resource, the n-th argument is reffered to as using '{n}'. For example: a resource message '{1} bought {2} apples in the shop.' with first argument value 'Bart' and second argument value '5' becomes: 'Bart bought 5 apples in the shop.'.

WString & Wt::WString::arg ( const std::wstring  value  ) 

Add a value for the next positional string argument of this localized string.

In the resource, the n-th argument is reffered to as using '{n}'. For example: a resource message '{1} bought {2} apples in the shop.' with first argument value 'Bart' and second argument value '5' becomes: 'Bart bought 5 apples in the shop.'.

const std::string Wt::WString::key (  )  const

Get the key for this localized string.

When the string is literal, the result is undefined.

bool Wt::WString::literal (  )  const [inline]

Is this string literal or localized ?

See also:
tr()

std::string Wt::WString::narrow (  )  const

Get the value as a narrow C++ string.

For a localized string, returns the current localized value.

Any wide character is narrowed, possibly losing information. If you wish to keep all information, use toUTF8() instead, which encodes wide characters in the string.

See also:
toUTF8()

Wt::WString::operator std::wstring (  )  const

Get the value as a wide C++ string.

For a localized string, returns the current localized value.

bool Wt::WString::refresh (  ) 

Refresh the message.

For a localized message, this rereads the value from the message resource bundle.

Returns whether the value has changed.

std::string Wt::WString::toUTF8 (  )  const

Get the value as a UTF8 unicode encoded string.

For a localized string, returns the current localized value.

See also:
fromUTF8()

WString Wt::WString::tr ( const char *  key  )  [static]

Construct a localized string with the specified key.

The key is looked up in the application message resource bundles. If the key cannot be resolved, the value is set to ??key??.

See also:
WApplication::messageResourceBundle()

std::wstring Wt::WString::value (  )  const

Get the value as a wide C++ string.

For a localized string, returns the current localized value.


The documentation for this class was generated from the following files:
Generated on Sun Jul 1 19:37:18 2007 for Wt by doxygen 1.4.7