From 6b32ac2e49921ffd1e5653b534a9c72c89b214e3 Mon Sep 17 00:00:00 2001 From: Jack Stouffer Date: Sat, 17 Jun 2017 18:57:21 -0400 Subject: [PATCH 1/2] Added migration guide to the pattern changelog --- changelog/pattern-deprecate.dd | 57 ++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/changelog/pattern-deprecate.dd b/changelog/pattern-deprecate.dd index 2fe5214fe66..fd14f94333b 100644 --- a/changelog/pattern-deprecate.dd +++ b/changelog/pattern-deprecate.dd @@ -8,3 +8,60 @@ $(MREF std, regex) and $(MREF std, algorithm). They will be removed from $(MREF std, string) on May 2018. If you still need to use these, please see $(LINK2 https://github.com/dlang/undeaD, undeaD). + +The following are examples of the deprecated functions, and their modern replacements. +Note that the new code is based on the range model, and therefore does not have +mutate against the original string, unlike the old code. + +$(REF munch, std, string): +------- +import std.algorithm; +import std.ascii; +import std.string; +import std.utf; + +string s = "\tabc"; + +// old +s.munch(whitespace); + +// new +size_t i = s.byCodeUnit.countUntil!(a => !isWhite(a)); +s = s[i .. $]; +------- + +$(REF inPattern, std, string): +------- +import std.string; +import std.regex; + +// old +if (inPattern('x', "a-z")) { ... } + +// new +if ("x".matchFirst(regex("[a-z]"))) { ... } +------- + +$(REF removechars, std, string): +------- +import std.string; +import std.regex; + +// old +"abc".removechars("a-z"); + +// new +"abc".replaceAll(regex("[a-z]"), ""); +------- + +$(REF squeeze, std, string): +------- +import std.algorithm; +import std.string; + +// old +"hello".squeeze; + +// new +"hello".uniq; +------- \ No newline at end of file From 29b5a688c5dad69165508d1eec865115b016f7b2 Mon Sep 17 00:00:00 2001 From: Martin Nowak Date: Sat, 24 Jun 2017 16:47:03 +0200 Subject: [PATCH 2/2] address review comments - also add ref to replacement function --- changelog/pattern-deprecate.dd | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/changelog/pattern-deprecate.dd b/changelog/pattern-deprecate.dd index fd14f94333b..12bedbeb189 100644 --- a/changelog/pattern-deprecate.dd +++ b/changelog/pattern-deprecate.dd @@ -10,10 +10,8 @@ $(MREF std, string) on May 2018. If you still need to use these, please see $(LINK2 https://github.com/dlang/undeaD, undeaD). The following are examples of the deprecated functions, and their modern replacements. -Note that the new code is based on the range model, and therefore does not have -mutate against the original string, unlike the old code. -$(REF munch, std, string): +Use $(REF find, std, algorithm, searching) to replace $(REF munch, std, string): ------- import std.algorithm; import std.ascii; @@ -26,11 +24,10 @@ string s = "\tabc"; s.munch(whitespace); // new -size_t i = s.byCodeUnit.countUntil!(a => !isWhite(a)); -s = s[i .. $]; +s = s.find!(a => !isWhite(a)); ------- -$(REF inPattern, std, string): +Use $(REF matchFirst, std, regex) to replace $(REF inPattern, std, string): ------- import std.string; import std.regex; @@ -42,7 +39,7 @@ if (inPattern('x', "a-z")) { ... } if ("x".matchFirst(regex("[a-z]"))) { ... } ------- -$(REF removechars, std, string): +Use $(REF replaceAll, std, regex) to replace $(REF removechars, std, string): ------- import std.string; import std.regex; @@ -54,7 +51,7 @@ import std.regex; "abc".replaceAll(regex("[a-z]"), ""); ------- -$(REF squeeze, std, string): +Use $(REF uniq, std, algorithm, iteration) to replace $(REF squeeze, std, string): ------- import std.algorithm; import std.string; @@ -64,4 +61,4 @@ import std.string; // new "hello".uniq; -------- \ No newline at end of file +-------