Skip to content

Commit

Permalink
[cpp] Fix Match.Find(stringStorage, regex).
Browse files Browse the repository at this point in the history
Fix #138
  • Loading branch information
pfusik committed Feb 15, 2024
1 parent 65eb83d commit 30d4cf0
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 6 deletions.
4 changes: 3 additions & 1 deletion GenCpp.fu
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 3 additions & 1 deletion libfut.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 3 additions & 1 deletion libfut.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14420,7 +14420,9 @@ protected override void WriteCallExpr(FuExpr obj, FuMethod method, List<FuExpr>
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);
Expand Down
4 changes: 3 additions & 1 deletion libfut.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
13 changes: 11 additions & 2 deletions test/RegexMatch.fu
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 30d4cf0

Please sign in to comment.