#ifndef DOXYGEN_SKIP
/* $Id: RFC5_UNICODE.dox 10035 2006-09-25 14:15:40Z fwarmerdam $ */
#endif /* DOXYGEN_SKIP */
/*!
\page rfc5_unicode RFC 5: Unicode support in GDAL
Author: Andrey Kiselev
Contact: dron@ak4719.spb.edu
Status: Development
\section rfc5_summary Summary
This document contains proposal on how to make GDAL core locale independent
preserving support for native character sets.
\section rfc5_main Main concepts
GDAL should be modified in a way to support three following main ideas:
// Get string in local encoding from the internal UTF-8 encoded string. // Out-of-range characters replaced with '?' in output string. // nEncoding A codename of encoding. If 0 the local system // encoding will be used. char* CPLString::recode( int nEncoding = 0 ); // Construct UTF-8 string object from string in other encoding // nEncoding A codename of encoding. If 0 the local system // encoding will be used. CPLString::CPLString( const char*, int nEncoding ); // Construct UTF-8 string object from array of wchar_t elements. // Source encoding is system specific. CPLString::CPLString( wchar_t* ); // Get string from UTF-8 encoding into array of wchar_t elements. // Destination encoding is system specific. operator wchar_t* (void) const;
pszFilename = argv[i]; if( pszFilename ) hDataset = GDALOpen( pszFilename, GA_ReadOnly );we should do
CPLString oFilename(argv[i], 0); // <-- Conversion from local encoding to UTF-8 hDataset = GDALOpen( oFilename.c_str(), GA_ReadOnly );For output instead of
printf( "Description = %s\n", GDALGetDescription(hBand) );we should do
CPLString oDescription( GDALGetDescription(hBand) ); printf( "Description = %s\n", oDescription.recode( 0 ) ); // <-- Conversion // from UTF-8 to localThe filename passed to GDALOpen() in UTF-8 encoding in the code snippet above will be further processed in the GDAL core. On Windows instead of
hFile = CreateFile( pszFilename, dwDesiredAccess, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, dwCreationDisposition, dwFlagsAndAttributes, NULL );we do
CPLString oFilename( pszFilename ); // I am prefer call the wide character version explicitly // rather than specify _UNICODE switch. hFile = CreateFileW( (wchar_t *)oFilename, dwDesiredAccess, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, dwCreationDisposition, dwFlagsAndAttributes, NULL );