Created attachment 930
std.regex.replace came to accept w/dstring
This issue was reported at 2ch.net.
import std.regex;
void main() {
.replace("a", .regex("a"), "b"); // ok
.replace("a"w, .regex("a"w), "b"w); // compile error
.replace("a"d, .regex("a"d), "b"d); // compile error
}
Comment #1 by rayerd.wiz — 2011-03-06T10:58:54Z
Comment on attachment 930
std.regex.replace came to accept w/dstring
From 22abb3531c34705395bee0c87b4c50ad9104adbe Mon Sep 17 00:00:00 2001
From: haru-s <[email protected]>
Date: Mon, 7 Mar 2011 03:56:41 +0900
Subject: [PATCH] std.regex.replace came to accept w/dstring.
---
std/regex.d | 17 ++++++++++++-----
1 files changed, 12 insertions(+), 5 deletions(-)
diff --git a/std/regex.d b/std/regex.d
index 683148f..9c00a0a 100644
--- a/std/regex.d
+++ b/std/regex.d
@@ -2576,8 +2576,8 @@ and, using the format string, generate and return a new string.
private static Range replace3(String)(String format, Range input,
regmatch_t[] pmatch)
{
- string result;
- uint c2;
+ Range result;
+ Unqual!(ElementType!String) c2;
sizediff_t startIdx;
sizediff_t endIdx;
int i;
@@ -2586,7 +2586,7 @@ and, using the format string, generate and return a new string.
result.length = 0;
for (size_t f = 0; f < format.length; f++)
{
- char c = format[f];
+ Unqual!(ElementType!String) c = format[f];
L1:
if (c != '$')
{
@@ -2640,7 +2640,7 @@ and, using the format string, generate and return a new string.
{
result ~= '$';
result ~= c;
- c = cast(char)c2;
+ c = c2;
goto L1;
}
}
@@ -2665,7 +2665,7 @@ and, using the format string, generate and return a new string.
}
return result;
}
-
+
/* ***********************************
* Like replace(char[] format), but uses old style formatting:
<table border=1 cellspacing=0 cellpadding=5>
@@ -2755,6 +2755,13 @@ unittest
assert(match("abc", regex(".b..")).empty);
}
+unittest
+{
+ replace("a", regex("a"), "b");
+ replace("a"w, regex("a"w), "b"w);
+ replace("a"d, regex("a"d), "b"d);
+}
+
//------------------------------------------------------------------------------
/**
--
1.7.3.1.msysgit.0