home *** CD-ROM | disk | FTP | other *** search
/ ftp.cs.arizona.edu / ftp.cs.arizona.edu.tar / ftp.cs.arizona.edu / icon / historic / v941.tgz / icon.v941src.tar / icon.v941src / ipl / procs / caseless.icn < prev    next >
Text File  |  2000-07-29  |  3KB  |  133 lines

  1. ############################################################################
  2. #
  3. #    File:     caseless.icn
  4. #
  5. #    Subject:  Procedures to perform caseless scanning
  6. #
  7. #    Author:   Nevin J. Liber
  8. #
  9. #    Date:     August 19, 1996
  10. #
  11. ############################################################################
  12. #
  13. #   This file is in the public domain.
  14. #
  15. ############################################################################
  16. #
  17. #    These procedures are analogous to the standard string-analysis
  18. #    functions except that uppercase letters are considered equivalent to
  19. #    lowercase letters.
  20. #
  21. #    anycl(c, s, i1, i2)    succeeds and produces i1 + 1, provided
  22. #                map(s[i1]) is in cset(map(c)) and i2 is
  23. #                greater than i1.  It fails otherwise.
  24. #
  25. #    balcl(c1, c2, c3, s, i1, i2)    generates the sequence of integer
  26. #                    positions in s preceding a
  27. #                    character of cset(map(c1)) in
  28. #                    map(s[i1:i2]) that is balanced with
  29. #                    respect to characters in cset(map(c2))
  30. #                    and cset(map(c3)), but fails if there
  31. #                    is no such position.
  32. #
  33. #    findcl(s1, s2, i1, i2)    generates the sequence of integer positions in
  34. #                s2 at which map(s1) occurs as a substring
  35. #                in map(s2[i1:i2]), but fails if there is no
  36. #                such position.
  37. #
  38. #    manycl(c, s, i1, i2)    succeeds and produces the position in s
  39. #                after the longest initial sequence of
  40. #                characters in cset(map(c)) within
  41. #                map(s[i1:i2]).  It fails if map(s[i1]) is not
  42. #                in cset(map(c)).
  43. #
  44. #    matchcl(s1, s2, i1, i2)    produces i1 + *s1 if
  45. #                map(s1) == map(s2[i1+:=*s1]) but fails
  46. #                otherwise.
  47. #
  48. #    uptocl(c, s, i1, i2)    generates the sequence of integer positions in
  49. #                s preceding a character of cset(map(c)) in
  50. #                map(s[i1:i2]).  It fails if there is no such
  51. #                position.
  52. #
  53. #    Defaults:    s, s2    &subject
  54. #            i1    &pos if s or s2 is defaulted; otherwise 1
  55. #            i2    0
  56. #            c1    &cset
  57. #            c2    '('
  58. #            c3    ')'
  59. #
  60. #    Errors:    101    i1 or i2 not integer
  61. #        103    s or s1 or s2 not string
  62. #        104    c or c1 or c2 or c3 not cset
  63. #
  64. ################################################################################
  65.  
  66.  
  67. procedure anycl(c, s, i1, i2)    #:    Caseless version of any()
  68.  
  69.     c := cset(map(cset(c)))
  70.     /i1 := (/s & &pos)
  71.     s := map(string(s) | (/s & &subject))
  72.  
  73.     return any(c, s, i1, i2)
  74.  
  75. end
  76.  
  77.  
  78. procedure balcl(c1, c2, c3, s, i1, i2)    #:    Caseless version of bal()
  79.  
  80.     c1 := cset(map(cset(c1)))
  81.     c2 := cset(map(cset(c2)))
  82.     c3 := cset(map(cset(c3)))
  83.     /i1 := (/s & &pos)
  84.     s := map(string(s) | (/s & &subject))
  85.  
  86.     suspend bal(c1, c2, c3, s, i1, i2)
  87.  
  88. end
  89.  
  90.  
  91. procedure findcl(s1, s2, i1, i2)    #:    Caseless version of find()
  92.  
  93.     s1 := map(string(s1))
  94.     /i1 := (/s2 & &pos)
  95.     s2 := map(string(s2) | (/s2 & &subject))
  96.  
  97.     suspend find(s1, s2, i1, i2)
  98.  
  99. end
  100.  
  101.  
  102. procedure manycl(c, s, i1, i2)    #:    Caseless version of many()
  103.  
  104.     c := cset(map(cset(c)))
  105.     /i1 := (/s & &pos)
  106.     s := map(string(s) | (/s & &subject))
  107.  
  108.     return many(c, s, i1, i2)
  109.  
  110. end
  111.  
  112.  
  113. procedure matchcl(s1, s2, i1, i2)    #:    Caseless version of match()
  114.  
  115.     s1 := map(string(s1))
  116.     /i1 := (/s2 & &pos)
  117.     s2 := map(string(s2) | (/s2 & &subject))
  118.  
  119.     return match(s1, s2, i1, i2)
  120.  
  121. end
  122.  
  123.  
  124. procedure uptocl(c, s, i1, i2)    #:    Caseless version of upto()
  125.  
  126.     c := cset(map(cset(c)))
  127.     /i1 := (/s & &pos)
  128.     s := map(string(s) | (/s & &subject))
  129.  
  130.     suspend upto(c, s, i1, i2)
  131.  
  132. end
  133.