diff options
author | Piotr Fusik <piotr@fusion-lang.org> | 2024-02-15 19:55:48 +0100 |
---|---|---|
committer | Piotr Fusik <piotr@fusion-lang.org> | 2024-02-15 19:55:48 +0100 |
commit | 30d4cf0a191b923b2d651a16ad40dc6762a4bedb (patch) | |
tree | 239f3b52a06b474db5b40058562f7b61a4c82744 | |
parent | 65eb83dd509d03d00ae96d334c9b49436499221a (diff) |
[cpp] Fix Match.Find(stringStorage, regex).
Fix #138
-rw-r--r-- | GenCpp.fu | 4 | ||||
-rw-r--r-- | libfut.cpp | 4 | ||||
-rw-r--r-- | libfut.cs | 4 | ||||
-rw-r--r-- | libfut.js | 4 | ||||
-rw-r--r-- | test/RegexMatch.fu | 13 |
5 files changed, 23 insertions, 6 deletions
@@ -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); @@ -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); @@ -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); @@ -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 |