home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / listings / v_11_11 / splash / splash.doc < prev    next >
Text File  |  1993-01-15  |  13KB  |  379 lines

  1. class SPList<T>    - A list of any type specified by T
  2.  
  3.     T& operator[n]    - returns a reference to the element at index
  4.               'n' (0 based). Generates an ASSERT error
  5.               if n < 0, can be used as an lvalue. Using
  6.               an index greater than the current size of the
  7.               list will cause the list to grow upto that
  8.               index. The values inbetween will be undefined
  9.               if <T> is a built-in type.
  10.  
  11.     operator void*()    - returns NULL if the list is empty,
  12.               can be used like: if(list) // not empty
  13.  
  14.     int isempty()    - returns TRUE if the list is empty, as an
  15.               alternative for the previous technique
  16.  
  17.     void reset()    - clears all elements in the list, but doesn't
  18.               actually free up the storage until it is
  19.               destroyed
  20.  
  21.     int count()        - returns the number of elements in the list
  22.     int scalar()    - Perl-like Synonym (alias) for count()
  23.  
  24.     T pop()        - removes and returns the last element on the
  25.               list. If the list is empty the value returned
  26.               is usually undefined
  27.  
  28.     void push(T x)    - puts the single value 'x' at the end of the
  29.               list
  30.  
  31.  
  32.     void push(SPList<T> l)
  33.              - puts all the elements in the list 'l' at the
  34.               end of the list.
  35.  
  36.     T shift()        - removes and returns the first element
  37.               in the list
  38.  
  39.     int unshift(T x)    - puts the single value 'x' at the start
  40.               of the list
  41.  
  42.     int unshift(SPList<T> l)
  43.             - puts all the elements in the list 'l'
  44.               at the start of the list
  45.  
  46.     SPList<T> reverse()
  47.             - returns a list that is in the reverse
  48.               order
  49.  
  50.     SPList<T> splice(offset, len, SPList<T> l)
  51.             - removes 'len' elements from 'offset' (0 based)
  52.               and inserts all the elements in the list 'l'
  53.               at the same position
  54.                 
  55.     SPList<T> splice(offset, len)
  56.             - removes 'len' elements from 'offset' (0 based)
  57.  
  58.     SPList<T> splice(offset)
  59.             - removes all the elements from 'offset'
  60.               (0 based)
  61.  
  62.     SPList<T> sort()    - returns a list that has been sorted according
  63.               to the rules that T::operator<() returns
  64.               for the type T.
  65.  
  66.     SubList<T> operator(offset, len)
  67.             - Returns the SubList from 'offset' for 'len'
  68.               elements. Maybe assigned to a SPList or used
  69.               wherever an SPList may be used. Can also be
  70.               assigned to, in which case the specified
  71.               elements are replaced with the RHS
  72.  
  73.     SubList<T> operator(Range rng)
  74.             - Same as above, but returns the range
  75.               specified by 'rng'
  76.  
  77.     SubList<T> operator(Slice slc)
  78.             - Same as above, but returns the slice
  79.               specified by 'slc'. A slice can be a
  80.               non-contiguous set of Ranges. See Slice
  81.               below.
  82.  
  83.     SubList<T> operator(char *s)
  84.             - Same as above, but returns the slice
  85.               specified by 's' where 's' is a string that
  86.               specifies a set of indices.
  87.               's' can be:-
  88.                 "a..b" or "a-b" which specifies a
  89.                  continuous range from a thru' b.
  90.                 "a,b,c" which specifies individual indices
  91.                  a, b and c.
  92.                 "a..b,c,d" which specifies a range and 2
  93.                  individual indices.
  94.  
  95. class SPStringList    - everything SPList does and ...
  96.  
  97.     int split(str [,pat] [,limit])
  98.             - appends the results of splitting the string
  99.               'str' to the list. If 'pat' is specified then
  100.               any string that matches the RE 'pat' is
  101.               considered a separator to split on, the
  102.               default is white-space. If 'limit' is specified
  103.               then no more than that number of elements is
  104.               generated. If 'limit' is not specified, then empty
  105.               entries are stripped from the end of the list.
  106.               If the RE includes subexpressions then they
  107.               are inserted into the list as well.
  108.               If 'pat' is equal to the string "' '" then
  109.               a special case is done which matches awks
  110.               handling of whitespace. If 'pat' is an empty
  111.               string "", then all characters are split into
  112.               the list
  113.  
  114.     SPString join([pat])
  115.             - Returns the string that is the result of
  116.               combining all the elements in the list, and
  117.               separating them by 'pat'. If 'pat' is omitted
  118.               then the elements are separated by a space
  119.  
  120.     int m(const char *exp, targ [,opts)
  121.             - Appends to the list all the subexpression
  122.               matches that occured when applying the regular
  123.               expression 'exp' to the string 'targ'.
  124.               The number of matches is returned. The first
  125.               element generated is the entire matched string
  126.               opts: (a const char * with default "")
  127.                   i - Forces case insensitive match
  128.     
  129.     SPStringList grep(const char *exp [,opts])
  130.             - returns a list of all the elements that
  131.               matched the regular expression 'exp'.
  132.               opts: (a const char * with default "")
  133.                   i - Forces the search to be case insensitive
  134.  
  135. class SPString        - A standard c null-terminated string may be
  136.               used anywhere that a SPString can be used
  137.               and vice-versa.
  138.             - Individual characters may be read with
  139.               the '[]' operator.
  140.  
  141.     int length()    - returns the length of the string
  142.  
  143.     char chop()        - removes and returns the last character in the
  144.               string
  145.  
  146.     int index(SPString str [, offset])
  147.             - returns the offset in the string that matches
  148.               the string 'str', starting at position
  149.               'offset' if specified, otherwise searches the
  150.               entire string.
  151.               Returns -1 if no match is found
  152.  
  153.     int rindex(SPString str [, offset])
  154.             - returns the offset in the string that matches
  155.               the string 'str', starting at the end of the
  156.               string - 'offset' if specified, otherwise
  157.               searches the entire string.
  158.               Returns -1 if no match is found
  159.  
  160.     substring substr(offset [, len])
  161.             - returns the substring within the string that
  162.               starts at 'offset' and is 'len' characters, if
  163.               'len' is omitted the rest of the string is
  164.               returned.
  165.               This may be used as an lvalue, in which case
  166.               the characters are removed, and the RHS of the
  167.               expression in inserted at the same postion.
  168.  
  169.     SPStringList split([,pat] [,limit])
  170.             - same as SPStringList::split() but returns
  171.               a list of splits
  172.  
  173.     operator<        - These operators do what you would expect
  174.     operator>
  175.     operator<=
  176.     operator>=
  177.     operator==
  178.     operator!=
  179.  
  180.     operator+        - returns the result of contenating two or more
  181.               strings
  182.  
  183.     operator+=        - replaces the LHS of the expression with the
  184.               concatenation of the LHS with the RHS
  185.  
  186.     int m(const char *exp [,opts])
  187.             - returns 0 if the regular expression 'exp'
  188.               fails to match the string. Returns 1 if a
  189.               match was made
  190.               opts: (a const char * with default "")
  191.                   i - Forces case insensitive match
  192.     int m(const Regexp& exp)
  193.             - Same as above but takes a precompiled
  194.               regular expression.
  195.  
  196.     int m(const char *exp, SPStringList& l [,opts])
  197.             - Loads the list 'l' with all subexpression
  198.               matches of the regular expression 'exp' with
  199.               the string. Returns 0 if no matches were made.
  200.               Returns the number of matches if any
  201.               opts: (a const char * with default "")
  202.                   i - Forces case insensitive match
  203.  
  204.     int m(const Regexp& exp, SPStringList& l)
  205.             - Same as above but takes a precompiled
  206.               regular expression.
  207.  
  208.     int tr(search, repl [,opts])
  209.             - replaces all occurrences of characters in 'search'
  210.               with the equivalent character in 'repl'. If 'repl'
  211.               is empty then just counts the characters.
  212.               opts: (a const char *) default is ""
  213.                  c - complements the 'search' pattern. Replaces
  214.                  all characters that are not in 'search', with
  215.                  the last character specified in 'repl'.
  216.                  d - deletes characters in 'search' that don't have an
  217.                  equivalent 'repl'
  218.                 cd - deletes characters not in 'search' 
  219.                  s - compresses sequences of translated characters
  220.                  in resulting string
  221.  
  222.     int s(exp, repl [,opts])
  223.             - substitute the first substring matched by
  224.               'exp' with the string 'repl'. $& in 'repl'
  225.               will be replaced by the entire matching
  226.               string, $1 - $9 will be replaced by the
  227.               respective subexpression match. \$ or \\
  228.               will insert a $ or \ respectively.
  229.               opts: (a const char *) default is ""
  230.                  g - causes all occurrences of 'exp' in
  231.                  the string to be replaced by 'repl'
  232.                  i - Forces case insensitive matching                
  233.  
  234. class Assoc<T>        - an associative array whose key is a SPString
  235.               and the value is any type T
  236.  
  237.     Assoc(SPString defkey, T defvalue)
  238.             - Constructor for an associative array, 'defkey'
  239.               becomes the default key, and 'defvalue' is the
  240.               default value. The default value is used to
  241.               create a new Association if a key is specified
  242.               that doesn't yet exist.
  243.  
  244.     T& operator(SPString str)
  245.             - returns a reference to the value that is
  246.               associated with the key 'str'. This may be
  247.               used as an lvalue, and is in the only way to
  248.               make an association. If the key didn't exist
  249.               it will be entered with the default value, if
  250.               it was specified in the constructor, and a
  251.               reference to that is returned. If no default
  252.               was specified, then the value will be
  253.               undefined
  254.  
  255.     Binar& operator[n]    - Returns the (key, value) pair found at index
  256.               'n' of the associative array
  257.  
  258.     SPStringList keys()
  259.             - Returns a list of all the keys in the
  260.               associative array.
  261.  
  262.     SPList<T> values()
  263.             - Returns a list of all the values in the
  264.               associative array.
  265.  
  266.     int isin(SPString key)
  267.             - Returns 1 if the string 'key' is a valid key
  268.               in the associative array. Returns 0 otherwise.
  269.  
  270.     T adelete(SPString key)
  271.             - deletes the entry whose key matches the string
  272.               'key'. The value of the deleted entry is
  273.               returned. Nothing happens if the key is not
  274.               found.
  275.  
  276. Miscellaneous
  277. =============
  278. class Range        - stores the range used in Regexp
  279.  
  280.     Range(s, e)        - creates a range whose start is at position
  281.               's' and the last character in the range is at
  282.               position 'e'. (inclusive range)
  283.     
  284.     int start()        - returns the start of the range
  285.  
  286.     int end()        - returns the end of the range (the position
  287.               of the last character in the range)
  288.  
  289.     int length()    - returns the length of the range
  290.  
  291.     set(s, e)        - sets the start of the range to 's' and the
  292.               end of the range to 'e'
  293.  
  294. class Slice        - allows the creation of a set of index ranges
  295.               for use in SPList to create SubLists.
  296.               The order in which elements of an SPList is
  297.               accessed is the same as the order that the
  298.               indices are added to the Slice.
  299.  
  300.     Slice(const char *s)
  301.             - creates a slice specified by 's' where 's' is
  302.               a string that specifies a set of indices.
  303.               's' can be:-
  304.                 "a..b" or "a-b" which specifies a
  305.                    continuous range from 'a' thru 'b'.
  306.                 "a,b,c" which specifies individual indices
  307.                    'a' 'b' 'c'.
  308.                 "a..b,c,d" which specifies a range and 2
  309.                 individual indices.
  310.  
  311.     Slice(int i1, i2, ... , -1)
  312.             - creates a slice from a set of indices
  313.               specified by 'i1' 'i2' upto a parameter that
  314.               is -1. This is a variable number of arguments
  315.               terminated by a -1. NOTE that this is not
  316.               type safe.
  317.  
  318.     Slice(Range rng)    - creates a slice that is a range specified by
  319.               'rng'.
  320.      
  321.     add(int i)        - allows the dynamic creation of a slice by
  322.               adding individual indices to the slice.
  323.  
  324.     compact()        - may be used after add()'ing indices to a
  325.               Slice, and before using the Slice to optimise
  326.               it. (Optional)
  327.  
  328. class Regexp        - Henry Spencers regular expression package
  329.               oo-ized
  330.  
  331.     Regexp(exp [,opts])    - Compiles a regular expression that can be
  332.               passed to one of the m() functions.
  333.               opts: (an int with default 0)
  334.                   Regexp::nocase - Forces case insensitive
  335.                            match
  336.  
  337.     int match(targ)    - returns 1 if the compield RE matches 'targ'
  338.               returns 0 if not
  339.     
  340.     int groups()    - returns 1 + the number of subexpression
  341.               matches found in the last match(). If the
  342.               previous match() succeeded then the whole
  343.               match is included in the count (hence +1)
  344.     
  345.     Range getgroup(n)    - returns the range of the 'n'th subgroup.
  346.               'n' = 0 is the range of the entire match
  347.  
  348. SPStringList m(exp, targ [,opts])
  349.             - returns a list of all the subexpression
  350.               matches that occured when applying the
  351.               regular expression 'exp' to the string
  352.               'targ'. element 0 of the list is the first
  353.               subexpression, element 1 the next, etc.
  354.               opts: (a const char * with default "")
  355.                   i - Forces case insensitive match
  356.  
  357. xin >> astring        - Text from the stream xin is loaded into
  358.               astring, the text is expected to be
  359.               terminated by '\n', which is removed from
  360.               the stream, but not put into astring.
  361.               asring is cleared first.
  362.  
  363. xin >> astringlist    - Each Text line, as defined above, is loaded
  364.               into an element of astringlist, which
  365.               is reset first.
  366.  
  367. To pre-compile a regular expression use Regexp(const char *, iflg).
  368. eg
  369. Regexp rexp("...([a-z*)$");
  370. //Regexp rexp("...([a-z*)$", Regexp::nocase); // for case insensitive
  371. SPString s;
  372.  
  373. for(int i=0;i<large_number;i++){
  374.     ... load s with string ...
  375.     if(s.m(rexp)) ... do something when matched
  376. }
  377.  
  378.  
  379.