Version 4.3.0.0.beta1, tag libreoffice-4.3.0.0.beta1
[LibreOffice.git] / connectivity / source / drivers / file / quotedstring.cxx
blob0ff6335f880e54f4b1d7f7dae372e0ccbad51843
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include "file/quotedstring.hxx"
21 #include <rtl/ustrbuf.hxx>
23 namespace connectivity
26 //= QuotedTokenizedString
29 sal_Int32 QuotedTokenizedString::GetTokenCount( sal_Unicode cTok, sal_Unicode cStrDel ) const
31 const sal_Int32 nLen = m_sString.getLength();
32 if ( !nLen )
33 return 0;
35 sal_Int32 nTokCount = 1;
36 bool bStart = true; // Are we on the first character in the Token?
37 bool bInString = false; // Are we WITHIN a (cStrDel delimited) String?
39 // Search for String-end after the first not matching character
40 for( sal_Int32 i = 0; i < nLen; ++i )
42 const sal_Unicode cChar = m_sString[i];
43 if (bStart)
45 bStart = false;
46 // First character a String-Delimiter?
47 if ( cChar == cStrDel )
49 bInString = true; // then we are now WITHIN the string!
50 continue; // skip this character!
54 if (bInString)
56 // when now the String-Delimiter-character occurs ...
57 if ( cChar == cStrDel )
59 if ((i+1 < nLen) && (m_sString[i+1] == cStrDel))
61 // double String-Delimter-character:
62 ++i; // no string-end, skip next character.
64 else
66 // String-End
67 bInString = false;
70 } // if (bInString)
71 else
73 // does the Token-character match, then raise TokCount
74 if ( cChar == cTok )
76 ++nTokCount;
77 bStart = true;
81 //OSL_TRACE("QuotedTokenizedString::nTokCount = %d\n", ((OUtoCStr(OUString(nTokCount))) ? (OUtoCStr(OUString(nTokCount))):("NULL")) );
83 return nTokCount;
87 OUString QuotedTokenizedString::GetTokenSpecial(sal_Int32& nStartPos, sal_Unicode cTok, sal_Unicode cStrDel) const
89 const sal_Int32 nLen = m_sString.getLength();
90 if ( nLen )
92 bool bInString = (nStartPos < nLen) && (m_sString[nStartPos] == cStrDel); // are we WITHIN a (cStrDel delimited) String?
94 // First character a String-Delimiter?
95 if (bInString )
96 ++nStartPos; // skip this character!
97 if ( nStartPos >= nLen )
98 return OUString();
100 OUStringBuffer sBuff( nLen - nStartPos + 1 );
102 // Search until end of string for the first not matching character
103 for( sal_Int32 i = nStartPos; i < nLen; ++i )
105 const sal_Unicode cChar = m_sString[i];
106 if (bInString)
108 // when now the String-Delimiter-character occurs ...
109 if ( cChar == cStrDel )
111 if ((i+1 < nLen) && (m_sString[i+1] == cStrDel))
113 // double String Delimiter-character
114 // no end of string, skip next character.
115 ++i;
116 sBuff.append(m_sString[i]); // character belongs to Result-String
118 else
120 //end of String
121 bInString = false;
124 else
126 sBuff.append(cChar);
129 else
131 // does the Token-sign match, then raise nTok
132 if ( cChar == cTok )
134 // premature break of loop possible, because we found what we were looking for
135 nStartPos = i+1;
136 break;
138 else
140 sBuff.append(cChar);
143 } // for( sal_Int32 i = nStartPos; i < nLen; ++i )
144 return sBuff.makeStringAndClear();
146 return OUString();
150 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */