home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / lisp / elk-2_0.lha / elk-2.0 / contrib / regexp / string-extensions.doc < prev    next >
Encoding:
Text File  |  1991-04-02  |  3.3 KB  |  90 lines

  1.                              string-extensions.scm                             
  2.  
  3.  Various misc. functions that operate on strings.
  4.  Ideas from various languages like :- CommonLisp, Icon, Python, Perl ...
  5.  The definitions here are written for portability rather than for
  6.  speed.  If you really need fast versions, I suggest you re-code in
  7.  a low level language like C.
  8.  
  9.  System : ELK
  10.  System Specific Features :-
  11.    provide (as in CommonLisp)
  12.  
  13.  
  14. string-center s1 width . s2
  15.  Center the string `s1' in a string of size `width', padding on the
  16.  left and right, if necessary with the string `s2'.  If `s2' is not
  17.  given, then spaces are used.  If `s1' cannot be centered exactly,
  18.  it is placed left of center.  Truncation is then done at the left
  19.  and right as necessary.  For example :-
  20.    (string-center "Detroit" 10 "+") == "+Detroit++"
  21.    (string-center "Detroit" 6)      == "Detroi"
  22.  Based on the Icon function center(s1, i, s2)
  23.  Note this does not do the same thing as the Icon function for the case
  24.  where `width' < (string-length s1).  If anybody can explain why the
  25.  Icon function produces "etroit" in the second case, I'll be happy to
  26.  change it.
  27.  
  28. string-find-string str substr . optional-start
  29.  Look for the string `substr' in the string `str'
  30.  If it is there, return the position of the start of it, otherwise
  31.  return #false
  32.  
  33. string-find-char str chr . start-pos
  34.  Look for the character `chr' in the string `str' optionally starting
  35.  at position `start-pos'
  36.  Returns the first position in the string at which the character is found
  37.  of #f if the character wasn't found.
  38.  
  39. string-prefix? str prefix
  40.  Checks if the string `prefix' is a prefix of the string `str'
  41.  If it is it returns #t
  42.  
  43. string-left s1 width . s2
  44.  Produce a string of size `width' in which the string `s1' is positioned
  45.  at the left and `s2' is used to pad out the remaining characters to
  46.  the right.  For example :-
  47.    (string-left "Detroit" 10 "+") == "Detroit+++"
  48.    (string-left "Detroit" 6)      == "Detroi"
  49.  Based on the Icon function left(s1, i, s2)
  50.  
  51. string-replc str copies
  52.  Generate `copies' number of copies of the string `str'
  53.  For example :-
  54.    (string-replc "+*+" 3) == "+*++*++*+"
  55.    (string-replc s 0) == ""
  56.  Based on the Icon function repl(s, i)
  57.  Returns : string
  58.  
  59. string-replw str width
  60.  Geneate a string which is `width' characters long consisting on the
  61.  given string `str'.  For example :-
  62.    (string-replw "abc" 10) == "abcabcabca"
  63.    (string-replw "abc" 1)  == "a"
  64.    (string-replw "abc" 0)  == ""
  65.    (string-replw ""    1)  == ""
  66.  
  67. string-reverse str
  68.  Produces a string consisting of the characters of the string `str'
  69.  in reverse order.  For example :-
  70.    (string-reverse "string") == "gnirts"
  71.    (string-reverse "") == ""
  72.  Based on the Icon function reverse(s)
  73.  Returns : string
  74.  
  75. string-right s1 width . s2
  76.  Produce a string of size `width' in which the string `s1' is positioned
  77.  at the right and `s2' is used to pad out the remaining characters to
  78.  the left.  For example :-
  79.    (string-right "Detroit" 10 "+") == "+++Detroit"
  80.    (string-right "Detroit" 6)      == "etroit"
  81.  Based on the Icon function right(s1, i, s2)
  82.  
  83. string-split-whitespace str
  84.  Returns a list of whitespace delimited words in the string `str'.
  85.  If the string is empty or contains only whitespace, then
  86.  it returns the empty list.
  87.  
  88. string-trim-whitespace str
  89.  Strip the leading and trailing whitespace from the string `str'
  90.