Update ooo320-m1
[ooovba.git] / connectivity / source / drivers / evoab / LNoException.cxx
blobb1cd94cd8697823be73654246e0cc21a526fcce9
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: LNoException.cxx,v $
10 * $Revision: 1.6 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_connectivity.hxx"
33 #include "LTable.hxx"
34 #include "LConnection.hxx"
36 using namespace connectivity;
37 using namespace connectivity::evoab;
39 //------------------------------------------------------------------
40 xub_StrLen OEvoabString::GetTokenCount( sal_Unicode cTok, sal_Unicode cStrDel ) const
42 if ( !Len() )
43 return 0;
45 xub_StrLen nTokCount = 1;
46 BOOL bStart = TRUE; // Stehen wir auf dem ersten Zeichen im Token?
47 BOOL bInString = FALSE; // Befinden wir uns INNERHALB eines (cStrDel delimited) String?
49 // Suche bis Stringende nach dem ersten nicht uebereinstimmenden Zeichen
50 for( xub_StrLen i = 0; i < Len(); i++ )
52 if (bStart)
54 bStart = FALSE;
55 // Erstes Zeichen ein String-Delimiter?
56 if ((*this).GetChar(i) == cStrDel)
58 bInString = TRUE; // dann sind wir jetzt INNERHALB des Strings!
59 continue; // dieses Zeichen ueberlesen!
63 if (bInString) {
64 // Wenn jetzt das String-Delimiter-Zeichen auftritt ...
65 if ( (*this).GetChar(i) == cStrDel )
67 if ((i+1 < Len()) && ((*this).GetChar(i+1) == cStrDel))
69 // Verdoppeltes String-Delimiter-Zeichen:
70 i++; // kein String-Ende, naechstes Zeichen ueberlesen.
72 else
74 // String-Ende
75 bInString = FALSE;
78 } else {
79 // Stimmt das Tokenzeichen ueberein, dann erhoehe TokCount
80 if ( (*this).GetChar(i) == cTok )
82 nTokCount++;
83 bStart = TRUE;
87 //OSL_TRACE("OEvoabString::nTokCount = %d\n", ((OUtoCStr(::rtl::OUString(nTokCount))) ? (OUtoCStr(::rtl::OUString(nTokCount))):("NULL")) );
89 return nTokCount;
92 //------------------------------------------------------------------
93 void OEvoabString::GetTokenSpecial( String& _rStr,xub_StrLen& nStartPos, sal_Unicode cTok, sal_Unicode cStrDel ) const
95 _rStr.Erase();
96 xub_StrLen nLen = Len();
97 if ( nLen )
99 BOOL bInString = (nStartPos < nLen) && ((*this).GetChar(nStartPos) == cStrDel); // Befinden wir uns INNERHALB eines (cStrDel delimited) String?
101 // Erstes Zeichen ein String-Delimiter?
102 if (bInString )
103 ++nStartPos; // dieses Zeichen ueberlesen!
104 // Suche bis Stringende nach dem ersten nicht uebereinstimmenden Zeichen
105 for( xub_StrLen i = nStartPos; i < nLen; ++i )
107 if (bInString)
109 // Wenn jetzt das String-Delimiter-Zeichen auftritt ...
110 if ( (*this).GetChar(i) == cStrDel )
112 if ((i+1 < nLen) && ((*this).GetChar(i+1) == cStrDel))
114 // Verdoppeltes String-Delimiter-Zeichen:
115 ++i; // kein String-Ende, naechstes Zeichen ueberlesen.
117 _rStr += (*this).GetChar(i); // Zeichen gehoert zum Resultat-String
119 else
121 // String-Ende
122 bInString = FALSE;
125 else
127 _rStr += (*this).GetChar(i); // Zeichen gehoert zum Resultat-String
131 else
133 // Stimmt das Tokenzeichen ueberein, dann erhoehe nTok
134 if ( (*this).GetChar(i) == cTok )
136 // Vorzeitiger Abbruch der Schleife moeglich, denn
137 // wir haben, was wir wollten.
138 nStartPos = i+1;
139 break;
141 else
143 _rStr += (*this).GetChar(i); // Zeichen gehoert zum Resultat-String
149 // -----------------------------------------------------------------------------
150 void OEvoabTable::refreshIndexes()
153 // -----------------------------------------------------------------------------
154 sal_Bool OEvoabTable::checkHeaderLine()
156 if (m_nFilePos == 0 && ((OEvoabConnection*)m_pConnection)->isHeaderLine())
158 BOOL bRead2;
161 bRead2 = m_pFileStream->ReadByteStringLine(m_aCurrentLine,m_pConnection->getTextEncoding());
163 while(bRead2 && !m_aCurrentLine.Len());
165 m_nFilePos = m_pFileStream->Tell();
166 if (m_pFileStream->IsEof())
167 return sal_False;
169 return sal_True;
171 //------------------------------------------------------------------
172 sal_Bool OEvoabTable::seekRow(IResultSetHelper::Movement eCursorPosition, sal_Int32 nOffset, sal_Int32& nCurPos)
174 //OSL_TRACE("OEvoabTable::(before SeekRow)m_aCurrentLine = %d\n", ((OUtoCStr(::rtl::OUString(m_aCurrentLine))) ? (OUtoCStr(::rtl::OUString(m_aCurrentLine))):("NULL")) );
176 if ( !m_pFileStream )
177 return sal_False;
178 OEvoabConnection* pConnection = (OEvoabConnection*)m_pConnection;
179 // ----------------------------------------------------------
180 // Positionierung vorbereiten:
181 //OSL_TRACE("OEvoabTable::(before SeekRow,m_pFileStriam Exist)m_aCurrentLine = %d\n", ((OUtoCStr(::rtl::OUString(m_aCurrentLine))) ? (OUtoCStr(::rtl::OUString(m_aCurrentLine))):("NULL")) );
183 m_nFilePos = nCurPos;
185 switch(eCursorPosition)
187 case IResultSetHelper::FIRST:
188 m_nFilePos = 0;
189 m_nRowPos = 1;
190 // run through
191 case IResultSetHelper::NEXT:
192 if(eCursorPosition != IResultSetHelper::FIRST)
193 ++m_nRowPos;
194 m_pFileStream->Seek(m_nFilePos);
195 if (m_pFileStream->IsEof() || !checkHeaderLine())
197 m_nMaxRowCount = m_nRowPos;
198 return sal_False;
201 m_aRowToFilePos.insert(::std::map<sal_Int32,sal_Int32>::value_type(m_nRowPos,m_nFilePos));
203 m_pFileStream->ReadByteStringLine(m_aCurrentLine,pConnection->getTextEncoding());
204 if (m_pFileStream->IsEof())
206 m_nMaxRowCount = m_nRowPos;
207 return sal_False;
209 nCurPos = m_pFileStream->Tell();
210 break;
211 case IResultSetHelper::PRIOR:
212 --m_nRowPos;
213 if(m_nRowPos > 0)
215 m_nFilePos = m_aRowToFilePos.find(m_nRowPos)->second;
216 m_pFileStream->Seek(m_nFilePos);
217 if (m_pFileStream->IsEof() || !checkHeaderLine())
218 return sal_False;
219 m_pFileStream->ReadByteStringLine(m_aCurrentLine,pConnection->getTextEncoding());
220 if (m_pFileStream->IsEof())
221 return sal_False;
222 nCurPos = m_pFileStream->Tell();
224 else
225 m_nRowPos = 0;
227 break;
229 break;
230 case IResultSetHelper::LAST:
231 if(m_nMaxRowCount)
233 m_nFilePos = m_aRowToFilePos.rbegin()->second;
234 m_nRowPos = m_aRowToFilePos.rbegin()->first;
235 m_pFileStream->Seek(m_nFilePos);
236 if (m_pFileStream->IsEof() || !checkHeaderLine())
237 return sal_False;
238 m_pFileStream->ReadByteStringLine(m_aCurrentLine,pConnection->getTextEncoding());
239 if (m_pFileStream->IsEof())
240 return sal_False;
241 nCurPos = m_pFileStream->Tell();
243 else
245 while(seekRow(IResultSetHelper::NEXT,1,nCurPos)) ; // run through after last row
246 // now I know all
247 seekRow(IResultSetHelper::PRIOR,1,nCurPos);
249 break;
250 case IResultSetHelper::RELATIVE:
251 if(nOffset > 0)
253 for(sal_Int32 i = 0;i<nOffset;++i)
254 seekRow(IResultSetHelper::NEXT,1,nCurPos);
256 else if(nOffset < 0)
258 for(sal_Int32 i = nOffset;i;++i)
259 seekRow(IResultSetHelper::PRIOR,1,nCurPos);
261 break;
262 case IResultSetHelper::ABSOLUTE:
264 if(nOffset < 0)
265 nOffset = m_nRowPos + nOffset;
266 ::std::map<sal_Int32,sal_Int32>::const_iterator aIter = m_aRowToFilePos.find(nOffset);
267 if(aIter != m_aRowToFilePos.end())
269 m_nFilePos = aIter->second;
270 m_pFileStream->Seek(m_nFilePos);
271 if (m_pFileStream->IsEof() || !checkHeaderLine())
272 return sal_False;
273 m_pFileStream->ReadByteStringLine(m_aCurrentLine,pConnection->getTextEncoding());
274 if (m_pFileStream->IsEof())
275 return sal_False;
276 nCurPos = m_pFileStream->Tell();
278 else if(m_nMaxRowCount && nOffset > m_nMaxRowCount) // offset is outside the table
280 m_nRowPos = m_nMaxRowCount;
281 return sal_False;
283 else
285 aIter = m_aRowToFilePos.upper_bound(nOffset);
286 if(aIter == m_aRowToFilePos.end())
288 m_nRowPos = m_aRowToFilePos.rbegin()->first;
289 nCurPos = m_nFilePos = m_aRowToFilePos.rbegin()->second;
290 while(m_nRowPos != nOffset)
291 seekRow(IResultSetHelper::NEXT,1,nCurPos);
293 else
295 --aIter;
296 m_nRowPos = aIter->first;
297 m_nFilePos = aIter->second;
298 m_pFileStream->Seek(m_nFilePos);
299 if (m_pFileStream->IsEof() || !checkHeaderLine())
300 return sal_False;
301 m_pFileStream->ReadByteStringLine(m_aCurrentLine,pConnection->getTextEncoding());
302 if (m_pFileStream->IsEof())
303 return sal_False;
304 nCurPos = m_pFileStream->Tell();
309 break;
310 case IResultSetHelper::BOOKMARK:
311 m_pFileStream->Seek(nOffset);
312 if (m_pFileStream->IsEof())
313 return sal_False;
315 m_nFilePos = m_pFileStream->Tell(); // Byte-Position in der Datei merken (am ZeilenANFANG)
316 m_pFileStream->ReadByteStringLine(m_aCurrentLine,pConnection->getTextEncoding());
317 if (m_pFileStream->IsEof())
318 return sal_False;
319 nCurPos = m_pFileStream->Tell();
320 break;
323 //OSL_TRACE("OEvoabTable::(after SeekRow)m_aCurrentLine = %d\n", ((OUtoCStr(::rtl::OUString(m_aCurrentLine))) ? (OUtoCStr(::rtl::OUString(m_aCurrentLine))):("NULL")) );
325 return sal_True;
327 // -----------------------------------------------------------------------------