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();
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
);
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!
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.
77 bInString
= sal_False
;
83 // does the Token-character match, then raise TokCount
91 //OSL_TRACE("QuotedTokenizedString::nTokCount = %d\n", ((OUtoCStr(::rtl::OUString(nTokCount))) ? (OUtoCStr(::rtl::OUString(nTokCount))):("NULL")) );
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" );
101 const xub_StrLen nLen
= m_sString
.Len();
104 sal_Bool bInString
= (nStartPos
< nLen
) && (m_sString
.GetChar(nStartPos
) == cStrDel
); // are we WITHIN a (cStrDel delimited) String?
106 // First character a String-Delimiter?
108 ++nStartPos
; // skip this character!
109 if ( nStartPos
>= nLen
)
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
);
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.
128 *pData
++ = m_sString
.GetChar(i
); // character belongs to Result-String
133 bInString
= sal_False
;
139 *pData
++ = cChar
; // character belongs to Result-String
145 // does the Token-sign match, then raise nTok
148 // premature break of loop possible, because we found what we were looking for
154 *pData
++ = cChar
; // character belongs to Result-String
157 } // for( xub_StrLen i = nStartPos; i < nLen; ++i )
159 _rStr
.ReleaseBufferAccess(xub_StrLen(pData
- pStart
));
164 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */