1*caf5cd79SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*caf5cd79SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*caf5cd79SAndrew Rist * or more contributor license agreements. See the NOTICE file 5*caf5cd79SAndrew Rist * distributed with this work for additional information 6*caf5cd79SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*caf5cd79SAndrew Rist * to you under the Apache License, Version 2.0 (the 8*caf5cd79SAndrew Rist * "License"); you may not use this file except in compliance 9*caf5cd79SAndrew Rist * with the License. You may obtain a copy of the License at 10*caf5cd79SAndrew Rist * 11*caf5cd79SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12*caf5cd79SAndrew Rist * 13*caf5cd79SAndrew Rist * Unless required by applicable law or agreed to in writing, 14*caf5cd79SAndrew Rist * software distributed under the License is distributed on an 15*caf5cd79SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*caf5cd79SAndrew Rist * KIND, either express or implied. See the License for the 17*caf5cd79SAndrew Rist * specific language governing permissions and limitations 18*caf5cd79SAndrew Rist * under the License. 19*caf5cd79SAndrew Rist * 20*caf5cd79SAndrew Rist *************************************************************/ 21*caf5cd79SAndrew Rist 22*caf5cd79SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir #ifndef _DBHELPER_DBCHARSET_HXX_ 25cdf0e10cSrcweir #define _DBHELPER_DBCHARSET_HXX_ 26cdf0e10cSrcweir 27cdf0e10cSrcweir #include <comphelper/stl_types.hxx> 28cdf0e10cSrcweir #include <rtl/textenc.h> 29cdf0e10cSrcweir #include <rtl/tencinfo.h> 30cdf0e10cSrcweir #include <rtl/ustring.hxx> 31cdf0e10cSrcweir #include "connectivity/dbtoolsdllapi.hxx" 32cdf0e10cSrcweir 33cdf0e10cSrcweir //......................................................................... 34cdf0e10cSrcweir namespace dbtools 35cdf0e10cSrcweir { 36cdf0e10cSrcweir //......................................................................... 37cdf0e10cSrcweir 38cdf0e10cSrcweir //========================================================================= 39cdf0e10cSrcweir //= OCharsetMap 40cdf0e10cSrcweir //========================================================================= 41cdf0e10cSrcweir /** is a class which translates between different charset representations. 42cdf0e10cSrcweir 43cdf0e10cSrcweir <p>The set of recognized charsets is very limited: only the ones which are database relevant are 44cdf0e10cSrcweir implemented at the moment</p> 45cdf0e10cSrcweir 46cdf0e10cSrcweir <p>Possible representations are: 47cdf0e10cSrcweir <ul> 48cdf0e10cSrcweir <li><b>IANA names.</b> 49cdf0e10cSrcweir Have a look at <A href="http://www.iana.org/assignments/character-sets">this document</A> for 50cdf0e10cSrcweir more details</li> 51cdf0e10cSrcweir <li><b>rtl_TextEncoding</b></li> 52cdf0e10cSrcweir </ul> 53cdf0e10cSrcweir </p> 54cdf0e10cSrcweir */ 55cdf0e10cSrcweir class OOO_DLLPUBLIC_DBTOOLS OCharsetMap 56cdf0e10cSrcweir { 57cdf0e10cSrcweir protected: 58cdf0e10cSrcweir DECLARE_STL_STDKEY_SET( rtl_TextEncoding, TextEncBag ); 59cdf0e10cSrcweir 60cdf0e10cSrcweir TextEncBag m_aEncodings; 61cdf0e10cSrcweir 62cdf0e10cSrcweir public: 63cdf0e10cSrcweir class CharsetIterator; 64cdf0e10cSrcweir friend class OCharsetMap::CharsetIterator; 65cdf0e10cSrcweir typedef CharsetIterator iterator; 66cdf0e10cSrcweir typedef CharsetIterator const_iterator; 67cdf0e10cSrcweir 68cdf0e10cSrcweir OCharsetMap(); 69cdf0e10cSrcweir virtual ~OCharsetMap(); 70cdf0e10cSrcweir 71cdf0e10cSrcweir struct IANA { }; 72cdf0e10cSrcweir 73cdf0e10cSrcweir /** find the given text encoding in the map. 74cdf0e10cSrcweir @return the <em>end</em> iterator if the encoding could not be found. 75cdf0e10cSrcweir */ 76cdf0e10cSrcweir CharsetIterator find(const rtl_TextEncoding _eEncoding) const; 77cdf0e10cSrcweir /** find the given IANA name in the map. 78cdf0e10cSrcweir @return the <em>end</em> iterator if the IANA name could not be found. 79cdf0e10cSrcweir */ 80cdf0e10cSrcweir CharsetIterator find(const ::rtl::OUString& _rIanaName, const IANA&) const; 81cdf0e10cSrcweir size() const82cdf0e10cSrcweir sal_Int32 size() const { ensureConstructed( ); return m_aEncodings.size(); } 83cdf0e10cSrcweir 84cdf0e10cSrcweir /// get access to the first element of the charset collection 85cdf0e10cSrcweir CharsetIterator begin() const; 86cdf0e10cSrcweir /// get access to the (last + 1st) element of the charset collection 87cdf0e10cSrcweir CharsetIterator end() const; 88cdf0e10cSrcweir 89cdf0e10cSrcweir protected: 90cdf0e10cSrcweir // needed because we want to call a virtual method during construction 91cdf0e10cSrcweir void lateConstruct(); ensureConstructed() const92cdf0e10cSrcweir inline void ensureConstructed( ) const { if ( m_aEncodings.empty() ) const_cast< OCharsetMap* >( this )->lateConstruct(); } 93cdf0e10cSrcweir 94cdf0e10cSrcweir virtual sal_Bool approveEncoding( const rtl_TextEncoding _eEncoding, const rtl_TextEncodingInfo& _rInfo ) const; 95cdf0e10cSrcweir }; 96cdf0e10cSrcweir 97cdf0e10cSrcweir //------------------------------------------------------------------------- 98cdf0e10cSrcweir //- CharsetIteratorDerefHelper 99cdf0e10cSrcweir //------------------------------------------------------------------------- 100cdf0e10cSrcweir class OOO_DLLPUBLIC_DBTOOLS CharsetIteratorDerefHelper 101cdf0e10cSrcweir { 102cdf0e10cSrcweir friend class OCharsetMap::CharsetIterator; 103cdf0e10cSrcweir 104cdf0e10cSrcweir rtl_TextEncoding m_eEncoding; 105cdf0e10cSrcweir ::rtl::OUString m_aIanaName; 106cdf0e10cSrcweir 107cdf0e10cSrcweir public: 108cdf0e10cSrcweir CharsetIteratorDerefHelper(const CharsetIteratorDerefHelper& _rSource); 109cdf0e10cSrcweir getEncoding() const110cdf0e10cSrcweir rtl_TextEncoding getEncoding() const { return m_eEncoding; } getIanaName() const111cdf0e10cSrcweir ::rtl::OUString getIanaName() const { return m_aIanaName; } 112cdf0e10cSrcweir 113cdf0e10cSrcweir protected: 114cdf0e10cSrcweir CharsetIteratorDerefHelper(); 115cdf0e10cSrcweir CharsetIteratorDerefHelper( const rtl_TextEncoding _eEncoding, const ::rtl::OUString& _rIanaName ); 116cdf0e10cSrcweir 117cdf0e10cSrcweir }; 118cdf0e10cSrcweir 119cdf0e10cSrcweir 120cdf0e10cSrcweir //------------------------------------------------------------------------- 121cdf0e10cSrcweir //- OCharsetMap::CharsetIterator 122cdf0e10cSrcweir //------------------------------------------------------------------------- 123cdf0e10cSrcweir class OOO_DLLPUBLIC_DBTOOLS OCharsetMap::CharsetIterator 124cdf0e10cSrcweir { 125cdf0e10cSrcweir friend class OCharsetMap; 126cdf0e10cSrcweir 127cdf0e10cSrcweir friend OOO_DLLPUBLIC_DBTOOLS bool operator==(const CharsetIterator& lhs, const CharsetIterator& rhs); operator !=(const CharsetIterator & lhs,const CharsetIterator & rhs)128cdf0e10cSrcweir friend bool operator!=(const CharsetIterator& lhs, const CharsetIterator& rhs) { return !(lhs == rhs); } 129cdf0e10cSrcweir 130cdf0e10cSrcweir // friend sal_Int32 operator-(const CharsetIterator& lhs, const CharsetIterator& rhs); 131cdf0e10cSrcweir 132cdf0e10cSrcweir protected: 133cdf0e10cSrcweir const OCharsetMap* m_pContainer; 134cdf0e10cSrcweir OCharsetMap::TextEncBag::const_iterator m_aPos; 135cdf0e10cSrcweir 136cdf0e10cSrcweir public: 137cdf0e10cSrcweir CharsetIterator(const CharsetIterator& _rSource); 138cdf0e10cSrcweir ~CharsetIterator(); 139cdf0e10cSrcweir 140cdf0e10cSrcweir CharsetIteratorDerefHelper operator*() const; 141cdf0e10cSrcweir // no -> operator 142cdf0e10cSrcweir // this would require us to a) store CharsetIteratorDerefHelper instances ourself so that we 143cdf0e10cSrcweir // can return a pointer or b) introduce a -> operator on the CharsetIteratorDerefHelper, too. 144cdf0e10cSrcweir 145cdf0e10cSrcweir /// prefix increment 146cdf0e10cSrcweir const CharsetIterator& operator++(); 147cdf0e10cSrcweir /// postfix increment operator ++(int)148cdf0e10cSrcweir const CharsetIterator operator++(int) { CharsetIterator hold(*this); ++*this; return hold; } 149cdf0e10cSrcweir 150cdf0e10cSrcweir /// prefix decrement 151cdf0e10cSrcweir const CharsetIterator& operator--(); 152cdf0e10cSrcweir /// postfix decrement operator --(int)153cdf0e10cSrcweir const CharsetIterator operator--(int) { CharsetIterator hold(*this); --*this; return hold; } 154cdf0e10cSrcweir 155cdf0e10cSrcweir protected: 156cdf0e10cSrcweir CharsetIterator(const OCharsetMap* _pContainer, OCharsetMap::TextEncBag::const_iterator _aPos ); 157cdf0e10cSrcweir }; 158cdf0e10cSrcweir 159cdf0e10cSrcweir //......................................................................... 160cdf0e10cSrcweir } // namespace dbtools 161cdf0e10cSrcweir //......................................................................... 162cdf0e10cSrcweir 163cdf0e10cSrcweir #endif // _DBHELPER_DBCHARSET_HXX_ 164cdf0e10cSrcweir 165