summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPiotr Fusik <piotr@fusion-lang.org>2024-02-15 19:55:48 +0100
committerPiotr Fusik <piotr@fusion-lang.org>2024-02-15 19:55:48 +0100
commit30d4cf0a191b923b2d651a16ad40dc6762a4bedb (patch)
tree239f3b52a06b474db5b40058562f7b61a4c82744
parent65eb83dd509d03d00ae96d334c9b49436499221a (diff)
[cpp] Fix Match.Find(stringStorage, regex).
Fix #138
-rw-r--r--GenCpp.fu4
-rw-r--r--libfut.cpp4
-rw-r--r--libfut.cs4
-rw-r--r--libfut.js4
-rw-r--r--test/RegexMatch.fu13
5 files changed, 23 insertions, 6 deletions
diff --git a/GenCpp.fu b/GenCpp.fu
index 772ca0c..a0c1066 100644
--- a/GenCpp.fu
+++ b/GenCpp.fu
@@ -1160,7 +1160,9 @@ public class GenCpp : GenCCpp
case FuId.MatchFindStr:
case FuId.MatchFindRegex:
Write("std::regex_search(");
- if (args[0].Type.Id == FuId.StringPtrType && !(args[0] is FuLiteral))
+ if (args[0].Type.Id == FuId.StringStorageType)
+ WritePostfix(args[0], ".c_str()");
+ else if (args[0].Type.Id == FuId.StringPtrType && !(args[0] is FuLiteral))
WriteBeginEnd(args[0]);
else
args[0].Accept(this, FuPriority.Argument);
diff --git a/libfut.cpp b/libfut.cpp
index 116dc52..b809bf4 100644
--- a/libfut.cpp
+++ b/libfut.cpp
@@ -14052,7 +14052,9 @@ void GenCpp::writeCallExpr(const FuExpr * obj, const FuMethod * method, const st
case FuId::matchFindStr:
case FuId::matchFindRegex:
write("std::regex_search(");
- if ((*args)[0]->type->id == FuId::stringPtrType && !dynamic_cast<const FuLiteral *>((*args)[0].get()))
+ if ((*args)[0]->type->id == FuId::stringStorageType)
+ writePostfix((*args)[0].get(), ".c_str()");
+ else if ((*args)[0]->type->id == FuId::stringPtrType && !dynamic_cast<const FuLiteral *>((*args)[0].get()))
writeBeginEnd((*args)[0].get());
else
(*args)[0]->accept(this, FuPriority::argument);
diff --git a/libfut.cs b/libfut.cs
index 2f0aea7..082540b 100644
--- a/libfut.cs
+++ b/libfut.cs
@@ -14420,7 +14420,9 @@ namespace Fusion
case FuId.MatchFindStr:
case FuId.MatchFindRegex:
Write("std::regex_search(");
- if (args[0].Type.Id == FuId.StringPtrType && !(args[0] is FuLiteral))
+ if (args[0].Type.Id == FuId.StringStorageType)
+ WritePostfix(args[0], ".c_str()");
+ else if (args[0].Type.Id == FuId.StringPtrType && !(args[0] is FuLiteral))
WriteBeginEnd(args[0]);
else
args[0].Accept(this, FuPriority.Argument);
diff --git a/libfut.js b/libfut.js
index 7faf156..a14c1df 100644
--- a/libfut.js
+++ b/libfut.js
@@ -14853,7 +14853,9 @@ export class GenCpp extends GenCCpp
case FuId.MATCH_FIND_STR:
case FuId.MATCH_FIND_REGEX:
this.write("std::regex_search(");
- if (args[0].type.id == FuId.STRING_PTR_TYPE && !(args[0] instanceof FuLiteral))
+ if (args[0].type.id == FuId.STRING_STORAGE_TYPE)
+ this.writePostfix(args[0], ".c_str()");
+ else if (args[0].type.id == FuId.STRING_PTR_TYPE && !(args[0] instanceof FuLiteral))
this.#writeBeginEnd(args[0]);
else
args[0].accept(this, FuPriority.ARGUMENT);
diff --git a/test/RegexMatch.fu b/test/RegexMatch.fu
index edd5e1e..15e2a5a 100644
--- a/test/RegexMatch.fu
+++ b/test/RegexMatch.fu
@@ -3,8 +3,17 @@ public class Test
public static bool Run()
{
Match() m;
- string s = "The quick brown fox jumps over the lazy dog";
- if (!m.Find(s, "(B.+?) (\\wo\\w)", RegexOptions.IgnoreCase)) //FAIL: swift TODO; cl
+ string() s = "The quick brown fox jumps over the lazy dog"; //FAIL: cl
+ if (!m.Find(s, "(B.+?) (\\wo\\w)", RegexOptions.IgnoreCase)) //FAIL: swift TODO
+ return false;
+ if (m.Start != 10
+ || m.End != 19 || m.End * 2 != 38
+ || m.Length != 9 || m.Length * 2 != 18
+ || m.Value != "brown fox"
+ || m.GetCapture(1) != "brown" || m.GetCapture(2) != "fox")
+ return false;
+ string p = "The quick brown fox jumps over the lazy dog";
+ if (!m.Find(p, "(B.+?) (\\wo\\w)", RegexOptions.IgnoreCase))
return false;
return m.Start == 10
&& m.End == 19 && m.End * 2 == 38