SourcePro® API Reference Guide

 
Loading...
Searching...
No Matches

Specifies the default character encoding scheme for conversions between narrow character strings and UTF-16 strings. More...

#include <rw/i18n/RWUConversionContext.h>

Inheritance diagram for RWUConversionContext:
RWUToUnicodeConversionContext RWUFromUnicodeConversionContext

Public Member Functions

 RWUConversionContext (const char *encoding=RWUConverterBase::getDefaultEncodingName())
 
 ~RWUConversionContext ()
 
- Public Member Functions inherited from RWUToUnicodeConversionContext
 RWUToUnicodeConversionContext (const char *encoding=RWUConverterBase::getDefaultEncodingName())
 
 ~RWUToUnicodeConversionContext ()
 
RWUToUnicodeConvertergetConverter ()
 
- Public Member Functions inherited from RWUFromUnicodeConversionContext
 RWUFromUnicodeConversionContext (const char *encoding=RWUConverterBase::getDefaultEncodingName())
 
 ~RWUFromUnicodeConversionContext ()
 
RWUFromUnicodeConvertergetConverter ()
 

Additional Inherited Members

- Static Public Member Functions inherited from RWUToUnicodeConversionContext
static RWUToUnicodeConversionContextgetContext ()
 
- Static Public Member Functions inherited from RWUFromUnicodeConversionContext
static RWUFromUnicodeConversionContextgetContext ()
 

Detailed Description

RWUConversionContext specifies the default character encoding scheme to use for subsequent implicit conversions between narrow character strings and UTF-16 encoded Unicode strings.

RWUConversionContext combines the functionality provided by the RWUToUnicodeConversionContext and RWUFromUnicodeConversionContext to provide a single convenient means for specifying the encoding for conversions to and from Unicode.

RWUConversionContext uses the resource acquisition is initialization idiom to manage two internal, per-thread stacks of RWUFromUnicodeConversionContext instances and RWUToUnicodeConversionContext.

Note
Instances of RWUConversionContext can only be constructed with static or automatic storage duration; dynamic allocation is not allowed. Do not create unnamed, temporary instances. The destructors for such objects pop the context off the context stack prematurely.
Example
#include <rw/i18n/RWUConversionContext.h>
#include <rw/i18n/RWUString.h>
#include <iostream>
int main() {
// Indicate that source and target strings
// are encoded according to ISO-8859-1
RWUConversionContext context("ISO-8859-1");
// NOTE! This won't work: RWUConversionContext("ISO-8859-1");
// Use implicit conversion to construct `str'
RWUString str("ISO-8859-1");
// Use implicit conversion to initialize `str2'
RWUString str2 = " source: ";
str += str2;
// Write an ISO-8859-1 encoded representation of
// `str' to std::cout
std::cout << str << "in ISO-8859-1" << std::endl;
{
// Create a nested conversion context
RWUConversionContext nestedContext("Shift-JIS");
// Write a Shift-JIS encoded representation of
// `str' to std::cout
std::cout << str << "in Shift-JIS" << std::endl;
// Nested context goes out of scope
}
// Original context goes out of scope
return 0;
}
Specifies the default character encoding scheme for conversions between narrow character strings and ...
Definition RWUConversionContext.h:101
Stores and manipulates Unicode character sequences encoded as UTF-16 code units.
Definition RWUString.h:187

Program output:

ISO-8859-1 source: in ISO-8859-1
ISO-8859-1 source: in Shift-JIS
See also
RWUToUnicodeConversionContext, RWUFromUnicodeConversionContext

Constructor & Destructor Documentation

◆ RWUConversionContext()

RWUConversionContext::RWUConversionContext ( const char * encoding = RWUConverterBase::getDefaultEncodingName())
inline

Constructs an RWUConversionContext for the specified encoding. The conversion context specifies the default implicit conversion to use when automatically converting a sequence of bytes into an RWUString, an RWUString into a sequence of bytes, or both. The encoding name is encoded in US-ASCII, and must specify one of the names or aliases currently recognized by the Internationalization Module (see RWUAvailableEncodingList and RWUEncodingAliasList).

The specified conversion context remains in effect until another conversion of the same direction is specified, or until the conversion context instance goes out of scope and is destroyed.

Exceptions
RWUExceptionThrown to indicate that a converter could not be constructed for the specified encoding. The exception carries one of the following status codes:

◆ ~RWUConversionContext()

RWUConversionContext::~RWUConversionContext ( )
inline

Destructor. Destroys self and restores the conversion context that was in effect prior to the construction of this instance.

Copyright © 2024 Rogue Wave Software, Inc., a Perforce company. All Rights Reserved.