C ++ Mac OS无限循环在regex_replace如果给定空白正则表达式 [英] C++ Mac OS infinite loop in regex_replace if given blank regex expression

查看:253
本文介绍了C ++ Mac OS无限循环在regex_replace如果给定空白正则表达式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

执行...

std::regex_replace("the string", std::regex(""), "doesn't matter");

...我的Mac将无限期挂。我是新来的xcode,但我想我正确使用它。我在调试程序时点击暂停,发现最后执行的代码在regex库内。我需要空白正则表达式,因为用户可能输入空格。

...my Mac will hang indefinitely. I'm new to xcode, but I think I am using it correctly. I hit "pause" while debugging the program and found the last executed code is deep within the regex library. I need blank regex to work because the user may input blank.

这不会发生在Windows上(我在跨平台开发)。

This does not occur on Windows (I'm developing cross-platform).

这不会出现在 std :: regex_match()

推荐答案

至于根本原因,请参阅 regex.cpp 源代码,位于 Apple Open Source < a>:

As for the root cause, see the regex.cpp source code at Apple Open Source:

case regex_constants::__re_err_empty:
    return "An empty regex is not allowed in the POSIX grammar.";

因此,您必须检查用户输入,并禁止传递一个空字符串来创建正则表达式对象。

So, you have to check the user input and disallow passing an empty string to create a regex object.

这篇关于C ++ Mac OS无限循环在regex_replace如果给定空白正则表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆