diff --git a/GenCpp.fu b/GenCpp.fu index 772ca0c9..a0c10666 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 116dc52a..b809bf43 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((*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((*args)[0].get())) writeBeginEnd((*args)[0].get()); else (*args)[0]->accept(this, FuPriority::argument); diff --git a/libfut.cs b/libfut.cs index 2f0aea79..082540bb 100644 --- a/libfut.cs +++ b/libfut.cs @@ -14420,7 +14420,9 @@ protected override void WriteCallExpr(FuExpr obj, FuMethod method, List 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 7faf1564..a14c1df1 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 edd5e1e9..15e2a5a7 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