22#include <osl/diagnose.h>
23#include <rtl/tencinfo.h>
36 const rtl_TextEncoding eFirstEncoding = RTL_TEXTENCODING_DONTKNOW;
37 const rtl_TextEncoding eLastEncoding = 100;
38 OSL_ENSURE( 0 == eFirstEncoding,
"OCharsetMap::OCharsetMap: somebody changed the numbers!" );
40 rtl_TextEncodingInfo aInfo; aInfo.StructSize =
sizeof( rtl_TextEncodingInfo );
41 for ( rtl_TextEncoding eEncoding = eFirstEncoding; eEncoding < eLastEncoding; ++eEncoding )
43 if ( ( RTL_TEXTENCODING_DONTKNOW == eEncoding )
44 || ( rtl_getTextEncodingInfo( eEncoding, &aInfo )
53 OSL_ENSURE(
find( RTL_TEXTENCODING_MS_1252 ) !=
end(),
"OCharsetMap::lateConstruct: missing compatibility encoding ANSI!" );
54 OSL_ENSURE(
find( RTL_TEXTENCODING_APPLE_ROMAN ) !=
end(),
"OCharsetMap::lateConstruct: missing compatibility encoding macintosh!" );
55 OSL_ENSURE(
find( RTL_TEXTENCODING_IBM_437 ) !=
end(),
"OCharsetMap::lateConstruct: missing compatibility encoding IBM437!" );
56 OSL_ENSURE(
find( RTL_TEXTENCODING_IBM_850) !=
end(),
"OCharsetMap::lateConstruct: missing compatibility encoding IBM850!" );
57 OSL_ENSURE(
find( RTL_TEXTENCODING_IBM_860 ) !=
end(),
"OCharsetMap::lateConstruct: missing compatibility encoding IBM860!" );
58 OSL_ENSURE(
find( RTL_TEXTENCODING_IBM_861 ) !=
end(),
"OCharsetMap::lateConstruct: missing compatibility encoding IBM861!" );
59 OSL_ENSURE(
find( RTL_TEXTENCODING_IBM_863 ) !=
end(),
"OCharsetMap::lateConstruct: missing compatibility encoding IBM863!" );
60 OSL_ENSURE(
find( RTL_TEXTENCODING_IBM_865 ) !=
end(),
"OCharsetMap::lateConstruct: missing compatibility encoding IBM865!" );
61 OSL_ENSURE(
find( RTL_TEXTENCODING_IBM_866 ) !=
end(),
"OCharsetMap::lateConstruct: missing compatibility encoding IBM866!" );
62 OSL_ENSURE(
find( RTL_TEXTENCODING_DONTKNOW ) !=
end(),
"OCharsetMap::lateConstruct: missing compatibility encoding SYSTEM!" );
63 OSL_ENSURE(
find( RTL_TEXTENCODING_UTF8 ) !=
end(),
"OCharsetMap::lateConstruct: missing compatibility encoding UTF-8!" );
64 OSL_ENSURE(
find( RTL_TEXTENCODING_BIG5_HKSCS ) !=
end(),
"OCharsetMap::lateConstruct: missing compatibility encoding Big5-HKSCS!" );
70 bool bIsMimeEncoding = 0 != ( _rInfo.Flags & RTL_TEXTENCODING_INFO_MIME );
71 OSL_ENSURE( !bIsMimeEncoding || rtl_getMimeCharsetFromTextEncoding( _eEncoding ),
72 "OCharsetMap::OCharsetMap: inconsistence in rtl!" );
73 return bIsMimeEncoding;
100 rtl_TextEncoding eEncoding = RTL_TEXTENCODING_DONTKNOW;
101 if ( !_rIanaName.empty() )
104 OString sMimeByteString =
OUStringToOString( _rIanaName, RTL_TEXTENCODING_ASCII_US );
106 eEncoding = rtl_getTextEncodingFromMimeCharset( sMimeByteString.getStr() );
108 if ( RTL_TEXTENCODING_DONTKNOW == eEncoding )
114 return find( eEncoding );
127 :m_eEncoding( _rSource.m_eEncoding )
128 ,m_aIanaName( _rSource.m_aIanaName )
134 :m_eEncoding( _eEncoding )
135 ,m_aIanaName(
std::move( _aIanaName ))
139 OCharsetMap::CharsetIterator::CharsetIterator(
const OCharsetMap* _pContainer, OCharsetMap::TextEncBag::const_iterator _aPos )
140 :m_pContainer( _pContainer )
141 ,m_aPos(
std::move( _aPos ))
143 OSL_ENSURE( m_pContainer,
"OCharsetMap::CharsetIterator::CharsetIterator : invalid container!" );
146 CharsetIteratorDerefHelper OCharsetMap::CharsetIterator::operator*()
const
148 OSL_ENSURE( m_aPos != m_pContainer->m_aEncodings.end(),
"OCharsetMap::CharsetIterator::operator*: invalid position!");
150 rtl_TextEncoding eEncoding = *m_aPos;
153 if ( RTL_TEXTENCODING_DONTKNOW != eEncoding )
155 const char* pIanaName = rtl_getMimeCharsetFromTextEncoding( eEncoding );
156 OSL_ENSURE( pIanaName,
"OCharsetMap::CharsetIterator: invalid mime name!" );
158 sIanaName = OUString::createFromAscii( pIanaName );
160 return CharsetIteratorDerefHelper( eEncoding, sIanaName );
166 OSL_ENSURE( m_aPos != m_pContainer->m_aEncodings.end(),
"OCharsetMap::CharsetIterator::operator++ : invalid position!" );
167 if ( m_aPos != m_pContainer->m_aEncodings.end())
175 OSL_ENSURE( m_aPos != m_pContainer->m_aEncodings.begin(),
"OCharsetMap::CharsetIterator::operator-- : invalid position!" );
176 if ( m_aPos != m_pContainer->m_aEncodings.begin() )
184 return ( lhs.m_pContainer == rhs.m_pContainer ) && ( lhs.m_aPos == rhs.m_aPos );
OString OUStringToOString(std::u16string_view str, ConnectionSettings const *settings)