home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / alt / sources / 2547 < prev    next >
Encoding:
Internet Message Format  |  1992-11-17  |  7.6 KB

  1. Path: sparky!uunet!ferkel.ucsb.edu!taco!rock!stanford.edu!agate!biosci!uwm.edu!spool.mu.edu!olivea!sgigate!odin!cody.esd.sgi.com!jegm
  2. From: jegm@cody.esd.sgi.com (Jim Morris)
  3. Newsgroups: alt.sources
  4. Subject: SPLASH c++ class library part 1 of 4
  5. Message-ID: <1992Nov18.030049.17227@odin.corp.sgi.com>
  6. Date: 18 Nov 92 03:00:49 GMT
  7. Sender: news@odin.corp.sgi.com (Net News)
  8. Organization: Silicon Graphics, Inc.
  9. Lines: 201
  10. Nntp-Posting-Host: cody.esd.sgi.com
  11.  
  12.  
  13. Archive-name: splashclass/part01
  14. Submitted-by: jegm@sgi.com
  15.  
  16. The SPLASH c++ class library
  17. ============================
  18.  
  19. (Small Perl-like List And String Handling class library)
  20.  
  21.  
  22. SPLASH is a c++ class library that implements my favourite Perl
  23. constructs.
  24.  
  25. For those not familiar with Perl, it is an excellent scripting language
  26. by Larry Wall and is available for most platforms.
  27.  
  28. This Class library provides List and String handling capabilities based
  29. on those provided in Perl, because the Perl constructs are so useful.
  30.  
  31. Overview
  32. -------- 
  33. In a nut-shell SPLASH provides a Dynamic List template class
  34. (SPList<T>) that allows you to add and extract data from the top of the
  35. list (push & pop), and from the bottom of the list (unshift & shift).
  36. ie a FIFO could be implemented by push'ing data onto the list and
  37. shift'ing data off the list.  The list can be sorted (uses operator< on
  38. the elements) and reversed.  (mylist.sort().reverse() will produce a
  39. list sorted in reverse order).  Another list can be inserted anywhere
  40. in a list, or elements deleted from within the list (splice).  And any
  41. individual element can be accessed using the '[]' operator.
  42.  
  43. The String class (SPString) implements a Dynamic string which provides
  44. an index() and rindex() function that finds the offset within the
  45. string of a sub-string. A substring may be extracted from the string,
  46. or assigned to within a string (expanding or shrinking the string as
  47. required). The string may be used anywhere a const char * can be used.
  48. The standard comparison functions (< > == etc) are available.  It
  49. allows string concatenation using the '+' and '+=' operator.  It
  50. provides regular expressions (with sub-expression extraction) that can
  51. be easily applied to the strings. A powerful substitute function and
  52. translation function (s() and tr()) are available.
  53.  
  54. The String List class (SPStringList) is basically a List class with
  55. some added functionality specific to lists of strings. It lets you grep
  56. for a regular expression within the list, returning a list of strings
  57. that match. It lets you generate a list of strings from a single string
  58. by splitting the string at a given regular expression (token parsing).
  59. It lets you generate a single string by concatenating a list of strings
  60. separated by a given string.
  61.  
  62. The Associative array class (Assoc<T>) lets you keep a list which is
  63. indexed by a string.
  64.  
  65. All the Classes have fully implemented streams operators for input and
  66. output, to allow convenient file or stream processing.
  67.  
  68. The Regexp class fully encapsulates the regular expression library, so
  69. you can easily use your own favourite one.
  70.  
  71. Usage Restrictions
  72. ------------------
  73.  
  74. There are none. This Code is not Copyright, use as you will.  The
  75. regexp code is Copyright by Henry Spencer, see the comments in regex.c
  76. for Copyright info.  The only changes I have made are to the header
  77. file, by adding a c++ prototype field.
  78.  
  79. Class description
  80. -----------------
  81. The Class Hierarchy and member functions are:-
  82.  
  83. class SPList<T>
  84.     T& operator[]    // index into list
  85.     void reset()    // clear out list
  86.     int scalar()    // returns number of elements in list
  87.     int count()        // ditto
  88.     T pop()        // returns and removes top of list
  89.     void push(T)    // enters element onto top of list
  90.     void push(SPList<T>) // enters a list of elements onto top of list
  91.     T shift()        // returns & removes element at bottom of list
  92.     int unshift(T)    // enters element into bottom of list
  93.     int unshift(SPList<T>) // enters lists into bottom of list
  94.     SPList<T> reverse()       // returns reverse order of list
  95.     SPList<T> splice(offset) // removes elements in list from 'offset'
  96.     SPList<T> splice(offset, len) // removes 'len' elements in list
  97.     SPList<T> splice(offset, len, SPList<T>)// replaces elements in list
  98.     SPList<T> sort() // sorts list according to result of '<' operator
  99.     ostream& operator>>() // input stream
  100.     istream& operator<<() // output stream
  101.  
  102.     class SPStringList // everything SPList does and ...
  103.         int split(str [,pat] [,limit]) // splits string on pattern
  104.     SPString join([pat])     // concatenates list with 'pat'
  105.     int m(exp, targ)      // makes list of sub exp matches
  106.     SPStringList grep(exp) // returns matches in list
  107.     ostream& operator>>()
  108.         istream& operator<<()
  109.  
  110. class SPString
  111.     int length()    // length of string
  112.     char chop()        // remove last character in string
  113.     int index(SPString [, offset]) // find string from start
  114.     int rindex(SPString [, offset]) // find string from end
  115.     SPString substr(offset [, len]) // substring works as lvalue as well
  116.     operator[]    // index character
  117.     operator<   // less than
  118.     operator>
  119.     operator<=
  120.     operator>=
  121.     operator==
  122.     operator!=
  123.     operator+        // concatenate 2 strings
  124.     operator+=        // as per c
  125.     int m(exp)         // return true if regexp matches string
  126.     int m(exp, SPStringList&) // ditto & generates a list of subexpressions
  127.     int tr(exp, rep [,opts]) // translate 'ex'p into 'rep'
  128.     int s(exp, rep [,opts]) // substitute 'exp' with 'rep'
  129.     ostream& operator>>()
  130.     istream& operator<<()
  131.  
  132. Associative array and helpers
  133. -----------------------------
  134.  
  135. class Binar<T>    // a key, value pair
  136.     T& value()
  137.     SPString& key()
  138.  
  139. class Assoc<T>    // an associateive array, loosely based on the perl one
  140.     T& operator(SPString) // equivalent to perl $assoc{"one"} = value
  141.     Binar& operator[n]      // returns n'th entry in associative array
  142.     SPStringList keys()   // returns a list of keys
  143.     SPList<T> values()    // returns a list of values
  144.     int isin(SPString)    // tests if key is in assoc array
  145.     T adelete(SPString)    // deletes given key/value
  146.  
  147. Other Classes
  148. -------------
  149.  
  150. VarString    - A variable length string class, used in SPString.
  151.  
  152. SPListBase<T>     - is the base class for SPList and handles the
  153.           auto expanding dynamic array, optimized for
  154.           prepending and appending data.
  155.  
  156. TempString     - makes a copy of a string, and can return a char *
  157.                and will free the storage when done. Something like
  158.           a cross between strsave() and alloca().
  159.  
  160. Regexp        - Handles the interface to the regular expression
  161.           library being used.
  162.  
  163. Range         - Simple class to maintain a range, just makes things
  164.           easier.
  165.  
  166. For More Info
  167. =============
  168.  
  169. See splash.readme for how to build and test, and various caveats.
  170. See splash.doc for documentation on each function.
  171. See sample/*.c++ for examples of how to use splash
  172. See regexp.doc for an explanation of the regexp library used
  173.  
  174. Distribution
  175. ------------
  176.  
  177. This is posted as a uuencoded, compressed tar file, I can supply
  178. it in .zoo or .zip format as well, with DOS compatible names.
  179. Email: jegm@sgi.com for a different format.
  180.  
  181. To use this posting cat part02 - part04 of the following postings in
  182. order into a file splash.uue, make sure only lines in between the:-
  183.  
  184. ------- Start Cut here --------
  185.  
  186. ------- End Cut here --------
  187.  
  188. are extracted.
  189.  
  190. Then:-
  191.  
  192. > uudecode splash.uue
  193. > uncompress splash.tar.Z
  194. > tar xvf splash.tar
  195.  
  196. The latest version of SPLASH is always available via anonymous
  197. FTP.
  198.  
  199. Also the current alpha version will also be available. This is for
  200. adventurous users only. It will be called splalphaxxx.tar.Z
  201.  
  202. Thanks to Michael Golan <mg@Princeton.EDU> for making the site
  203. available.
  204.  
  205. site:-
  206. samadams.princeton.edu
  207.  
  208. Path:-
  209. /u/ftp/pub/pec/splash.tar.Z
  210.  
  211. --
  212. Jim Morris, Email: jegm@esd.sgi.com  Voice: (415) 390-5136
  213.