我们在验证std::string
包含有效UTF_8字符集的 a 时遇到问题。问题是我有一个std::string
in 程序,它在运行时可能会收到一些无效的 UTF-8字符。目前我正在参考 glib/utf8-validate.c 文件以供参考。但是glib使用的数据类型不是a std::string
,所以不能用这个。
平台是 QNX(Linux 主机开发)。
首先,您应该始终在问题中包含 QNX 版本,因为例如 6.3.2 (Neutrino) 的 gcc 版本是 3.7。
第二次使用 const char* c_str() const; 对于 c 函数。
#include <stdio.h>
#include <dbus/dbus.h>
#include <string>
#include <iostream>
int main(void)
{
std::string test = "test";
std::cout << dbus_validate_utf8(test.c_str(), 0) << std::endl;
return 0;
}
但这可能会帮助而不是使用 dbus_validate_utf8 吗?:
甚至这样: