Add and use str2wcstring(string, size_t)

This is just for convenience.
This commit is contained in:
Fabian Homborg 2017-12-19 11:05:20 +01:00
parent 2de38ef7bf
commit f9d883dd74
3 changed files with 7 additions and 1 deletions

View file

@ -91,7 +91,7 @@ static const wchar_t *string_get_arg_stdin(wcstring *storage, const io_streams_t
}
// Split the buffer on the '\n' and return the first part.
*storage = str2wcstring(buffer.c_str(), pos);
*storage = str2wcstring(buffer, pos);
buffer.erase(0, pos + 1);
return storage->c_str();
}

View file

@ -290,6 +290,11 @@ wcstring str2wcstring(const std::string &in) {
return str2wcs_internal(in.data(), in.size());
}
wcstring str2wcstring(const std::string &in, size_t len) {
// Handles embedded nulls!
return str2wcs_internal(in.data(), len);
}
char *wcs2str(const wchar_t *in) {
if (!in) return NULL;
size_t desired_size = MAX_UTF8_BYTES * wcslen(in) + 1;

View file

@ -285,6 +285,7 @@ int fgetws2(wcstring *s, FILE *f);
wcstring str2wcstring(const char *in);
wcstring str2wcstring(const char *in, size_t len);
wcstring str2wcstring(const std::string &in);
wcstring str2wcstring(const std::string &in, size_t len);
/// Returns a newly allocated multibyte character string equivalent of the specified wide character
/// string.