Add a variant of wcs2string which accepts a ptr, length pair

This will be useful when refactoring separated buffers.
This commit is contained in:
ridiculousfish 2021-02-04 13:28:48 -08:00
parent 86a12e1abd
commit fc97151aec
2 changed files with 6 additions and 3 deletions

View file

@ -406,10 +406,12 @@ wcstring str2wcstring(const std::string &in, size_t len) {
return str2wcs_internal(in.data(), len);
}
std::string wcs2string(const wcstring &input) {
std::string wcs2string(const wcstring &input) { return wcs2string(input.data(), input.size()); }
std::string wcs2string(const wchar_t *in, size_t len) {
std::string result;
result.reserve(input.size());
wcs2string_callback(input.data(), input.size(), [&](const char *buff, size_t bufflen) {
result.reserve(len);
wcs2string_callback(in, len, [&](const char *buff, size_t bufflen) {
result.append(buff, bufflen);
return true;
});

View file

@ -291,6 +291,7 @@ wcstring str2wcstring(const std::string &in, size_t len);
/// This function decodes illegal character sequences in a reversible way using the private use
/// area.
std::string wcs2string(const wcstring &input);
std::string wcs2string(const wchar_t *in, size_t len);
// Check if we are running in the test mode, where we should suppress error output
#define TESTS_PROGRAM_NAME L"(ignore)"