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 //= QuotedTokenizedString
29 sal_Int32
QuotedTokenizedString::GetTokenCount( sal_Unicode cTok
, sal_Unicode cStrDel
) const
31 const sal_Int32 nLen
= m_sString
.getLength();
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
];
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!
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.
73 // does the Token-character match, then raise TokCount
81 //OSL_TRACE("QuotedTokenizedString::nTokCount = %d\n", ((OUtoCStr(OUString(nTokCount))) ? (OUtoCStr(OUString(nTokCount))):("NULL")) );
87 OUString
QuotedTokenizedString::GetTokenSpecial(sal_Int32
& nStartPos
, sal_Unicode cTok
, sal_Unicode cStrDel
) const
89 const sal_Int32 nLen
= m_sString
.getLength();
92 bool bInString
= (nStartPos
< nLen
) && (m_sString
[nStartPos
] == cStrDel
); // are we WITHIN a (cStrDel delimited) String?
94 // First character a String-Delimiter?
96 ++nStartPos
; // skip this character!
97 if ( nStartPos
>= nLen
)
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
];
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.
116 sBuff
.append(m_sString
[i
]); // character belongs to Result-String
131 // does the Token-sign match, then raise nTok
134 // premature break of loop possible, because we found what we were looking for
143 } // for( sal_Int32 i = nStartPos; i < nLen; ++i )
144 return sBuff
.makeStringAndClear();
150 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */