Delimiter character, generally one of DelimiterCharacters.
Original line to apply the replacement expression to.
Replacement expression to apply.
Whether or not to require the expression to end with the delimiter.
The passed line with the relevant bits replaced, or string.init if the expression didn't apply.
1 { 2 immutable replaced = "Hello D".sedReplaceImpl!'/'("s/Hello D/Hullo C/", relaxSyntax : false); 3 assert((replaced == "Hullo C"), replaced); 4 } 5 { 6 immutable replaced = "Hello D".sedReplaceImpl!'/'("s/l/L/g", relaxSyntax : false); 7 assert((replaced == "HeLLo D"), replaced); 8 } 9 { 10 immutable replaced = "Hello D".sedReplaceImpl!'/'("s/l/L/", relaxSyntax : false); 11 assert((replaced == "HeLlo D"), replaced); 12 } 13 { 14 immutable replaced = "I am a fish".sedReplaceImpl!'|'("s|fish|snek|g", relaxSyntax : false); 15 assert((replaced == "I am a snek"), replaced); 16 } 17 { 18 immutable replaced = "This is /a/a space".sedReplaceImpl!'/'("s/a\\//_/g", relaxSyntax : false); 19 assert((replaced == "This is /_a space"), replaced); 20 } 21 { 22 immutable replaced = "This is INVALID" 23 .sedReplaceImpl!'#'("s#asdfasdf#asdfasdf#asdfafsd#g", relaxSyntax : false); 24 assert(!replaced.length, replaced); 25 } 26 { 27 immutable replaced = "Hello D".sedReplaceImpl!'/'("s/Hello D/Hullo C", relaxSyntax : true); 28 assert((replaced == "Hullo C"), replaced); 29 } 30 { 31 immutable replaced = "Hello D".sedReplaceImpl!'/'("s/l/L/g", relaxSyntax : true); 32 assert((replaced == "HeLLo D"), replaced); 33 } 34 { 35 immutable replaced = "Hello D".sedReplaceImpl!'/'("s/l/L", relaxSyntax : true); 36 assert((replaced == "HeLlo D"), replaced); 37 } 38 { 39 immutable replaced = "Hello D".sedReplaceImpl!'/'("s/l/L/", relaxSyntax : true); 40 assert((replaced == "HeLlo D"), replaced); 41 } 42 { 43 immutable replaced = "This is INVALID".sedReplaceImpl!'#'("s#INVALID#valid##", relaxSyntax : true); 44 assert(!replaced.length, replaced); 45 } 46 { 47 immutable replaced = "snek".sedReplaceImpl!'/'("s/snek/", relaxSyntax : true); 48 assert(!replaced.length, replaced); 49 } 50 { 51 immutable replaced = "snek".sedReplaceImpl!'/'("s/snek", relaxSyntax : true); 52 assert(!replaced.length, replaced); 53 } 54 { 55 immutable replaced = "hink".sedReplaceImpl!'/'("s/honk/henk/", relaxSyntax : true); 56 assert(!replaced.length, replaced); 57 }
Private sed-replace implementation.
Works on any given character delimiter. Works with escapes.