C ++正则表达式在Android NDK中不起作用 [英] C++ regex not working in Android NDK

查看:248
本文介绍了C ++正则表达式在Android NDK中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下一段代码

#include <string>
struct Confs{
    std::string regexp;
};

class foo
{
public:
    static int search(const std::string& phrase);
    static const Confs configs[];
};



const Confs foo::configs[] = {
    //Regular Expresion
    {"^adb"}, //Example
    {"^qwr"}, //Example
    {"^a5eo"}, //Real
};

int foo::search(const std::string& phrase){
    for(size_t i=0; i<sizeof(configs)/sizeof(Confs); i++){
        std::regex re(configs[i].regexp);
        if (std::regex_search(phrase, re)) {
            return i;
        }
    }
    return -1;
}

int main(){
    std::cout << foo::search("a5eo_asd") << std::endl;
    return 0;
}

当我搜索"a5eo_asd"时,找不到匹配项.甚至在一开始就删除了"^".没有匹配项.

When I search for "a5eo_asd" it does not find a match. Even removing the "^" at the begining. No match.

与ndk-build(clang,NDK 10d)和gnustl_static c ++ 11一起编译.

但是,使用其他工具链进行的编译可以使相同的代码正常工作(Android平台构建,桌面g ++).我正在执行的模棱两可的事情是什么,以便代码在一个平台而不是另一个平台中找到一个匹配项?

However, the compilation with other toolschains make the same code to work (Android platform build, desktop g++). What is the ambiguous thing I am doing so that the code founds a match in a platform and not in another?

推荐答案

尝试使用免费的开源正则表达式匹配器(这里). 它很小的跨平台,速度极快,并且没有任何依赖关系. 只需将文件复制到您的源文件中,即可开始使用

Try the open source free regex matcher (here). Its tiny, cross platform, extremely fast, and does not have any dependencies. Just copy the files into your source and you are ready to go

这篇关于C ++正则表达式在Android NDK中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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