fusionlanguage/fut

Regex C++ issue smatch vs cmatch

caesay opened this issue · 1 comments

The following fut code:

    public static string() StrTrim(string() str)
    {
        Match() match;
        if (match.Find(str, "(\\S.*\\S|\\S)")) {
            Console.WriteLine($"StrTrim: {str} -> {match.GetCapture(1)}");
            return match.GetCapture(1);
        }
        return str;
    }

produces the following (invalid) C++

std::string Util::strTrim(std::string str)
{
	std::cmatch match;
	if (std::regex_search(str, match, std::regex("(\\S.*\\S|\\S)"))) {
		std::cout << "StrTrim: " << str << " -> " << match.str(1) << '\n';
		return match.str(1);
	}
	return str;
}

Changing std::cmatch to std::smatch fixes the compiler error.

Thank you for reporting this!

I ended up with a different fix. std::smatch wouldn't work for matching string references. Therefore I kept std::cmatch, but emit str.c_str().