regex and sortedarray changes
authortimmy <timmy@timmy-desktop.(none)>
Thu, 18 Mar 2010 03:08:57 +0000 (23:08 -0400)
committertimmy <timmy@timmy-desktop.(none)>
Thu, 18 Mar 2010 03:08:57 +0000 (23:08 -0400)
src/core/sorted.slate
src/lib/convenience.slate [new file with mode: 0644]
src/lib/regex.slate

index 4302bd1..63aa21c 100644 (file)
@@ -29,6 +29,12 @@ sc@(SortedArray traits) newSortedBy: block
 sc@(SortedArray traits) shouldArrange: x before: y
 [sc sortBlock applyTo: {x. y}].
 
+sc@(SortedArray traits) min
+[sc isEmpty ifFalse: [sc first]].
+
+sc@(SortedArray traits) max
+[sc isEmpty ifFalse: [sc last]].
+
 sc@(SortedArray traits) median
 [sc at: sc size + 1 // 2].
 
diff --git a/src/lib/convenience.slate b/src/lib/convenience.slate
new file mode 100644 (file)
index 0000000..eda17c8
--- /dev/null
@@ -0,0 +1,12 @@
+
+c@(Collection traits) min
+[
+  c reduce: #min: `er
+].
+
+c@(Collection traits) max
+[
+  c reduce: #max: `er
+
+].
+
index 48c4ad6..af6520d 100644 (file)
@@ -275,6 +275,14 @@ m@(Regex Matcher traits) subexpressionMatches
   matches
 ].
 
+m@(Regex Matcher traits) subexpressionMatchesArray
+[ | matches |
+  matches: (ExtensibleArray new &capacity: m subexpressions keys max + 1).
+  m subexpression keysDo: [|:key | matches at: key put: (m subexpression: key)].
+  matches
+].
+
+
 m@(Regex Matcher traits) matches: node
 [
   (m match: node) ~= Regex Matcher Fail
@@ -290,6 +298,17 @@ m@(Regex Matcher traits) match: s@(String traits)
   m match: s from: 0
 ].
 
+string@(String traits) =~ regex@(Regex Matcher traits)
+[
+  regex `>> [match: string. subexpressionMatchesArray]
+].
+
+string@(String traits) =~ regex@(String traits)
+[
+  string =~ (Regex Matcher newOn: regex)
+].
+
+
 m@(Regex Matcher traits) match: s@(String traits) from: fromStart
 [ |res|
   m subexpressions: Dictionary new.