Home My Page Projects Code Snippets Project Openings SML/NJ
Summary Activity Forums Tracker Lists Tasks Docs Surveys News SCM Files

SCM Repository

[smlnj] Diff of /sml/trunk/src/system/smlnj/init/substring.sml
ViewVC logotype

Diff of /sml/trunk/src/system/smlnj/init/substring.sml

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1147, Fri Mar 15 03:40:35 2002 UTC revision 1148, Fri Mar 15 21:38:57 2002 UTC
# Line 1  Line 1 
1    
2  (* substring.sml  (* substring.sml
3   *   *
4   * COPYRIGHT (c) 1995 AT&T Bell Laboratories.   * COPYRIGHT (c) 1995 AT&T Bell Laboratories.
# Line 61  Line 62 
62                else raise Core.Subscript                else raise Core.Subscript
63            end            end
64        | extract (s, i, SOME n) = substring(s, i, n)        | extract (s, i, SOME n) = substring(s, i, n)
65      fun all s = SS(s, 0, stringSize s)      fun full s = SS(s, 0, stringSize s)
66        val all = full                      (* deprecated *)
67    
68      fun isEmpty (SS(_, _, 0)) = true      fun isEmpty (SS(_, _, 0)) = true
69        | isEmpty _ = false        | isEmpty _ = false
# Line 105  Line 107 
107            PreString.revConcat (length (0, [], ssl))            PreString.revConcat (length (0, [], ssl))
108          end          end
109    
110      (* concatenate a list of substrings, using the given string as the
111       * separator *)
112        fun concatWith _ [] = ""
113          | concatWith _ [x] = string x
114          | concatWith sep (h :: t) = let
115                val sep' = full sep
116                fun loop ([], l) = concat (rev (l, []))
117                  | loop (h :: t, l) = loop (t, h :: sep' :: l)
118            in
119                loop (t, [h])
120            end
121    
122    (* explode a substring into a list of characters *)    (* explode a substring into a list of characters *)
123      fun explode (SS(s, i, n)) = let      fun explode (SS(s, i, n)) = let
124            fun f(l, j) = if (j < i)            fun f(l, j) = if (j < i)
# Line 116  Line 130 
130    
131    (* Substring comparisons *)    (* Substring comparisons *)
132      fun isPrefix s1 (SS(s2, i2, n2)) = PreString.isPrefix (s1, s2, i2, n2)      fun isPrefix s1 (SS(s2, i2, n2)) = PreString.isPrefix (s1, s2, i2, n2)
133        fun isSuffix s1 (SS(s2, i2, n2)) =
134            PreString.isPrefix (s1, s2, i2 + n2 - stringSize s1, n2)
135        fun isSubstring s1 (SS(s2, i2, n2)) = (* FIXME: KMP or BM (?) *)
136            let val stop = i2 + n2 - stringSize s1
137                fun matches_at_or_after i =
138                    i < stop andalso
139                    (PreString.isPrefix (s1, s2, i, n2) orelse
140                     matches_at_or_after (i + 1))
141            in
142                matches_at_or_after i2
143            end
144      fun compare (SS(s1, i1, n1), SS(s2, i2, n2)) =      fun compare (SS(s1, i1, n1), SS(s2, i2, n2)) =
145            PreString.cmp (s1, i1, n1, s2, i2, n2)            PreString.cmp (s1, i1, n1, s2, i2, n2)
146      fun collate cmpFn (SS(s1, i1, n1), SS(s2, i2, n2)) =      fun collate cmpFn (SS(s1, i1, n1), SS(s2, i2, n2)) =

Legend:
Removed from v.1147  
changed lines
  Added in v.1148

root@smlnj-gforge.cs.uchicago.edu
ViewVC Help
Powered by ViewVC 1.0.0