1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include "charsets.hxx"
21 #include <osl/diagnose.h>
22 #include "dbu_misc.hrc"
23 #include <rtl/tencinfo.h>
24 #include <tools/rcid.h>
25 #include "moduledbu.hxx"
29 using namespace ::dbtools
;
32 OCharsetDisplay::OCharsetDisplay()
34 ,SvxTextEncodingTable()
35 , m_aSystemDisplayName(ModuleRes( STR_RSC_CHARSETS
))
39 bool OCharsetDisplay::approveEncoding( const rtl_TextEncoding _eEncoding
, const rtl_TextEncodingInfo
& _rInfo
) const
41 if ( !OCharsetMap::approveEncoding( _eEncoding
, _rInfo
) )
44 if ( RTL_TEXTENCODING_DONTKNOW
== _eEncoding
)
47 return !GetTextString(_eEncoding
).isEmpty();
50 OCharsetDisplay::const_iterator
OCharsetDisplay::begin() const
52 return const_iterator( this, OCharsetMap::begin() );
55 OCharsetDisplay::const_iterator
OCharsetDisplay::end() const
57 return const_iterator( this, OCharsetMap::end() );
60 OCharsetDisplay::const_iterator
OCharsetDisplay::findEncoding(const rtl_TextEncoding _eEncoding
) const
62 OCharsetMap::const_iterator aBaseIter
= OCharsetMap::find(_eEncoding
);
63 return const_iterator( this, aBaseIter
);
66 OCharsetDisplay::const_iterator
OCharsetDisplay::findIanaName(const OUString
& _rIanaName
) const
68 OCharsetMap::const_iterator aBaseIter
= OCharsetMap::find(_rIanaName
, OCharsetMap::IANA());
69 return const_iterator( this, aBaseIter
);
72 OCharsetDisplay::const_iterator
OCharsetDisplay::findDisplayName(const OUString
& _rDisplayName
) const
74 rtl_TextEncoding eEncoding
= RTL_TEXTENCODING_DONTKNOW
;
75 if ( _rDisplayName
!= m_aSystemDisplayName
)
77 eEncoding
= GetTextEncoding( _rDisplayName
);
78 OSL_ENSURE( RTL_TEXTENCODING_DONTKNOW
!= eEncoding
,
79 "OCharsetDisplay::find: non-empty display name, but DONTKNOW!" );
81 return const_iterator( this, OCharsetMap::find( eEncoding
) );
84 // CharsetDisplayDerefHelper
85 CharsetDisplayDerefHelper::CharsetDisplayDerefHelper(const CharsetDisplayDerefHelper
& _rSource
)
86 :CharsetDisplayDerefHelper_Base(_rSource
)
87 ,m_sDisplayName(_rSource
.m_sDisplayName
)
91 CharsetDisplayDerefHelper::CharsetDisplayDerefHelper(const CharsetDisplayDerefHelper_Base
& _rBase
, const OUString
& _rDisplayName
)
92 :CharsetDisplayDerefHelper_Base(_rBase
)
93 ,m_sDisplayName(_rDisplayName
)
95 OSL_ENSURE( !m_sDisplayName
.isEmpty(), "CharsetDisplayDerefHelper::CharsetDisplayDerefHelper: invalid display name!" );
98 // OCharsetDisplay::ExtendedCharsetIterator
99 OCharsetDisplay::ExtendedCharsetIterator::ExtendedCharsetIterator( const OCharsetDisplay
* _pContainer
, const base_iterator
& _rPosition
)
100 :m_pContainer(_pContainer
)
101 ,m_aPosition(_rPosition
)
103 OSL_ENSURE(m_pContainer
, "OCharsetDisplay::ExtendedCharsetIterator::ExtendedCharsetIterator : invalid container!");
106 OCharsetDisplay::ExtendedCharsetIterator::ExtendedCharsetIterator(const ExtendedCharsetIterator
& _rSource
)
107 :m_pContainer( _rSource
.m_pContainer
)
108 ,m_aPosition( _rSource
.m_aPosition
)
112 CharsetDisplayDerefHelper
OCharsetDisplay::ExtendedCharsetIterator::operator*() const
114 OSL_ENSURE( m_aPosition
!= m_pContainer
->OCharsetDisplay_Base::end(), "OCharsetDisplay::ExtendedCharsetIterator::operator* : invalid position!");
116 rtl_TextEncoding eEncoding
= (*m_aPosition
).getEncoding();
117 return CharsetDisplayDerefHelper(
119 RTL_TEXTENCODING_DONTKNOW
== eEncoding
? m_pContainer
->m_aSystemDisplayName
: m_pContainer
->GetTextString( eEncoding
)
123 const OCharsetDisplay::ExtendedCharsetIterator
& OCharsetDisplay::ExtendedCharsetIterator::operator++()
125 OSL_ENSURE( m_aPosition
!= m_pContainer
->OCharsetDisplay_Base::end(), "OCharsetDisplay::ExtendedCharsetIterator::operator++ : invalid position!");
126 if ( m_aPosition
!= m_pContainer
->OCharsetDisplay_Base::end() )
131 const OCharsetDisplay::ExtendedCharsetIterator
& OCharsetDisplay::ExtendedCharsetIterator::operator--()
133 OSL_ENSURE( m_aPosition
!= m_pContainer
->OCharsetDisplay_Base::begin(), "OCharsetDisplay::ExtendedCharsetIterator::operator-- : invalid position!");
134 if ( m_aPosition
!= m_pContainer
->OCharsetDisplay_Base::begin() )
139 bool operator==(const OCharsetDisplay::ExtendedCharsetIterator
& lhs
, const OCharsetDisplay::ExtendedCharsetIterator
& rhs
)
141 return (lhs
.m_pContainer
== rhs
.m_pContainer
) && (lhs
.m_aPosition
== rhs
.m_aPosition
);
146 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */