Skip to content

Commit

Permalink
updates
Browse files Browse the repository at this point in the history
  • Loading branch information
arnoudbuzing committed Aug 14, 2018
1 parent ad0023b commit 4ca4e94
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions Prototypes/String.wl
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,11 @@ $UUIDStringPattern =

CapitalizeSentences[string_] := StringReplace[string, Map[# -> Capitalize[#] &, TextSentences[string]]]

StringSwap[string_String, a_String <-> b_String] := If[
StringDisjointQ[a,b],
StringSwap[string_String, a_String <-> b_String] := Module[{i1,i2,ok},
i1 = Interval /@ StringPosition[string,a];
i2 = Interval /@ StringPosition[string,b];
ok = SameQ[ {Interval[]}, Union @ Flatten @ Outer[IntervalIntersection,i1,i2]];
If[ ok,
StringReplace[string, {a -> b, b -> a}],
$Failed (* swapping can be problematic with things like "ab" <-> "bc"; give up on those cases for now *)
]
Expand Down

0 comments on commit 4ca4e94

Please sign in to comment.