Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

string_append_subcstr 的改进建议。 #3

Closed
activesys opened this issue Nov 13, 2011 · 3 comments
Closed

string_append_subcstr 的改进建议。 #3

activesys opened this issue Nov 13, 2011 · 3 comments

Comments

@activesys
Copy link
Owner

string_append_subcstr 当遇到 '\0' 字符时,整个 '\0' 之后的字符串会被截断,即使字符串长度参数设为很大也不起作用。

建议 string 中可容纳 '\0' 字符,以保持和 c++ 中的 stl 一致,对于 c++ 程序,我经常通过类似于如下的代码来存放数据:
string buffer("hello\0, world.", 14);

之所以选择 string,是因为它很适合存储网络或串口数据,并提供了一些相关的算法方便解析数据,因此建议对于该功能,有必要考虑一下是否增加。

同样,对于获取数据时也可根据需要不截断 '\0' 数据。

@activesys
Copy link
Owner Author

basic_string_t类型的所有涉及到subcstr的函数的行为与STL的行为都不相符,原因是libcstl没有正确的处理subcstr的长度,而参考了subcstr中终结符的位置来计算长度,实际上subcstr函数中终结符是应该作为普通字符处理的。并且在其他内部的处理函数上,对于basic_string_t中包含的终结符要做特殊的处理,这与其他的容器不一致。

@activesys
Copy link
Owner Author

确认一下其他容器的array函数是否有类似的情况。

@activesys
Copy link
Owner Author

string_append_subcstr是一类terminator问题,在2.2版本中全部解决了,其他容器的init_copy_array函数不存在这样的问题,因为terminator是非法的字符。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant