LibreOffice Module connectivity (master) 1
quotedstring.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20#include <file/quotedstring.hxx>
21#include <rtl/ustrbuf.hxx>
22
23namespace connectivity
24{
25
27 {
28 const sal_Int32 nLen = m_sString.getLength();
29 if ( !nLen )
30 return 0;
31
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?
35
36 // Search for String-end after the first not matching character
37 for( sal_Int32 i = 0; i < nLen; ++i )
38 {
39 const sal_Unicode cChar = m_sString[i];
40 if (bStart)
41 {
42 bStart = false;
43 // First character a String-Delimiter?
44 if ( cChar == cStrDel )
45 {
46 bInString = true; // then we are now WITHIN the string!
47 continue; // skip this character!
48 }
49 }
50
51 if (bInString)
52 {
53 // when now the String-Delimiter-character occurs...
54 if ( cChar == cStrDel )
55 {
56 if ((i+1 < nLen) && (m_sString[i+1] == cStrDel))
57 {
58 // double String-Delimiter-character:
59 ++i; // no string-end, skip next character.
60 }
61 else
62 {
63 // String-End
64 bInString = false;
65 }
66 }
67 } // if (bInString)
68 else
69 {
70 // does the Token-character match, then raise TokCount
71 if ( cChar == cTok )
72 {
73 ++nTokCount;
74 bStart = true;
75 }
76 }
77 }
78
79 return nTokCount;
80 }
81
82
83 OUString QuotedTokenizedString::GetTokenSpecial(sal_Int32& nStartPos, sal_Unicode cTok, sal_Unicode cStrDel) const
84 {
85 const sal_Int32 nLen = m_sString.getLength();
86 if ( nLen )
87 {
88 bool bInString = (nStartPos < nLen) && (m_sString[nStartPos] == cStrDel); // are we WITHIN a (cStrDel delimited) String?
89
90 // First character a String-Delimiter?
91 if (bInString )
92 ++nStartPos; // skip this character!
93 if ( nStartPos >= nLen )
94 return OUString();
95
96 OUStringBuffer sBuff( nLen - nStartPos + 1 );
97
98 // Search until end of string for the first not matching character
99 for( sal_Int32 i = nStartPos; i < nLen; ++i )
100 {
101 const sal_Unicode cChar = m_sString[i];
102 if (bInString)
103 {
104 // when now the String-Delimiter-character occurs ...
105 if ( cChar == cStrDel )
106 {
107 if ((i+1 < nLen) && (m_sString[i+1] == cStrDel))
108 {
109 // double String Delimiter-character
110 // no end of string, skip next character.
111 ++i;
112 sBuff.append(m_sString[i]); // character belongs to Result-String
113 }
114 else
115 {
116 //end of String
117 bInString = false;
118 }
119 }
120 else
121 {
122 sBuff.append(cChar);
123 }
124 }
125 else
126 {
127 // does the Token-sign match, then raise nTok
128 if ( cChar == cTok )
129 {
130 // premature break of loop possible, because we found what we were looking for
131 nStartPos = i+1;
132 break;
133 }
134 else
135 {
136 sBuff.append(cChar);
137 }
138 }
139 } // for( sal_Int32 i = nStartPos; i < nLen; ++i )
140 return sBuff.makeStringAndClear();
141 }
142 return OUString();
143 }
144}
145
146/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
OUString GetTokenSpecial(sal_Int32 &nStartPos, sal_Unicode cTok, sal_Unicode cStrDel='\0') const
sal_Int32 GetTokenCount(sal_Unicode cTok, sal_Unicode cStrDel) const
int i
sal_uInt16 sal_Unicode