Bump for 3.6-28
[LibreOffice.git] / connectivity / source / drivers / file / quotedstring.cxx
blobe277bcf95e3bae7862a54123036dbcbe8cba7f2e
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
29 #include "file/quotedstring.hxx"
30 #include <rtl/logfile.hxx>
32 namespace connectivity
34 //==================================================================
35 //= QuotedTokenizedString
36 //==================================================================
37 //------------------------------------------------------------------
38 xub_StrLen QuotedTokenizedString::GetTokenCount( sal_Unicode cTok, sal_Unicode cStrDel ) const
40 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "QuotedTokenizedString::GetTokenCount" );
41 const xub_StrLen nLen = m_sString.Len();
42 if ( !nLen )
43 return 0;
45 xub_StrLen nTokCount = 1;
46 sal_Bool bStart = sal_True; // Are we on the first character in the Token?
47 sal_Bool bInString = sal_False; // Are we WITHIN a (cStrDel delimited) String?
49 // Search for String-end after the first not matching character
50 for( xub_StrLen i = 0; i < nLen; ++i )
52 const sal_Unicode cChar = m_sString.GetChar(i);
53 if (bStart)
55 bStart = sal_False;
56 // First character a String-Delimiter?
57 if ( cChar == cStrDel )
59 bInString = sal_True; // then we are now WITHIN the string!
60 continue; // skip this character!
64 if (bInString)
66 // when now the String-Delimiter-character occurs ...
67 if ( cChar == cStrDel )
69 if ((i+1 < nLen) && (m_sString.GetChar(i+1) == cStrDel))
71 // double String-Delimter-character:
72 ++i; // no string-end, skip next character.
74 else
76 // String-End
77 bInString = sal_False;
80 } // if (bInString)
81 else
83 // does the Token-character match, then raise TokCount
84 if ( cChar == cTok )
86 ++nTokCount;
87 bStart = sal_True;
91 //OSL_TRACE("QuotedTokenizedString::nTokCount = %d\n", ((OUtoCStr(::rtl::OUString(nTokCount))) ? (OUtoCStr(::rtl::OUString(nTokCount))):("NULL")) );
93 return nTokCount;
96 //------------------------------------------------------------------
97 void QuotedTokenizedString::GetTokenSpecial( String& _rStr,xub_StrLen& nStartPos, sal_Unicode cTok, sal_Unicode cStrDel ) const
99 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "QuotedTokenizedString::GetTokenCount" );
100 _rStr.Erase();
101 const xub_StrLen nLen = m_sString.Len();
102 if ( nLen )
104 sal_Bool bInString = (nStartPos < nLen) && (m_sString.GetChar(nStartPos) == cStrDel); // are we WITHIN a (cStrDel delimited) String?
106 // First character a String-Delimiter?
107 if (bInString )
108 ++nStartPos; // skip this character!
109 if ( nStartPos >= nLen )
110 return;
112 sal_Unicode* pData = _rStr.AllocBuffer( nLen - nStartPos + 1 );
113 const sal_Unicode* pStart = pData;
114 // Search until end of string for the first not matching character
115 for( xub_StrLen i = nStartPos; i < nLen; ++i )
117 const sal_Unicode cChar = m_sString.GetChar(i);
118 if (bInString)
120 // when now the String-Delimiter-character occurs ...
121 if ( cChar == cStrDel )
123 if ((i+1 < nLen) && (m_sString.GetChar(i+1) == cStrDel))
125 // double String Delimiter-character
126 // no end of string, skip next character.
127 ++i;
128 *pData++ = m_sString.GetChar(i); // character belongs to Result-String
130 else
132 //end of String
133 bInString = sal_False;
134 *pData = 0;
137 else
139 *pData++ = cChar; // character belongs to Result-String
143 else
145 // does the Token-sign match, then raise nTok
146 if ( cChar == cTok )
148 // premature break of loop possible, because we found what we were looking for
149 nStartPos = i+1;
150 break;
152 else
154 *pData++ = cChar; // character belongs to Result-String
157 } // for( xub_StrLen i = nStartPos; i < nLen; ++i )
158 *pData = 0;
159 _rStr.ReleaseBufferAccess(xub_StrLen(pData - pStart));
164 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */