1*6a302a70SAndrew Rist/************************************************************** 2cdf0e10cSrcweir * 3*6a302a70SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*6a302a70SAndrew Rist * or more contributor license agreements. See the NOTICE file 5*6a302a70SAndrew Rist * distributed with this work for additional information 6*6a302a70SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*6a302a70SAndrew Rist * to you under the Apache License, Version 2.0 (the 8*6a302a70SAndrew Rist * "License"); you may not use this file except in compliance 9*6a302a70SAndrew Rist * with the License. You may obtain a copy of the License at 10*6a302a70SAndrew Rist * 11*6a302a70SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12*6a302a70SAndrew Rist * 13*6a302a70SAndrew Rist * Unless required by applicable law or agreed to in writing, 14*6a302a70SAndrew Rist * software distributed under the License is distributed on an 15*6a302a70SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*6a302a70SAndrew Rist * KIND, either express or implied. See the License for the 17*6a302a70SAndrew Rist * specific language governing permissions and limitations 18*6a302a70SAndrew Rist * under the License. 19*6a302a70SAndrew Rist * 20*6a302a70SAndrew Rist *************************************************************/ 21cdf0e10cSrcweir 22cdf0e10cSrcweir#ifndef _UCB_REGEXPMAP_TPT_ 23cdf0e10cSrcweir#define _UCB_REGEXPMAP_TPT_ 24cdf0e10cSrcweir 25cdf0e10cSrcweir#ifndef _UCB_REGEXPMAP_HXX_ 26cdf0e10cSrcweir#include <regexpmap.hxx> 27cdf0e10cSrcweir#endif 28cdf0e10cSrcweir 29cdf0e10cSrcweir#include <list> 30cdf0e10cSrcweir 31cdf0e10cSrcweir#ifndef _RTL_USTRING_HXX_ 32cdf0e10cSrcweir#include <rtl/ustring.hxx> 33cdf0e10cSrcweir#endif 34cdf0e10cSrcweir 35cdf0e10cSrcweir#ifndef _UCB_REGEXP_HXX_ 36cdf0e10cSrcweir#include "regexp.hxx" 37cdf0e10cSrcweir#endif 38cdf0e10cSrcweir 39cdf0e10cSrcweirusing namespace ucb_impl; 40cdf0e10cSrcweir 41cdf0e10cSrcweirnamespace ucb_impl { 42cdf0e10cSrcweir 43cdf0e10cSrcweir//============================================================================ 44cdf0e10cSrcweir 45cdf0e10cSrcweirtemplate< typename Val > 46cdf0e10cSrcweirstruct Entry 47cdf0e10cSrcweir{ 48cdf0e10cSrcweir Regexp m_aRegexp; 49cdf0e10cSrcweir Val m_aValue; 50cdf0e10cSrcweir 51cdf0e10cSrcweir inline Entry(Regexp const & rTheRegexp, Val const & rTheValue): 52cdf0e10cSrcweir m_aRegexp(rTheRegexp), m_aValue(rTheValue) {} 53cdf0e10cSrcweir}; 54cdf0e10cSrcweir 55cdf0e10cSrcweir//============================================================================ 56cdf0e10cSrcweirtemplate< typename Val > class List: public std::list< Entry< Val > > {}; 57cdf0e10cSrcweir 58cdf0e10cSrcweir//============================================================================ 59cdf0e10cSrcweir// 60cdf0e10cSrcweir// RegexpMapIterImpl 61cdf0e10cSrcweir// 62cdf0e10cSrcweir//============================================================================ 63cdf0e10cSrcweir 64cdf0e10cSrcweirtemplate< typename Val > 65cdf0e10cSrcweirclass RegexpMapIterImpl 66cdf0e10cSrcweir{ 67cdf0e10cSrcweirpublic: 68cdf0e10cSrcweir typedef RegexpMapImpl< Val > MapImpl; 69cdf0e10cSrcweir typedef typename List< Val >::iterator ListIterator; 70cdf0e10cSrcweir 71cdf0e10cSrcweir // Solaris needs these for the ctor... 72cdf0e10cSrcweir 73cdf0e10cSrcweir inline RegexpMapIterImpl(); 74cdf0e10cSrcweir 75cdf0e10cSrcweir inline RegexpMapIterImpl(MapImpl * pTheMap, int nTheList, 76cdf0e10cSrcweir ListIterator aTheIndex); 77cdf0e10cSrcweir 78cdf0e10cSrcweir RegexpMapIterImpl(RegexpMapImpl< Val > * pTheMap, bool bBegin); 79cdf0e10cSrcweir 80cdf0e10cSrcweir bool operator ==(RegexpMapIterImpl const & rOther) const; 81cdf0e10cSrcweir 82cdf0e10cSrcweir RegexpMapImpl< Val > const * getMap() const { return m_pMap; } 83cdf0e10cSrcweir 84cdf0e10cSrcweir int getList() const { return m_nList; } 85cdf0e10cSrcweir 86cdf0e10cSrcweir typename List< Val >::iterator const & getIndex() const { return m_aIndex; } 87cdf0e10cSrcweir 88cdf0e10cSrcweir void next(); 89cdf0e10cSrcweir 90cdf0e10cSrcweir RegexpMapEntry< Val > & get(); 91cdf0e10cSrcweir 92cdf0e10cSrcweirprivate: 93cdf0e10cSrcweir mutable RegexpMapEntry< Val > m_aEntry; 94cdf0e10cSrcweir typename List< Val >::iterator m_aIndex; 95cdf0e10cSrcweir RegexpMapImpl< Val > * m_pMap; 96cdf0e10cSrcweir int m_nList; 97cdf0e10cSrcweir mutable bool m_bEntrySet; 98cdf0e10cSrcweir 99cdf0e10cSrcweir void setEntry() const; 100cdf0e10cSrcweir}; 101cdf0e10cSrcweir 102cdf0e10cSrcweir} 103cdf0e10cSrcweir 104cdf0e10cSrcweirtemplate< typename Val > 105cdf0e10cSrcweirinline RegexpMapIterImpl< Val >::RegexpMapIterImpl(): 106cdf0e10cSrcweir m_aEntry(rtl::OUString(), 0), 107cdf0e10cSrcweir m_pMap(0), 108cdf0e10cSrcweir m_nList(-1), 109cdf0e10cSrcweir m_bEntrySet(false) 110cdf0e10cSrcweir{} 111cdf0e10cSrcweir 112cdf0e10cSrcweirtemplate< typename Val > 113cdf0e10cSrcweirinline RegexpMapIterImpl< Val >::RegexpMapIterImpl(MapImpl * pTheMap, 114cdf0e10cSrcweir int nTheList, 115cdf0e10cSrcweir ListIterator aTheIndex): 116cdf0e10cSrcweir m_aEntry(rtl::OUString(), 0), 117cdf0e10cSrcweir m_aIndex(aTheIndex), 118cdf0e10cSrcweir m_pMap(pTheMap), 119cdf0e10cSrcweir m_nList(nTheList), 120cdf0e10cSrcweir m_bEntrySet(false) 121cdf0e10cSrcweir{} 122cdf0e10cSrcweir 123cdf0e10cSrcweir//============================================================================ 124cdf0e10cSrcweirtemplate< typename Val > 125cdf0e10cSrcweirvoid RegexpMapIterImpl< Val >::setEntry() const 126cdf0e10cSrcweir{ 127cdf0e10cSrcweir if (!m_bEntrySet) 128cdf0e10cSrcweir { 129cdf0e10cSrcweir Entry< Val > const & rTheEntry 130cdf0e10cSrcweir = m_nList == -1 ? *m_pMap->m_pDefault : *m_aIndex; 131cdf0e10cSrcweir m_aEntry 132cdf0e10cSrcweir = RegexpMapEntry< Val >(rTheEntry.m_aRegexp.getRegexp(false), 133cdf0e10cSrcweir const_cast< Val * >(&rTheEntry.m_aValue)); 134cdf0e10cSrcweir m_bEntrySet = true; 135cdf0e10cSrcweir } 136cdf0e10cSrcweir} 137cdf0e10cSrcweir 138cdf0e10cSrcweir//============================================================================ 139cdf0e10cSrcweirtemplate< typename Val > 140cdf0e10cSrcweirRegexpMapIterImpl< Val >::RegexpMapIterImpl(RegexpMapImpl< Val > * pTheMap, 141cdf0e10cSrcweir bool bBegin): 142cdf0e10cSrcweir m_aEntry(rtl::OUString(), 0), 143cdf0e10cSrcweir m_pMap(pTheMap), 144cdf0e10cSrcweir m_bEntrySet(false) 145cdf0e10cSrcweir{ 146cdf0e10cSrcweir if (bBegin) 147cdf0e10cSrcweir { 148cdf0e10cSrcweir m_nList = -1; 149cdf0e10cSrcweir m_aIndex = typename List< Val >::iterator(); 150cdf0e10cSrcweir if (!m_pMap->m_pDefault) 151cdf0e10cSrcweir next(); 152cdf0e10cSrcweir } 153cdf0e10cSrcweir else 154cdf0e10cSrcweir { 155cdf0e10cSrcweir m_nList = Regexp::KIND_DOMAIN; 156cdf0e10cSrcweir m_aIndex = m_pMap->m_aList[Regexp::KIND_DOMAIN].end(); 157cdf0e10cSrcweir } 158cdf0e10cSrcweir} 159cdf0e10cSrcweir 160cdf0e10cSrcweir//============================================================================ 161cdf0e10cSrcweirtemplate< typename Val > 162cdf0e10cSrcweirbool RegexpMapIterImpl< Val >::operator ==(RegexpMapIterImpl const & rOther) 163cdf0e10cSrcweir const 164cdf0e10cSrcweir{ 165cdf0e10cSrcweir return m_pMap == rOther.m_pMap 166cdf0e10cSrcweir && m_nList == rOther.m_nList 167cdf0e10cSrcweir && m_aIndex == rOther.m_aIndex; 168cdf0e10cSrcweir} 169cdf0e10cSrcweir 170cdf0e10cSrcweir//============================================================================ 171cdf0e10cSrcweirtemplate< typename Val > 172cdf0e10cSrcweirvoid RegexpMapIterImpl< Val >::next() 173cdf0e10cSrcweir{ 174cdf0e10cSrcweir switch (m_nList) 175cdf0e10cSrcweir { 176cdf0e10cSrcweir case Regexp::KIND_DOMAIN: 177cdf0e10cSrcweir if (m_aIndex == m_pMap->m_aList[m_nList].end()) 178cdf0e10cSrcweir return; 179cdf0e10cSrcweir default: 180cdf0e10cSrcweir ++m_aIndex; 181cdf0e10cSrcweir if (m_nList == Regexp::KIND_DOMAIN 182cdf0e10cSrcweir || m_aIndex != m_pMap->m_aList[m_nList].end()) 183cdf0e10cSrcweir break; 184cdf0e10cSrcweir case -1: 185cdf0e10cSrcweir do 186cdf0e10cSrcweir { 187cdf0e10cSrcweir ++m_nList; 188cdf0e10cSrcweir m_aIndex = m_pMap->m_aList[m_nList].begin(); 189cdf0e10cSrcweir } 190cdf0e10cSrcweir while (m_nList < Regexp::KIND_DOMAIN 191cdf0e10cSrcweir && m_aIndex == m_pMap->m_aList[m_nList].end()); 192cdf0e10cSrcweir break; 193cdf0e10cSrcweir } 194cdf0e10cSrcweir m_bEntrySet = false; 195cdf0e10cSrcweir} 196cdf0e10cSrcweir 197cdf0e10cSrcweir//============================================================================ 198cdf0e10cSrcweirtemplate< typename Val > 199cdf0e10cSrcweirRegexpMapEntry< Val > & RegexpMapIterImpl< Val >::get() 200cdf0e10cSrcweir{ 201cdf0e10cSrcweir setEntry(); 202cdf0e10cSrcweir return m_aEntry; 203cdf0e10cSrcweir} 204cdf0e10cSrcweir 205cdf0e10cSrcweir//============================================================================ 206cdf0e10cSrcweir// 207cdf0e10cSrcweir// RegexpMapConstIter 208cdf0e10cSrcweir// 209cdf0e10cSrcweir//============================================================================ 210cdf0e10cSrcweir 211cdf0e10cSrcweirtemplate< typename Val > 212cdf0e10cSrcweirRegexpMapConstIter< Val >::RegexpMapConstIter(RegexpMapIterImpl< Val > * 213cdf0e10cSrcweir pTheImpl): 214cdf0e10cSrcweir m_pImpl(pTheImpl) 215cdf0e10cSrcweir{} 216cdf0e10cSrcweir 217cdf0e10cSrcweir//============================================================================ 218cdf0e10cSrcweirtemplate< typename Val > 219cdf0e10cSrcweirRegexpMapConstIter< Val >::RegexpMapConstIter(): 220cdf0e10cSrcweir m_pImpl(new RegexpMapIterImpl< Val >) 221cdf0e10cSrcweir{} 222cdf0e10cSrcweir 223cdf0e10cSrcweir//============================================================================ 224cdf0e10cSrcweirtemplate< typename Val > 225cdf0e10cSrcweirRegexpMapConstIter< Val >::RegexpMapConstIter(RegexpMapConstIter const & 226cdf0e10cSrcweir rOther): 227cdf0e10cSrcweir m_pImpl(new RegexpMapIterImpl< Val >(*rOther.m_pImpl)) 228cdf0e10cSrcweir{} 229cdf0e10cSrcweir 230cdf0e10cSrcweir//============================================================================ 231cdf0e10cSrcweirtemplate< typename Val > 232cdf0e10cSrcweirRegexpMapConstIter< Val >::~RegexpMapConstIter() 233cdf0e10cSrcweir{ 234cdf0e10cSrcweir delete m_pImpl; 235cdf0e10cSrcweir} 236cdf0e10cSrcweir 237cdf0e10cSrcweir//============================================================================ 238cdf0e10cSrcweirtemplate< typename Val > 239cdf0e10cSrcweirRegexpMapConstIter< Val > & 240cdf0e10cSrcweirRegexpMapConstIter< Val >::operator =(RegexpMapConstIter const & rOther) 241cdf0e10cSrcweir{ 242cdf0e10cSrcweir *m_pImpl = *rOther.m_pImpl; 243cdf0e10cSrcweir return *this; 244cdf0e10cSrcweir} 245cdf0e10cSrcweir 246cdf0e10cSrcweir//============================================================================ 247cdf0e10cSrcweirtemplate< typename Val > 248cdf0e10cSrcweirRegexpMapConstIter< Val > & RegexpMapConstIter< Val >::operator ++() 249cdf0e10cSrcweir{ 250cdf0e10cSrcweir m_pImpl->next(); 251cdf0e10cSrcweir return *this; 252cdf0e10cSrcweir} 253cdf0e10cSrcweir 254cdf0e10cSrcweir//============================================================================ 255cdf0e10cSrcweirtemplate< typename Val > 256cdf0e10cSrcweirRegexpMapConstIter< Val > RegexpMapConstIter< Val >::operator ++(int) 257cdf0e10cSrcweir{ 258cdf0e10cSrcweir RegexpMapConstIter aTemp(*this); 259cdf0e10cSrcweir m_pImpl->next(); 260cdf0e10cSrcweir return aTemp; 261cdf0e10cSrcweir} 262cdf0e10cSrcweir 263cdf0e10cSrcweir//============================================================================ 264cdf0e10cSrcweirtemplate< typename Val > 265cdf0e10cSrcweirRegexpMapEntry< Val > const & RegexpMapConstIter< Val >::operator *() const 266cdf0e10cSrcweir{ 267cdf0e10cSrcweir return m_pImpl->get(); 268cdf0e10cSrcweir} 269cdf0e10cSrcweir 270cdf0e10cSrcweir//============================================================================ 271cdf0e10cSrcweirtemplate< typename Val > 272cdf0e10cSrcweirRegexpMapEntry< Val > const * RegexpMapConstIter< Val >::operator ->() const 273cdf0e10cSrcweir{ 274cdf0e10cSrcweir return &m_pImpl->get(); 275cdf0e10cSrcweir} 276cdf0e10cSrcweir 277cdf0e10cSrcweir//============================================================================ 278cdf0e10cSrcweirtemplate< typename Val > 279cdf0e10cSrcweirbool RegexpMapConstIter< Val >::equals(RegexpMapConstIter const & rOther) 280cdf0e10cSrcweir const 281cdf0e10cSrcweir{ 282cdf0e10cSrcweir return *m_pImpl == *rOther.m_pImpl; 283cdf0e10cSrcweir} 284cdf0e10cSrcweir 285cdf0e10cSrcweir//============================================================================ 286cdf0e10cSrcweir// 287cdf0e10cSrcweir// RegexpMapIter 288cdf0e10cSrcweir// 289cdf0e10cSrcweir//============================================================================ 290cdf0e10cSrcweir 291cdf0e10cSrcweirtemplate< typename Val > 292cdf0e10cSrcweirRegexpMapIter< Val >::RegexpMapIter(RegexpMapIterImpl< Val > * pTheImpl): 293cdf0e10cSrcweir RegexpMapConstIter< Val >(pTheImpl) 294cdf0e10cSrcweir{} 295cdf0e10cSrcweir 296cdf0e10cSrcweir//============================================================================ 297cdf0e10cSrcweirtemplate< typename Val > 298cdf0e10cSrcweirRegexpMapIter< Val > & RegexpMapIter< Val >::operator ++() 299cdf0e10cSrcweir{ 300cdf0e10cSrcweir this->m_pImpl->next(); 301cdf0e10cSrcweir return *this; 302cdf0e10cSrcweir} 303cdf0e10cSrcweir 304cdf0e10cSrcweir//============================================================================ 305cdf0e10cSrcweirtemplate< typename Val > 306cdf0e10cSrcweirRegexpMapIter< Val > RegexpMapIter< Val >::operator ++(int) 307cdf0e10cSrcweir{ 308cdf0e10cSrcweir RegexpMapIter aTemp(*this); 309cdf0e10cSrcweir this->m_pImpl->next(); 310cdf0e10cSrcweir return aTemp; 311cdf0e10cSrcweir} 312cdf0e10cSrcweir 313cdf0e10cSrcweir//============================================================================ 314cdf0e10cSrcweirtemplate< typename Val > 315cdf0e10cSrcweirRegexpMapEntry< Val > & RegexpMapIter< Val >::operator *() 316cdf0e10cSrcweir{ 317cdf0e10cSrcweir return this->m_pImpl->get(); 318cdf0e10cSrcweir} 319cdf0e10cSrcweir 320cdf0e10cSrcweir//============================================================================ 321cdf0e10cSrcweirtemplate< typename Val > 322cdf0e10cSrcweirRegexpMapEntry< Val > const & RegexpMapIter< Val >::operator *() const 323cdf0e10cSrcweir{ 324cdf0e10cSrcweir return this->m_pImpl->get(); 325cdf0e10cSrcweir} 326cdf0e10cSrcweir 327cdf0e10cSrcweir//============================================================================ 328cdf0e10cSrcweirtemplate< typename Val > 329cdf0e10cSrcweirRegexpMapEntry< Val > * RegexpMapIter< Val >::operator ->() 330cdf0e10cSrcweir{ 331cdf0e10cSrcweir return &this->m_pImpl->get(); 332cdf0e10cSrcweir} 333cdf0e10cSrcweir 334cdf0e10cSrcweir//============================================================================ 335cdf0e10cSrcweirtemplate< typename Val > 336cdf0e10cSrcweirRegexpMapEntry< Val > const * RegexpMapIter< Val >::operator ->() const 337cdf0e10cSrcweir{ 338cdf0e10cSrcweir return &this->m_pImpl->get(); 339cdf0e10cSrcweir} 340cdf0e10cSrcweir 341cdf0e10cSrcweir//============================================================================ 342cdf0e10cSrcweir// 343cdf0e10cSrcweir// RegexpMap 344cdf0e10cSrcweir// 345cdf0e10cSrcweir//============================================================================ 346cdf0e10cSrcweir 347cdf0e10cSrcweirnamespace ucb_impl { 348cdf0e10cSrcweir 349cdf0e10cSrcweirtemplate< typename Val > 350cdf0e10cSrcweirstruct RegexpMapImpl 351cdf0e10cSrcweir{ 352cdf0e10cSrcweir List< Val > m_aList[Regexp::KIND_DOMAIN + 1]; 353cdf0e10cSrcweir Entry< Val > * m_pDefault; 354cdf0e10cSrcweir 355cdf0e10cSrcweir RegexpMapImpl(): m_pDefault(0) {} 356cdf0e10cSrcweir 357cdf0e10cSrcweir ~RegexpMapImpl() { delete m_pDefault; } 358cdf0e10cSrcweir}; 359cdf0e10cSrcweir 360cdf0e10cSrcweir} 361cdf0e10cSrcweir 362cdf0e10cSrcweir//============================================================================ 363cdf0e10cSrcweirtemplate< typename Val > 364cdf0e10cSrcweirRegexpMap< Val >::RegexpMap(): 365cdf0e10cSrcweir m_pImpl(new RegexpMapImpl< Val >) 366cdf0e10cSrcweir{} 367cdf0e10cSrcweir 368cdf0e10cSrcweir//============================================================================ 369cdf0e10cSrcweirtemplate< typename Val > 370cdf0e10cSrcweirRegexpMap< Val >::RegexpMap(RegexpMap const & rOther): 371cdf0e10cSrcweir m_pImpl(new RegexpMapImpl< Val >(*rOther.m_pImpl)) 372cdf0e10cSrcweir{} 373cdf0e10cSrcweir 374cdf0e10cSrcweir//============================================================================ 375cdf0e10cSrcweirtemplate< typename Val > 376cdf0e10cSrcweirRegexpMap< Val >::~RegexpMap() 377cdf0e10cSrcweir{ 378cdf0e10cSrcweir delete m_pImpl; 379cdf0e10cSrcweir} 380cdf0e10cSrcweir 381cdf0e10cSrcweir//============================================================================ 382cdf0e10cSrcweirtemplate< typename Val > 383cdf0e10cSrcweirRegexpMap< Val > & RegexpMap< Val >::operator =(RegexpMap const & rOther) 384cdf0e10cSrcweir{ 385cdf0e10cSrcweir *m_pImpl = *rOther.m_pImpl; 386cdf0e10cSrcweir return *this; 387cdf0e10cSrcweir} 388cdf0e10cSrcweir 389cdf0e10cSrcweir//============================================================================ 390cdf0e10cSrcweirtemplate< typename Val > 391cdf0e10cSrcweirbool RegexpMap< Val >::add(rtl::OUString const & rKey, Val const & rValue, 392cdf0e10cSrcweir bool bOverwrite, rtl::OUString * pReverse) 393cdf0e10cSrcweir{ 394cdf0e10cSrcweir Regexp aRegexp(Regexp::parse(rKey)); 395cdf0e10cSrcweir 396cdf0e10cSrcweir if (aRegexp.isDefault()) 397cdf0e10cSrcweir { 398cdf0e10cSrcweir if (m_pImpl->m_pDefault) 399cdf0e10cSrcweir { 400cdf0e10cSrcweir if (!bOverwrite) 401cdf0e10cSrcweir return false; 402cdf0e10cSrcweir delete m_pImpl->m_pDefault; 403cdf0e10cSrcweir } 404cdf0e10cSrcweir m_pImpl->m_pDefault = new Entry< Val >(aRegexp, rValue); 405cdf0e10cSrcweir } 406cdf0e10cSrcweir else 407cdf0e10cSrcweir { 408cdf0e10cSrcweir List< Val > & rTheList = m_pImpl->m_aList[aRegexp.getKind()]; 409cdf0e10cSrcweir 410cdf0e10cSrcweir typename List< Val >::iterator aEnd(rTheList.end()); 411cdf0e10cSrcweir for (typename List< Val >::iterator aIt(rTheList.begin()); aIt != aEnd; ++aIt) 412cdf0e10cSrcweir { 413cdf0e10cSrcweir if (aIt->m_aRegexp == aRegexp) 414cdf0e10cSrcweir { 415cdf0e10cSrcweir if (bOverwrite) 416cdf0e10cSrcweir { 417cdf0e10cSrcweir rTheList.erase(aIt); 418cdf0e10cSrcweir break; 419cdf0e10cSrcweir } 420cdf0e10cSrcweir else 421cdf0e10cSrcweir return false; 422cdf0e10cSrcweir } 423cdf0e10cSrcweir } 424cdf0e10cSrcweir 425cdf0e10cSrcweir rTheList.push_back(Entry< Val >(aRegexp, rValue)); 426cdf0e10cSrcweir } 427cdf0e10cSrcweir 428cdf0e10cSrcweir if (pReverse) 429cdf0e10cSrcweir *pReverse = aRegexp.getRegexp(true); 430cdf0e10cSrcweir 431cdf0e10cSrcweir return true; 432cdf0e10cSrcweir} 433cdf0e10cSrcweir 434cdf0e10cSrcweir//============================================================================ 435cdf0e10cSrcweirtemplate< typename Val > 436cdf0e10cSrcweirtypename RegexpMap< Val >::iterator RegexpMap< Val >::find(rtl::OUString const & rKey, 437cdf0e10cSrcweir rtl::OUString * pReverse) 438cdf0e10cSrcweir{ 439cdf0e10cSrcweir Regexp aRegexp(Regexp::parse(rKey)); 440cdf0e10cSrcweir 441cdf0e10cSrcweir if (pReverse) 442cdf0e10cSrcweir *pReverse = aRegexp.getRegexp(true); 443cdf0e10cSrcweir 444cdf0e10cSrcweir if (aRegexp.isDefault()) 445cdf0e10cSrcweir { 446cdf0e10cSrcweir if (m_pImpl->m_pDefault) 447cdf0e10cSrcweir return RegexpMapIter< Val >(new RegexpMapIterImpl< Val >(m_pImpl, 448cdf0e10cSrcweir true)); 449cdf0e10cSrcweir } 450cdf0e10cSrcweir else 451cdf0e10cSrcweir { 452cdf0e10cSrcweir List< Val > & rTheList = m_pImpl->m_aList[aRegexp.getKind()]; 453cdf0e10cSrcweir 454cdf0e10cSrcweir typename List< Val > ::iterator aEnd(rTheList.end()); 455cdf0e10cSrcweir for (typename List< Val >::iterator aIt(rTheList.begin()); aIt != aEnd; ++aIt) 456cdf0e10cSrcweir if (aIt->m_aRegexp == aRegexp) 457cdf0e10cSrcweir return RegexpMapIter< Val >(new RegexpMapIterImpl< Val >( 458cdf0e10cSrcweir m_pImpl, 459cdf0e10cSrcweir aRegexp.getKind(), aIt)); 460cdf0e10cSrcweir } 461cdf0e10cSrcweir 462cdf0e10cSrcweir return RegexpMapIter< Val >(new RegexpMapIterImpl< Val >(m_pImpl, false)); 463cdf0e10cSrcweir} 464cdf0e10cSrcweir 465cdf0e10cSrcweir//============================================================================ 466cdf0e10cSrcweirtemplate< typename Val > 467cdf0e10cSrcweirvoid RegexpMap< Val >::erase(iterator const & rPos) 468cdf0e10cSrcweir{ 469cdf0e10cSrcweir if (rPos.m_pImpl->getMap() == m_pImpl) 470cdf0e10cSrcweir { 471cdf0e10cSrcweir if (rPos.m_pImpl->getList() == -1) 472cdf0e10cSrcweir { 473cdf0e10cSrcweir if (m_pImpl->m_pDefault) 474cdf0e10cSrcweir { 475cdf0e10cSrcweir delete m_pImpl->m_pDefault; 476cdf0e10cSrcweir m_pImpl->m_pDefault = 0; 477cdf0e10cSrcweir } 478cdf0e10cSrcweir } 479cdf0e10cSrcweir else 480cdf0e10cSrcweir m_pImpl->m_aList[rPos.m_pImpl->getList()]. 481cdf0e10cSrcweir erase(rPos.m_pImpl->getIndex()); 482cdf0e10cSrcweir } 483cdf0e10cSrcweir} 484cdf0e10cSrcweir 485cdf0e10cSrcweir//============================================================================ 486cdf0e10cSrcweirtemplate< typename Val > 487cdf0e10cSrcweirtypename RegexpMap< Val >::iterator RegexpMap< Val >::begin() 488cdf0e10cSrcweir{ 489cdf0e10cSrcweir return RegexpMapIter< Val >(new RegexpMapIterImpl< Val >(m_pImpl, true)); 490cdf0e10cSrcweir} 491cdf0e10cSrcweir 492cdf0e10cSrcweir//============================================================================ 493cdf0e10cSrcweirtemplate< typename Val > 494cdf0e10cSrcweirtypename RegexpMap< Val >::const_iterator RegexpMap< Val >::begin() const 495cdf0e10cSrcweir{ 496cdf0e10cSrcweir return RegexpMapConstIter< Val >(new RegexpMapIterImpl< Val >(m_pImpl, 497cdf0e10cSrcweir true)); 498cdf0e10cSrcweir} 499cdf0e10cSrcweir 500cdf0e10cSrcweir//============================================================================ 501cdf0e10cSrcweirtemplate< typename Val > 502cdf0e10cSrcweirtypename RegexpMap< Val >::iterator RegexpMap< Val >::end() 503cdf0e10cSrcweir{ 504cdf0e10cSrcweir return RegexpMapIter< Val >(new RegexpMapIterImpl< Val >(m_pImpl, false)); 505cdf0e10cSrcweir} 506cdf0e10cSrcweir 507cdf0e10cSrcweir//============================================================================ 508cdf0e10cSrcweirtemplate< typename Val > 509cdf0e10cSrcweirtypename RegexpMap< Val >::const_iterator RegexpMap< Val >::end() const 510cdf0e10cSrcweir{ 511cdf0e10cSrcweir return RegexpMapConstIter< Val >(new RegexpMapIterImpl< Val >(m_pImpl, 512cdf0e10cSrcweir false)); 513cdf0e10cSrcweir} 514cdf0e10cSrcweir 515cdf0e10cSrcweir//============================================================================ 516cdf0e10cSrcweirtemplate< typename Val > 517cdf0e10cSrcweirbool RegexpMap< Val >::empty() const 518cdf0e10cSrcweir{ 519cdf0e10cSrcweir return !m_pImpl->m_pDefault 520cdf0e10cSrcweir && m_pImpl->m_aList[Regexp::KIND_PREFIX].empty() 521cdf0e10cSrcweir && m_pImpl->m_aList[Regexp::KIND_AUTHORITY].empty() 522cdf0e10cSrcweir && m_pImpl->m_aList[Regexp::KIND_DOMAIN].empty(); 523cdf0e10cSrcweir} 524cdf0e10cSrcweir 525cdf0e10cSrcweir//============================================================================ 526cdf0e10cSrcweirtemplate< typename Val > 527cdf0e10cSrcweirtypename RegexpMap< Val >::size_type RegexpMap< Val >::size() const 528cdf0e10cSrcweir{ 529cdf0e10cSrcweir return (m_pImpl->m_pDefault ? 1 : 0) 530cdf0e10cSrcweir + m_pImpl->m_aList[Regexp::KIND_PREFIX].size() 531cdf0e10cSrcweir + m_pImpl->m_aList[Regexp::KIND_AUTHORITY].size() 532cdf0e10cSrcweir + m_pImpl->m_aList[Regexp::KIND_DOMAIN].size(); 533cdf0e10cSrcweir} 534cdf0e10cSrcweir 535cdf0e10cSrcweir//============================================================================ 536cdf0e10cSrcweirtemplate< typename Val > 537cdf0e10cSrcweirVal const * RegexpMap< Val >::map(rtl::OUString const & rString, 538cdf0e10cSrcweir rtl::OUString * pTranslation, 539cdf0e10cSrcweir bool * pTranslated) const 540cdf0e10cSrcweir{ 541cdf0e10cSrcweir for (int n = Regexp::KIND_DOMAIN; n >= Regexp::KIND_PREFIX; --n) 542cdf0e10cSrcweir { 543cdf0e10cSrcweir List< Val > const & rTheList = m_pImpl->m_aList[n]; 544cdf0e10cSrcweir 545cdf0e10cSrcweir typename List< Val >::const_iterator aEnd(rTheList.end()); 546cdf0e10cSrcweir for (typename List< Val >::const_iterator aIt(rTheList.begin()); aIt != aEnd; 547cdf0e10cSrcweir ++aIt) 548cdf0e10cSrcweir if (aIt->m_aRegexp.matches(rString, pTranslation, pTranslated)) 549cdf0e10cSrcweir return &aIt->m_aValue; 550cdf0e10cSrcweir } 551cdf0e10cSrcweir if (m_pImpl->m_pDefault 552cdf0e10cSrcweir && m_pImpl->m_pDefault->m_aRegexp.matches(rString, pTranslation, 553cdf0e10cSrcweir pTranslated)) 554cdf0e10cSrcweir return &m_pImpl->m_pDefault->m_aValue; 555cdf0e10cSrcweir return 0; 556cdf0e10cSrcweir} 557cdf0e10cSrcweir 558cdf0e10cSrcweir#endif // _UCB_REGEXPMAP_TPT_ 559