More local string cleanups.
This commit is contained in:
19
src/form.cc
19
src/form.cc
@ -1279,24 +1279,23 @@ char *DilloHtmlFormImpl::makeMultipartBoundary(iconv_t char_encoder,
|
||||
std::string DilloHtmlFormImpl::encodeText(iconv_t char_encoder, std::string &&input)
|
||||
{
|
||||
int rc = 0;
|
||||
Dstr *output;
|
||||
const int bufsize = 128;
|
||||
inbuf_t *inPtr;
|
||||
char *buffer, *outPtr;
|
||||
char *outPtr;
|
||||
size_t inLeft, outRoom;
|
||||
bool bad_chars = false;
|
||||
|
||||
if ((char_encoder == (iconv_t) -1) || input.empty())
|
||||
return input;
|
||||
|
||||
output = dStr_new("");
|
||||
std::string output;
|
||||
inPtr = input.data();
|
||||
inLeft = input.size();
|
||||
buffer = dNew(char, bufsize);
|
||||
std::vector< char > buffer( bufsize );
|
||||
|
||||
while ((rc != EINVAL) && (inLeft > 0)) {
|
||||
|
||||
outPtr = buffer;
|
||||
outPtr = buffer.data();
|
||||
outRoom = bufsize;
|
||||
|
||||
rc = iconv(char_encoder, &inPtr, &inLeft, &outPtr, &outRoom);
|
||||
@ -1309,7 +1308,7 @@ std::string DilloHtmlFormImpl::encodeText(iconv_t char_encoder, std::string &&in
|
||||
// GNU iconv has the undocumented(!) behavior that EILSEQ is also
|
||||
// returned when a character cannot be converted.
|
||||
|
||||
dStr_append_l(output, buffer, bufsize - outRoom);
|
||||
output+= std::string_view{ buffer.data(), buffer.data() + bufsize - outRoom };
|
||||
|
||||
if (rc == -1) {
|
||||
rc = errno;
|
||||
@ -1319,7 +1318,7 @@ std::string DilloHtmlFormImpl::encodeText(iconv_t char_encoder, std::string &&in
|
||||
bad_chars = true;
|
||||
inPtr++;
|
||||
inLeft--;
|
||||
dStr_append_c(output, '?');
|
||||
output+= '?';
|
||||
} else if (rc == EINVAL) {
|
||||
MSG_ERR("Form encode text: bad source string.\n");
|
||||
}
|
||||
@ -1334,11 +1333,7 @@ std::string DilloHtmlFormImpl::encodeText(iconv_t char_encoder, std::string &&in
|
||||
MSG_WARN("Form encode text: string cannot be converted cleanly.\n");
|
||||
}
|
||||
|
||||
dFree(buffer);
|
||||
|
||||
std::string rv= output->str;
|
||||
dStr_free( output, 1 );
|
||||
return rv;
|
||||
return output;
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user