Changeset 1125


Ignore:
Timestamp:
2000-04-18T16:06:12+12:00 (24 years ago)
Author:
kjm18
Message:

added GetCStr and BrowseCompare

Location:
trunk/gsdl/src/mgpp/text
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/gsdl/src/mgpp/text/UCArray.cpp

    r855 r1125  
    3535}
    3636
     37char * GetCStr(UCArray text) {
     38
     39  char *cstr = new char[text.size()+1];
     40  UCArray::const_iterator here = text.begin();
     41  UCArray::const_iterator end = text.end();
     42
     43  int i = 0;
     44  while (here != end) {
     45    cstr[i] = (char)*here;
     46    here++; i++;
     47  }
     48  cstr[i]='\0';
     49  return cstr;
     50}
    3751
    3852ostream &operator<<(ostream &s, const UCArray &a) {
     
    214228}
    215229
     230/* comparison for browse index - items match if the smaller word
     231   is a prefix of the larger word, case independent
     232*/
     233int BrowseCompare (const UCArray &a1, const UCArray &a2) {
     234  unsigned int l1 = a1.size();
     235  unsigned int l2 = a2.size();
     236  unsigned int l = (l1 < l2) ? l1 : l2; // l is the shorter of the two
     237  int diff = 0;
     238
     239  UCArray::const_iterator a1Here = a1.begin();
     240  UCArray::const_iterator a2Here = a2.begin();
     241
     242  while(l--) {
     243    if ((diff = casecharmap[*a1Here] - casecharmap[*a2Here]) !=0)
     244      return diff;
     245    a1Here++;
     246    a2Here++;
     247  }
     248  return 0;
     249
     250}
    216251
    217252unsigned long PrefixLen (const UCArray &a1, const UCArray &a2) {
  • trunk/gsdl/src/mgpp/text/UCArray.h

    r855 r1125  
    5151// functions to manipulate UCArrays
    5252void SetCStr (UCArray &text, const char *cStr);
     53char * GetCStr(UCArray text);
    5354inline void UCArrayClear (UCArray &a) {
    5455  a.erase (a.begin(), a.end());
     
    8990// compares the two strings in dictionary order
    9091int DictCompare (const UCArray &a1, const UCArray &a2);
    91 
     92// compares the two strings, case independent, a match (ie 0) is
     93// if one string is a prefix of the other
     94int BrowseCompare (const UCArray &a1, const UCArray &a2);
    9295
    9396struct LTUCArray {
     
    113116
    114117#endif
     118
     119
     120
     121
     122
Note: See TracChangeset for help on using the changeset viewer.