#include "misc.h" PUBLIC SSTRING *SSTRINGS::getitem (int no) const { return (SSTRING *)ARRAY::getitem(no); } static int cmp (const ARRAY_OBJ *o1, const ARRAY_OBJ *o2) { SSTRING *s1 = (SSTRING *)o1; SSTRING *s2 = (SSTRING *)o2; return s1->cmp(*s2); } /* Sort the array of SSTRING */ PUBLIC void SSTRINGS::sort () { ARRAY::sort (cmp); } /* Find the occurence of a string in the array. Return -1 if not found or the index if found */ PUBLIC int SSTRINGS::lookup(const char *str) const { int ret = -1; int nb = getnb(); for (int i=0; icmp(str)==0){ ret = i; break; } } return ret; } PUBLIC int SSTRINGS::lookup(const SSTRING *str) const { return lookup (str->get()); } PUBLIC int SSTRINGS::lookup(const SSTRING &str) const { return lookup (str.get()); } /* Find the occurence of a string in the array, case insensitive. Return -1 if not found or the index if found */ PUBLIC int SSTRINGS::ilookup(const char *str) const { int ret = -1; int nb = getnb(); for (int i=0; iicmp(str)==0){ ret = i; break; } } return ret; } PUBLIC int SSTRINGS::ilookup(const SSTRING *str) const { return ilookup (str->get()); } PUBLIC int SSTRINGS::ilookup(const SSTRING &str) const { return ilookup (str.get()); } /* Remove empty line in a string table */ PUBLIC void SSTRINGS::remove_empty () { for (int i=0; iis_empty()){ remove_del(s); i--; } } } /* Remove duplicate strings Assume the array is already sorted. */ PUBLIC void SSTRINGS::remove_dups () { if (getnb() > 0){ const char *last = getitem(0)->get(); for (int i=1; icmp(last)==0){ remove_del(s); i--; }else{ last = s->get(); } } } } PUBLIC void SSTRINGS::append (const SSTRINGS &tb) { int nbtb = tb.getnb(); for (int i=0; iget())); } } PUBLIC SSTRINGS &SSTRINGS::operator = (const SSTRINGS &_strs) { remove_all(); for (int i=0; i<_strs.getnb(); i++){ add (new SSTRING(_strs.getitem(i)->get())); } return *this; } PUBLIC SSTRING *SSTRINGS::add (SSTRING *s) { ARRAY::add (s); return s; } PUBLIC SSTRING *SSTRINGS::add (const char *s) { SSTRING *ret = new SSTRING (s); ARRAY::add (ret); return ret; } PUBLIC SSTRING *SSTRINGS::add (const SSTRING &s) { SSTRING *ret = new SSTRING (s); ARRAY::add (ret); return ret; } PUBLIC SSTRING *SSTRINGS::add (const SSTRING *s) { SSTRING *ret = new SSTRING (s); ARRAY::add (ret); return ret; }