1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 // MARKER(update_precomp.py): autogen include statement, do not remove 29 #include "precompiled_xmloff.hxx" 30 #include <rtl/ustring.hxx> 31 #include <tools/debug.hxx> 32 #include <svl/svarray.hxx> 33 #include "xmloff/i18nmap.hxx" 34 35 using namespace rtl; 36 37 class SvI18NMapEntry_Impl 38 { 39 sal_uInt16 nKind; 40 OUString aName; 41 OUString aNewName; 42 43 public: 44 45 const OUString& GetNewName() const { return aNewName; } 46 47 SvI18NMapEntry_Impl( sal_uInt16 nKnd, const OUString& rName, 48 const OUString& rNewName ) : 49 nKind( nKnd ), 50 aName( rName ), 51 aNewName( rNewName ) 52 {} 53 54 SvI18NMapEntry_Impl( sal_uInt16 nKnd, const OUString& rName ) : 55 nKind( nKnd ), 56 aName( rName ) 57 {} 58 59 sal_Bool operator==( const SvI18NMapEntry_Impl& r ) const 60 { 61 return nKind == r.nKind && 62 aName == r.aName; 63 } 64 65 sal_Bool operator<( const SvI18NMapEntry_Impl& r ) const 66 { 67 return nKind < r.nKind || 68 ( nKind == r.nKind && 69 aName < r.aName); 70 } 71 }; 72 73 typedef SvI18NMapEntry_Impl *SvI18NMapEntry_ImplPtr; 74 SV_DECL_PTRARR_SORT_DEL( SvI18NMap_Impl, SvI18NMapEntry_ImplPtr, 20, 5 ) 75 SV_IMPL_OP_PTRARR_SORT( SvI18NMap_Impl, SvI18NMapEntry_ImplPtr ) 76 77 // --------------------------------------------------------------------- 78 79 SvI18NMapEntry_Impl *SvI18NMap::_Find( sal_uInt16 nKind, 80 const OUString& rName ) const 81 { 82 SvI18NMapEntry_Impl *pRet = 0; 83 SvI18NMapEntry_Impl aTst( nKind, rName ); 84 85 sal_uInt16 nPos; 86 if( pImpl->Seek_Entry( &aTst, &nPos ) ) 87 { 88 pRet = (*pImpl)[nPos]; 89 } 90 91 return pRet; 92 } 93 94 SvI18NMap::SvI18NMap() : 95 pImpl( 0 ) 96 { 97 pImpl = new SvI18NMap_Impl; 98 } 99 100 SvI18NMap::~SvI18NMap() 101 { 102 delete pImpl; 103 } 104 105 void SvI18NMap::Add( sal_uInt16 nKind, const OUString& rName, 106 const OUString& rNewName ) 107 { 108 SvI18NMapEntry_Impl *pEntry = _Find( nKind, rName ); 109 DBG_ASSERT( !pEntry, "SvI18NMap::Add: item registered already" ); 110 if( !pEntry ) 111 { 112 pEntry = new SvI18NMapEntry_Impl( nKind, rName, rNewName ); 113 pImpl->Insert( pEntry ); 114 } 115 } 116 117 const OUString& SvI18NMap::Get( sal_uInt16 nKind, const OUString& rName ) const 118 { 119 SvI18NMapEntry_Impl *pEntry = _Find( nKind, rName ); 120 if( pEntry ) 121 return pEntry->GetNewName(); 122 else 123 return rName; 124 } 125 126 127