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

Add c_str method to string to match std::string #238

Merged
merged 1 commit into from
Nov 6, 2024

Conversation

opera-aberglund
Copy link
Contributor

For reference: https://cplusplus.com/reference/string/string/c_str/

Just a convenience method, but it's one I used in the std lib and it was a hassle to remove every call to it when I switched to Cista strings.

@felixguendling
Copy link
Owner

The string.h string is not \0 terminated. So c_str() is very misleading here.

I propose to add .c_str() to the cista::cstring:
https://github.com/felixguendling/cista/blob/master/include/cista/containers/cstring.h

@opera-aberglund
Copy link
Contributor Author

The string.h string is not \0 terminated. So c_str() is very misleading here.

I propose to add .c_str() to the cista::cstring: https://github.com/felixguendling/cista/blob/master/include/cista/containers/cstring.h

Ah you're right. Let me fix it.

@felixguendling
Copy link
Owner

If you want to mirror the standard, it seems it's always const.

https://en.cppreference.com/w/cpp/string/basic_string/c_str

Only .data() has a non-const overload.

https://en.cppreference.com/w/cpp/string/basic_string/data

@opera-aberglund
Copy link
Contributor Author

If you want to mirror the standard, it seems it's always const.

https://en.cppreference.com/w/cpp/string/basic_string/c_str

Only .data() has a non-const overload.

https://en.cppreference.com/w/cpp/string/basic_string/data

Right right.. I though it was just an alias for .data(), but then perhaps it makes even more sense to have the c_str() method since it's guaranteed to be immutable.

@felixguendling felixguendling merged commit 847b271 into felixguendling:master Nov 6, 2024
10 checks passed
@felixguendling
Copy link
Owner

Thanks! :)

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

Successfully merging this pull request may close these issues.

2 participants