/* This file is part of dc_qt. dc_qt is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. dc_qt is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with dc_qt; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "dc_parse.h" #include #ifndef _QT_3 // section is not part of qt2 This is a _slow_ hack that works in qt2 // dc_qt compilied against qt2 a little while ago, but didn't run properly // I compile everything against qt3, so I don't care right now. Backporting // shouldn't be too difficult later for the rest. How different can the API // be? Famous last words... const QString section(const QString & str, char sep, int n) { QString result = ""; int start = 0; // find the nth occurence of the sep char, then move ahead // 1 in the string so that we skip the sep char for (int i = 0; i < n; i++) start = str.find(sep, start) + 1; for (int i = start; str[i] != sep && i < str.length(); i++) result += str[i]; return result; } #endif const QString dc_parse::get_str(int n) { #ifndef _QT_3 return section(str, sep, n); #else return str.section(sep, n, n); #endif } int dc_parse::num_strs() { return str.contains(sep) + 1; } void dc_parse::remove_quotes() { QString tmp = ""; int quotes = 0; for (int i = 0; i < str.length(); i++) { // don't copy until we've read two quotes if (quotes < 2 && str[i] == '\"') quotes++; else if(quotes < 2) ; else tmp += str[i]; tmp.stripWhiteSpace(); } str = tmp; }