Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/gsdl/src/library/gdbmclass.cpp

    r4 r22  
    574574  return 1;
    575575}
     576
     577// functions related to sorting
     578
     579// returns whatever comes after ':#:' in str
     580// -- this is a nasty hack that I'm sure Rodger will want to change ;-)
     581text_t get_section_str(const text_t &str) {
     582
     583  text_t ret;
     584  int found = 0;
     585
     586  text_t::const_iterator here = str.begin();
     587  text_t::const_iterator end = str.end();
     588
     589  while (here != end) {
     590    if (found) {
     591      ret.push_back(*here);
     592    } else {
     593      here = findchar (here, end, ':');
     594      if ((*(here+1) == '#') && (*(here+2) == ':')) {
     595    found = 1;
     596    here = here+2;
     597      }
     598    }
     599    here ++;
     600  }
     601  return ret;
     602}
     603
     604// removes leading spaces and leading 'the' 'a' and 'an'
     605// from string
     606void alphabetize_string_english (text_t &text) {
     607 
     608  if (text.empty()) return;
     609
     610  text_t firstword;
     611  char *word;
     612
     613  text_t::iterator here = text.begin();
     614  text_t::const_iterator end = text.end();
     615
     616  if ((*here != ' ') && (*here != 'a') && (*here != 'A') &&
     617      (*here != 't') && (*here != 'T')) return;
     618
     619  int foundchar = 0;
     620  while (here != end) {
     621    if (*here == ' ' && !foundchar) {here ++; continue;}
     622    if (*here == ' ' && foundchar) {
     623      text.erase(text.begin(), (here+1));
     624      break;
     625    }
     626    foundchar ++;
     627    if (foundchar == 1) {
     628      getdelimitstr (here, end, ' ', firstword);
     629      word = firstword.getcstr();
     630      if ((_stricmp(word, "the") != 0) && (_stricmp(word, "a") != 0) &&
     631      (_stricmp(word, "an") != 0)) break;
     632    }
     633    here ++;
     634  }
     635  delete word;
     636}
     637
     638// removes leading space, puts last name before
     639// any preceeding names
     640void alphabetize_string_name (text_t &text) {
     641 
     642  if (text.empty()) return;
     643 
     644  text_t lastname;
     645  char *lname;
     646  vector<text_t> words;
     647  splitchar (text.begin(), text.end(), ' ', words);
     648  lastname = words.back();
     649  words.pop_back();
     650  lname = lastname.getcstr();
     651 
     652  while ((_stricmp(lname, "jnr") == 0) || (_stricmp(lname, "snr") == 0) ||
     653     (_stricmp(lname, "esq") == 0)) {
     654    lastname = words.back();
     655    words.pop_back();
     656    lname = lastname.getcstr();
     657  }
     658
     659  text.clear();
     660  joinchar (words, ' ', text);
     661  text = lastname + text;
     662}
     663
     664char ** string_add (char **array, int *len, char *str) {
     665  char **ret;
     666
     667  ret = (char**)realloc(array, (*len+1)*sizeof(char*));
     668  ret[*len] = (char*)strdup(str);
     669  (*len) ++;
     670
     671  return ret;
     672}
     673
     674void string_sort (char **array, int len) {
     675  qsort((void*)array, (unsigned int)(len), sizeof(char*), compare_str);
     676}
     677
     678static int compare_str (const void *e1, const void *e2) {
     679  return _stricmp(*((char**)e1), *((char**)e2));
     680}
     681
     682void string_free(char **array, int len) {
     683  for (int i = 0; i < len; i++)
     684    free (array[i]);
     685  free (array);
     686}
Note: See TracChangeset for help on using the changeset viewer.