update emoji autocorrect entries from po-files
[LibreOffice.git] / connectivity / source / drivers / file / quotedstring.cxx
blobc5fffb1f949eeeaf66e810a72cb2f0a175132452
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 sal_Int32 QuotedTokenizedString::GetTokenCount( sal_Unicode cTok, sal_Unicode cStrDel ) const
28 const sal_Int32 nLen = m_sString.getLength();
29 if ( !nLen )
30 return 0;
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];
40 if (bStart)
42 bStart = false;
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!
51 if (bInString)
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-Delimter-character:
59 ++i; // no string-end, skip next character.
61 else
63 // String-End
64 bInString = false;
67 } // if (bInString)
68 else
70 // does the Token-character match, then raise TokCount
71 if ( cChar == cTok )
73 ++nTokCount;
74 bStart = true;
78 //OSL_TRACE("QuotedTokenizedString::nTokCount = %d\n", ((OUtoCStr(OUString(nTokCount))) ? (OUtoCStr(OUString(nTokCount))):("NULL")) );
80 return nTokCount;
84 OUString QuotedTokenizedString::GetTokenSpecial(sal_Int32& nStartPos, sal_Unicode cTok, sal_Unicode cStrDel) const
86 const sal_Int32 nLen = m_sString.getLength();
87 if ( nLen )
89 bool bInString = (nStartPos < nLen) && (m_sString[nStartPos] == cStrDel); // are we WITHIN a (cStrDel delimited) String?
91 // First character a String-Delimiter?
92 if (bInString )
93 ++nStartPos; // skip this character!
94 if ( nStartPos >= nLen )
95 return OUString();
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];
103 if (bInString)
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.
112 ++i;
113 sBuff.append(m_sString[i]); // character belongs to Result-String
115 else
117 //end of String
118 bInString = false;
121 else
123 sBuff.append(cChar);
126 else
128 // does the Token-sign match, then raise nTok
129 if ( cChar == cTok )
131 // premature break of loop possible, because we found what we were looking for
132 nStartPos = i+1;
133 break;
135 else
137 sBuff.append(cChar);
140 } // for( sal_Int32 i = nStartPos; i < nLen; ++i )
141 return sBuff.makeStringAndClear();
143 return OUString();
147 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */