/** * Yudit Unicode Editor Source File * * GNU Copyright (C) 1997-2006 Gaspar Sinai * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License, version 2, * dated June 1991. See file COPYYING for details. * * This program 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 this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ /** * @author: Gaspar Sinai * @version: 2000-04-23 */ #include "SStringVector.h" #include SStringVector::SStringVector (void) : SVector() { } SStringVector::SStringVector (const SStringVector& base) : SVector(base) { } /** * Do a split on base using delim. * empty elements are not put in the resulting vector */ SStringVector::SStringVector (const SString& base, const SString& delim, bool once) : SVector() { split(base, delim, once); } SStringVector::SStringVector (const SString& base) : SVector() { split(base, ","); } SStringVector::SStringVector (const char* base) : SVector() { split(base, ","); } SObject* SStringVector::clone() const { return new SStringVector (*this); } SStringVector::~SStringVector () { } /** * split a string into an array * @param s is the string to split * @param delim is the delimiter list * @param once is true if we quit after one spli * retgurn the number of splits */ unsigned int SStringVector::split (const SString& s, const SString& delim, bool once) { derefer (); char* excl = new char[256]; memset (excl, 0, 256); unsigned int dsize = delim.size(); for (unsigned int d=0; dfind (*peek(i)); if (found<0) continue; if (found < less || where ==-1) { less = found; where = i; } } if (where >= 0) { s->truncate (less); return where; } return -1; } SString SStringVector::join(const SString& delimiter) const { SString str; for (unsigned int i=0; i left) { pivot = (right+left)/2; mid= pivot; // Make a partition while (true) { // We compare everything to the pivot while (i= 0) i++; while (j>left && (compare (indeces, j, mid) * asc) < 0) j--; // Left index reached right index if (i>=j) break; // swap - it may swap the pivot as well. if (i==mid) mid=j; else if (j==mid) mid =i; // Swap unsigned int o = indeces[(unsigned int)i]; indeces[(unsigned int)i] = indeces[(unsigned int)j]; indeces[(unsigned int)j] = o; } // Make sure we don't sort the pivot - originally it is // in the left array so we exchange it with something // that belongs to left and lies in the boundary. // It might be the pivot itself... unsigned int o = indeces[(unsigned int)mid]; indeces[(unsigned int)mid] = indeces[(unsigned int)j]; indeces[(unsigned int)j] = o; sort (indeces, ascending, left, j-1); sort (indeces, ascending, i, right); } } /** * compare addresed trhough indeces. */ int SStringVector::compare (unsigned int* indeces, int i1, int i2) { const SString& js = *peek (indeces[(unsigned int) i1]); const SString& ms = *peek (indeces[(unsigned int) i2]); return js.compare(ms); } void SStringVector::append (const SStringVector& v) { unsigned int sz = v.size(); for (unsigned int i=0; i::append (str); } void SStringVector::append (const char* str) { SVector::append (SString(str)); }