1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 sal_Int32
QuotedTokenizedString::GetTokenCount( sal_Unicode cTok
, sal_Unicode cStrDel
) const
28 const sal_Int32 nLen
= m_sString
.getLength();
32 sal_Int32 nTokCount
= 1;
33 bool bStart
= true; // Are we on the first character in the Token?
34 bool bInString
= false; // Are we WITHIN a (cStrDel delimited) String?
36 // Search for String-end after the first not matching character
37 for( sal_Int32 i
= 0; i
< nLen
; ++i
)
39 const sal_Unicode cChar
= m_sString
[i
];
43 // First character a String-Delimiter?
44 if ( cChar
== cStrDel
)
46 bInString
= true; // then we are now WITHIN the string!
47 continue; // skip this character!
53 // when now the String-Delimiter-character occurs...
54 if ( cChar
== cStrDel
)
56 if ((i
+1 < nLen
) && (m_sString
[i
+1] == cStrDel
))
58 // double String-Delimiter-character:
59 ++i
; // no string-end, skip next character.
70 // does the Token-character match, then raise TokCount
78 //OSL_TRACE("QuotedTokenizedString::nTokCount = %d\n", ((OUtoCStr(OUString(nTokCount))) ? (OUtoCStr(OUString(nTokCount))):("NULL")) );
84 OUString
QuotedTokenizedString::GetTokenSpecial(sal_Int32
& nStartPos
, sal_Unicode cTok
, sal_Unicode cStrDel
) const
86 const sal_Int32 nLen
= m_sString
.getLength();
89 bool bInString
= (nStartPos
< nLen
) && (m_sString
[nStartPos
] == cStrDel
); // are we WITHIN a (cStrDel delimited) String?
91 // First character a String-Delimiter?
93 ++nStartPos
; // skip this character!
94 if ( nStartPos
>= nLen
)
97 OUStringBuffer
sBuff( nLen
- nStartPos
+ 1 );
99 // Search until end of string for the first not matching character
100 for( sal_Int32 i
= nStartPos
; i
< nLen
; ++i
)
102 const sal_Unicode cChar
= m_sString
[i
];
105 // when now the String-Delimiter-character occurs ...
106 if ( cChar
== cStrDel
)
108 if ((i
+1 < nLen
) && (m_sString
[i
+1] == cStrDel
))
110 // double String Delimiter-character
111 // no end of string, skip next character.
113 sBuff
.append(m_sString
[i
]); // character belongs to Result-String
128 // does the Token-sign match, then raise nTok
131 // premature break of loop possible, because we found what we were looking for
140 } // for( sal_Int32 i = nStartPos; i < nLen; ++i )
141 return sBuff
.makeStringAndClear();
147 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */