home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / cpp_libs / oath.lha / oath / src / string.cc < prev    next >
Encoding:
C/C++ Source or Header  |  1991-08-29  |  2.9 KB  |  112 lines

  1. //***************************************************************************
  2. //             OATH :: Object-oriented Abstract Type Hierarchy
  3. //***************************************************************************
  4. //
  5. //  Copyright (C) 1991, 1990  Texas Instruments Incorporated
  6. //  Permission is granted to any individual or institution
  7. //  to use, copy, modify, and distribute this software,
  8. //  provided that this complete copyright and permission notice
  9. //  is maintained, intact, in all copies and supporting documentation.
  10. //
  11. //  Texas Instruments Incorporated provides this software "as is"
  12. //  without express or implied warranty.
  13. //
  14. //***************************************************************************
  15. //  string (stringA, stringG)
  16. //  stringPos (stringPosA, stringPosG)
  17. //
  18. //  History:
  19. //    06/91  Brian M Kennedy  New macros & format; remove printDiagnostic
  20. //    10/90  Brian M Kennedy  Major Rewrite
  21. //    02/90  Brian M Kennedy  Original
  22. //
  23. //***************************************************************************
  24.  
  25. #include "copyright.h"
  26.  
  27. #include <oath/string.h>
  28.  
  29. #include <stdlib.h>
  30.  
  31. #include <math.h>    /* shouldn't be needed, but abs not in stdlib! */
  32.  
  33. /////////////////////////////////////////////////////////////////////////////
  34. // string Outlines
  35.  
  36. OUTLINES(string, list)
  37.  
  38.     int stringG::
  39. hash (const char * C)
  40.    {int H = 0;
  41.     while(*C)
  42.        {H = (H << 2) + *C;
  43.     C++;
  44.        }
  45.     return abs(H);
  46.    }
  47.  
  48.     int stringG::
  49. hash (const stringPosG* Start, const stringPosG* Beyond)
  50.    {int H = 0;
  51.     stringPosA P = (stringPosA&)Start->makeCopy(0);
  52.     while(P() && !P.guts()->isEqual(Beyond))
  53.        {H = (H << 2) + (*P).value();
  54.     ++P;
  55.        }
  56.     assumed(P.guts()->isEqual(Beyond),"First pos was not prior to second pos!");
  57.     return abs(H);
  58.    }
  59.  
  60.     int stringG::
  61. hashLower (const char * C)
  62.    {int H = 0;
  63.     while(*C)
  64.        {H = (H << 2) + tolower(*C);
  65.     C++;
  66.        }
  67.     return abs(H);
  68.    }
  69.  
  70.     int stringG::
  71. hashLower (const stringPosG* Start, const stringPosG* Beyond)
  72.    {int H = 0;
  73.     stringPosA P = (stringPosA&)Start->makeCopy(0);
  74.     while(P() && !P.guts()->isEqual(Beyond))
  75.        {H = (H << 2) + tolower((*P).value());
  76.     ++P;
  77.        }
  78.     assumed(P.guts()->isEqual(Beyond),"First pos was not prior to second pos!");
  79.     return abs(H);
  80.    }
  81.  
  82.     int stringG::
  83. hashUpper (const char * C)
  84.    {int H = 0;
  85.     while(*C)
  86.        {H = (H << 2) + toupper(*C);
  87.     C++;
  88.        }
  89.     return abs(H);
  90.    }
  91.  
  92.  
  93.     int stringG::
  94. hashUpper (const stringPosG* Start, const stringPosG* Beyond)
  95.    {int H = 0;
  96.     stringPosA P = (stringPosA&)Start->makeCopy(0);
  97.     while(P() && !P.guts()->isEqual(Beyond))
  98.        {H = (H << 2) + toupper((*P).value());
  99.     ++P;
  100.        }
  101.     assumed(P.guts()->isEqual(Beyond),"First pos was not prior to second pos!");
  102.     return abs(H);
  103.    }
  104.  
  105.  
  106. /////////////////////////////////////////////////////////////////////////////
  107. // stringPos Outlines
  108.  
  109. OUTLINES(stringPos, listPos)
  110.  
  111. //***************************************************************************
  112.