home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 5 Edit / 05-Edit.zip / fed0217s.zip / source / dict.cpp < prev    next >
C/C++ Source or Header  |  2000-12-13  |  1KB  |  72 lines

  1. /*
  2. ** Module   :DICT.CPP
  3. ** Abstract :
  4. **
  5. ** Copyright (C) Sergey I. Yevtushenko
  6. **
  7. ** Log: Thu  09/04/1998 Created
  8. **
  9. */
  10.  
  11. #include <malloc.h>
  12. #include <string.h>
  13.  
  14. #include <dict.h>
  15. #include <_ctype.h>
  16. #include <version.h>
  17.  
  18. Dictionary::Dictionary(int Case, PPair pList, int size):SortedCollection()
  19. {
  20.     bCase = Case;
  21.     bDuplicates = 0;
  22.  
  23.     for(int i = 0; i < size; i++)
  24.         Add(&pList[i]);
  25. }
  26.  
  27. Dictionary::~Dictionary()
  28. {
  29.     RemoveAll();
  30. }
  31.  
  32. void Dictionary::Free(Ptr)
  33. {
  34. }
  35.  
  36. int Dictionary::Compare(Ptr p1, Ptr p2)
  37. {
  38.     return (bCase) ? strcmp(PPair(p1)->key, PPair(p2)->key) :
  39.                   __cstrcmp(PPair(p1)->key, PPair(p2)->key);
  40. }
  41.  
  42. PPair Dictionary::IsIn(char *key, int Case)
  43. {
  44.     Pair p;
  45.     p.key = key;
  46.  
  47.     int save_case = bCase;
  48.     bCase = Case;
  49.  
  50.     unsigned long index = Look(&p);
  51.  
  52.     if(index < Count() && !Compare(&p, Get(index)))
  53.     {
  54.         bCase = save_case;
  55.         return PPair(Get(index));
  56.     }
  57.     bCase = save_case;
  58.     return 0;
  59. }
  60.  
  61. PPair Dictionary::IsIn(char *key, int len, int Case)
  62. {
  63.     char *buf;
  64.  
  65.     buf = (char*) alloca(len+1);
  66.  
  67.     memcpy(buf, key, len);
  68.     buf[len] = 0;
  69.     return IsIn(buf, Case);
  70. }
  71.  
  72.