[MLton-commit] r5503
Vesa Karvonen
vesak at mlton.org
Wed Apr 11 07:58:17 PDT 2007
Added extendl and extendr.
----------------------------------------------------------------------
U mltonlib/trunk/com/ssh/extended-basis/unstable/detail/text/mk-text-ext.fun
U mltonlib/trunk/com/ssh/extended-basis/unstable/public/text/substring.sig
----------------------------------------------------------------------
Modified: mltonlib/trunk/com/ssh/extended-basis/unstable/detail/text/mk-text-ext.fun
===================================================================
--- mltonlib/trunk/com/ssh/extended-basis/unstable/detail/text/mk-text-ext.fun 2007-04-11 11:59:17 UTC (rev 5502)
+++ mltonlib/trunk/com/ssh/extended-basis/unstable/detail/text/mk-text-ext.fun 2007-04-11 14:58:16 UTC (rev 5503)
@@ -94,5 +94,21 @@
open Substring
type t = substring
val length = size
+ fun extendl pred ss = let
+ val (s, i, n) = base ss
+ val j = i+n
+ fun lp i = if 0 < i andalso pred (String.sub (s, i-1)) then lp (i-1)
+ else substring (s, i, j-i)
+ in
+ lp i
+ end
+ fun extendr pred ss = let
+ val (s, i, n) = base ss
+ val m = String.size s
+ fun lp j = if j < m andalso pred (String.sub (s, j)) then lp (j+1)
+ else substring (s, i, j-i)
+ in
+ lp (i+n)
+ end
end
end
Modified: mltonlib/trunk/com/ssh/extended-basis/unstable/public/text/substring.sig
===================================================================
--- mltonlib/trunk/com/ssh/extended-basis/unstable/public/text/substring.sig 2007-04-11 11:59:17 UTC (rev 5502)
+++ mltonlib/trunk/com/ssh/extended-basis/unstable/public/text/substring.sig 2007-04-11 14:58:16 UTC (rev 5503)
@@ -16,4 +16,18 @@
* Returns the size of the given substring. This is equivalent to
* {size}.
*)
+
+ val extendl : char UnPr.t -> t UnOp.t
+ val extendr : char UnPr.t -> t UnOp.t
+ (**
+ * These extend the substring with characters satisfying the predicate
+ * as far as possible within the underlying string either to the left
+ * or to the right. For example,
+ *
+ *> "aa" = string |< extendr (eq #"a") |< substring ("aabb", 0, 0)
+ *
+ * and
+ *
+ *> "aabb" = string |< extendr (const true) |< substring ("aabb", 0, 0)
+ *)
end
More information about the MLton-commit
mailing list