LibreOffice Module dbaccess (master) 1
charsets.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20#include <charsets.hxx>
21#include <core_resource.hxx>
22#include <osl/diagnose.h>
23#include <strings.hrc>
24#include <rtl/tencinfo.h>
25#include <svx/txenctab.hxx>
26#include <utility>
27
28namespace dbaui
29{
30 using namespace ::dbtools;
31
32 // OCharsetDisplay
34 : m_aSystemDisplayName(DBA_RES( STR_RSC_CHARSETS ))
35 {
36 }
37
38 bool OCharsetDisplay::approveEncoding( const rtl_TextEncoding _eEncoding, const rtl_TextEncodingInfo& _rInfo ) const
39 {
40 if ( !OCharsetMap::approveEncoding( _eEncoding, _rInfo ) )
41 return false;
42
43 if ( RTL_TEXTENCODING_DONTKNOW == _eEncoding )
44 return true;
45
46 return !SvxTextEncodingTable::GetTextString(_eEncoding).isEmpty();
47 }
48
50 {
51 return const_iterator( this, OCharsetMap::begin() );
52 }
53
55 {
56 return const_iterator( this, OCharsetMap::end() );
57 }
58
59 OCharsetDisplay::const_iterator OCharsetDisplay::findEncoding(const rtl_TextEncoding _eEncoding) const
60 {
61 OCharsetMap::const_iterator aBaseIter = OCharsetMap::find(_eEncoding);
62 return const_iterator( this, aBaseIter );
63 }
64
66 {
68 return const_iterator( this, aBaseIter );
69 }
70
72 {
73 rtl_TextEncoding eEncoding = RTL_TEXTENCODING_DONTKNOW;
74 if ( _rDisplayName != m_aSystemDisplayName )
75 {
76 eEncoding = SvxTextEncodingTable::GetTextEncoding(_rDisplayName);
77 OSL_ENSURE( RTL_TEXTENCODING_DONTKNOW != eEncoding,
78 "OCharsetDisplay::find: non-empty display name, but DONTKNOW!" );
79 }
80 return const_iterator( this, OCharsetMap::find( eEncoding ) );
81 }
82
83 // CharsetDisplayDerefHelper
86 ,m_sDisplayName(_rSource.m_sDisplayName)
87 {
88 }
89
90 CharsetDisplayDerefHelper::CharsetDisplayDerefHelper(const ::dbtools::CharsetIteratorDerefHelper& _rBase, OUString _sDisplayName)
92 ,m_sDisplayName(std::move(_sDisplayName))
93 {
94 OSL_ENSURE( !m_sDisplayName.isEmpty(), "CharsetDisplayDerefHelper::CharsetDisplayDerefHelper: invalid display name!" );
95 }
96
97 // OCharsetDisplay::ExtendedCharsetIterator
99 :m_pContainer(_pContainer)
100 ,m_aPosition(std::move(_aPosition))
101 {
102 OSL_ENSURE(m_pContainer, "OCharsetDisplay::ExtendedCharsetIterator::ExtendedCharsetIterator : invalid container!");
103 }
104
106 {
107 OSL_ENSURE( m_aPosition != m_pContainer->OCharsetDisplay_Base::end(), "OCharsetDisplay::ExtendedCharsetIterator::operator* : invalid position!");
108
109 rtl_TextEncoding eEncoding = (*m_aPosition).getEncoding();
111 *m_aPosition,
112 RTL_TEXTENCODING_DONTKNOW == eEncoding ? m_pContainer->m_aSystemDisplayName : SvxTextEncodingTable::GetTextString(eEncoding)
113 );
114 }
115
117 {
118 OSL_ENSURE( m_aPosition != m_pContainer->OCharsetDisplay_Base::end(), "OCharsetDisplay::ExtendedCharsetIterator::operator++ : invalid position!");
119 if ( m_aPosition != m_pContainer->OCharsetDisplay_Base::end() )
120 ++m_aPosition;
121 return *this;
122 }
123
125 {
126 return (lhs.m_pContainer == rhs.m_pContainer) && (lhs.m_aPosition == rhs.m_aPosition);
127 }
128
129} // namespace dbaui
130
131/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
static rtl_TextEncoding GetTextEncoding(const OUString &rStr)
static OUString GetTextString(const rtl_TextEncoding nEnc)
CharsetDisplayDerefHelper(const CharsetDisplayDerefHelper &_rSource)
Definition: charsets.cxx:84
ExtendedCharsetIterator(const OCharsetDisplay *_pContainer, base_iterator _aPosition)
Definition: charsets.cxx:98
CharsetDisplayDerefHelper operator*() const
Definition: charsets.cxx:105
const ExtendedCharsetIterator & operator++()
prefix increment
Definition: charsets.cxx:116
container::CharsetIterator base_iterator
Definition: charsets.hxx:87
const_iterator findIanaName(std::u16string_view _rIanaName) const
Definition: charsets.cxx:65
const_iterator findEncoding(const rtl_TextEncoding _eEncoding) const
Definition: charsets.cxx:59
virtual bool approveEncoding(const rtl_TextEncoding _eEncoding, const rtl_TextEncodingInfo &_rInfo) const override
Definition: charsets.cxx:38
OUString m_aSystemDisplayName
Definition: charsets.hxx:33
const_iterator findDisplayName(const OUString &_rDisplayName) const
Definition: charsets.cxx:71
ExtendedCharsetIterator const_iterator
Definition: charsets.hxx:40
const_iterator begin() const
get access to the first element of the charset collection
Definition: charsets.cxx:49
const_iterator end() const
get access to the (last + 1st) element of the charset collection
Definition: charsets.cxx:54
CharsetIterator const_iterator
virtual bool approveEncoding(const rtl_TextEncoding _eEncoding, const rtl_TextEncodingInfo &_rInfo) const
CharsetIterator findIanaName(std::u16string_view _rIanaName) const
friend friend OOO_DLLPUBLIC_DBTOOLS bool operator==(const CharsetIterator &lhs, const CharsetIterator &rhs)
CharsetIterator find(const rtl_TextEncoding _eEncoding) const
CharsetIterator end() const
CharsetIterator begin() const
const OCharsetMap * m_pContainer
#define DBA_RES(id)