Another dString retired.

This commit is contained in:
2025-08-11 03:24:48 -04:00
parent 9c4d7b6849
commit 17b7c8a8dc
3 changed files with 24 additions and 28 deletions

View File

@ -678,24 +678,24 @@ void Html_tag_close_textarea(DilloHtml *html)
if (html->InFlags & IN_TEXTAREA && !S_TOP(html)->display_none) { if (html->InFlags & IN_TEXTAREA && !S_TOP(html)->display_none) {
/* Remove the line ending that follows the opening tag */ /* Remove the line ending that follows the opening tag */
if (html->Stash->str[0] == '\r') if (html->Stash[0] == '\r')
dStr_erase(html->Stash, 0, 1); html->Stash.erase( 0, 1 );
if (html->Stash->str[0] == '\n') if (html->Stash[0] == '\n')
dStr_erase(html->Stash, 0, 1); html->Stash.erase( 0, 1 );
/* As the spec recommends to canonicalize line endings, it is safe /* As the spec recommends to canonicalize line endings, it is safe
* to replace '\r' with '\n'. It will be canonicalized anyway! */ * to replace '\r' with '\n'. It will be canonicalized anyway! */
for (i = 0; i < html->Stash->len; ++i) { for (i = 0; i < html->Stash.size(); ++i) {
if (html->Stash->str[i] == '\r') { if (html->Stash[i] == '\r') {
if (html->Stash->str[i + 1] == '\n') if (html->Stash[i + 1] == '\n')
dStr_erase(html->Stash, i, 1); html->Stash.erase( i, 1 );
else else
html->Stash->str[i] = '\n'; html->Stash[i] = '\n';
} }
} }
/* The HTML3.2 spec says it can have "text and character entities". */ /* The HTML3.2 spec says it can have "text and character entities". */
auto str = a_Html_parse_entities(html, html->Stash->str, html->Stash->len); auto str = a_Html_parse_entities(html, html->Stash.c_str(), html->Stash.size());
auto input = Html_get_current_input(*html); auto input = Html_get_current_input(*html);
if (input) { if (input) {
input->init_str = str; input->init_str = str;
@ -1973,6 +1973,6 @@ static void Html_option_finish(DilloHtml *html)
(input->type == DILLO_HTML_INPUT_SELECT || (input->type == DILLO_HTML_INPUT_SELECT ||
input->type == DILLO_HTML_INPUT_SEL_LIST)) { input->type == DILLO_HTML_INPUT_SEL_LIST)) {
DilloHtmlOptbase *opt = input->select->getCurrentOpt (); DilloHtmlOptbase *opt = input->select->getCurrentOpt ();
opt->setContent (html->Stash->str, html->Stash->len); opt->setContent (html->Stash.c_str(), html->Stash.size());
} }
} }

View File

@ -491,7 +491,6 @@ DilloHtml::DilloHtml(BrowserWindow *p_bw, const DilloUrl *url,
InFlags = IN_NONE; InFlags = IN_NONE;
Stash = dStr_new("");
StashSpace = false; StashSpace = false;
pre_column = 0; pre_column = 0;
@ -603,7 +602,6 @@ int DilloHtml::getCurrLineNumber()
*/ */
void DilloHtml::freeParseData() void DilloHtml::freeParseData()
{ {
dStr_free(Stash, TRUE);
dStr_free(attr_data, TRUE); dStr_free(attr_data, TRUE);
} }
@ -814,7 +812,7 @@ void a_Html_stash_init(DilloHtml *html)
{ {
S_TOP(html)->parse_mode = DILLO_HTML_PARSE_MODE_STASH; S_TOP(html)->parse_mode = DILLO_HTML_PARSE_MODE_STASH;
html->StashSpace = false; html->StashSpace = false;
dStr_truncate(html->Stash, 0); html->Stash.clear();
} }
/** /**
@ -1104,10 +1102,10 @@ static void Html_process_space(DilloHtml *html, const char *space,
if (S_TOP(html)->display_none) { if (S_TOP(html)->display_none) {
/* do nothing */ /* do nothing */
} else if (parse_mode == DILLO_HTML_PARSE_MODE_STASH) { } else if (parse_mode == DILLO_HTML_PARSE_MODE_STASH) {
html->StashSpace = (html->Stash->len > 0); html->StashSpace = not html->Stash.empty();
} else if (parse_mode == DILLO_HTML_PARSE_MODE_VERBATIM) { } else if (parse_mode == DILLO_HTML_PARSE_MODE_VERBATIM) {
dStr_append_l(html->Stash, space, spacesize); html->Stash+= std::string_view{ space, space + spacesize };
} else if (parse_mode == DILLO_HTML_PARSE_MODE_PRE) { } else if (parse_mode == DILLO_HTML_PARSE_MODE_PRE) {
int spaceCnt = 0; int spaceCnt = 0;
@ -1168,7 +1166,7 @@ static void Html_process_space(DilloHtml *html, const char *space,
} }
if (parse_mode == DILLO_HTML_PARSE_MODE_STASH_AND_BODY) if (parse_mode == DILLO_HTML_PARSE_MODE_STASH_AND_BODY)
html->StashSpace = (html->Stash->len > 0); html->StashSpace = not html->Stash.empty();
} }
} }
@ -1195,15 +1193,14 @@ static void Html_process_word(DilloHtml *html, const char *word, int size)
if (parse_mode == DILLO_HTML_PARSE_MODE_STASH || if (parse_mode == DILLO_HTML_PARSE_MODE_STASH ||
parse_mode == DILLO_HTML_PARSE_MODE_STASH_AND_BODY) { parse_mode == DILLO_HTML_PARSE_MODE_STASH_AND_BODY) {
if (html->StashSpace) { if (html->StashSpace) {
dStr_append_c(html->Stash, ' '); html->Stash+= ' ';
html->StashSpace = false; html->StashSpace = false;
} }
const std::string Pword= a_Html_parse_entities(html, word, size); html->Stash+= a_Html_parse_entities(html, word, size);
dStr_append(html->Stash, Pword.c_str());
} else if (parse_mode == DILLO_HTML_PARSE_MODE_VERBATIM) { } else if (parse_mode == DILLO_HTML_PARSE_MODE_VERBATIM) {
/* word goes in untouched, it is not processed here. */ /* word goes in untouched, it is not processed here. */
dStr_append_l(html->Stash, word, size); html->Stash+= std::string_view{ word, word + size };
} }
if (parse_mode == DILLO_HTML_PARSE_MODE_STASH || if (parse_mode == DILLO_HTML_PARSE_MODE_STASH ||
@ -1667,7 +1664,7 @@ static void Html_tag_close_title(DilloHtml *html)
/* title is only valid inside HEAD */ /* title is only valid inside HEAD */
if (html->InFlags & IN_HEAD && html->Num_TITLE == 1) { if (html->InFlags & IN_HEAD && html->Num_TITLE == 1) {
/* Ignore empty titles: <title></title> */ /* Ignore empty titles: <title></title> */
char *title = html->Stash->str; const char *title = html->Stash.c_str();
if (!title || title[0] == '\0') if (!title || title[0] == '\0')
return; return;
a_UIcmd_set_page_title(html->bw, title); a_UIcmd_set_page_title(html->bw, title);
@ -1730,8 +1727,8 @@ static void Html_tag_open_style(DilloHtml *html, const char *tag, int tagsize)
static void Html_tag_close_style(DilloHtml *html) static void Html_tag_close_style(DilloHtml *html)
{ {
if (prefs.parse_embedded_css && html->loadCssFromStash) if (prefs.parse_embedded_css && html->loadCssFromStash)
html->styleEngine->parse(html, html->base_url.get(), html->Stash->str, html->styleEngine->parse(html, html->base_url.get(), html->Stash.c_str(),
html->Stash->len, CSS_ORIGIN_AUTHOR); html->Stash.size(), CSS_ORIGIN_AUTHOR);
} }
/* /*
@ -4262,9 +4259,8 @@ static int Html_write_raw(DilloHtml *html, char *buf, int bufsize, int Eof)
} else if (strncmp(buf + buf_index, "</", 2) == 0 && } else if (strncmp(buf + buf_index, "</", 2) == 0 &&
Html_match_tag(tag, buf+buf_index+2, strlen(tag)+1)) { Html_match_tag(tag, buf+buf_index+2, strlen(tag)+1)) {
/* copy VERBATIM text into the stash buffer */ /* copy VERBATIM text into the stash buffer */
text = dStrndup(buf + token_start, buf_index - token_start); const std::string text{ buf + token_start, buf + buf_index };
dStr_append(html->Stash, text); html->Stash+= text.c_str();
dFree(text);
token_start = buf_index; token_start = buf_index;
break; break;
} else } else

View File

@ -196,7 +196,7 @@ public: //BUG: for now everything is public
int InFlags; /**< tracks which elements we are in */ int InFlags; /**< tracks which elements we are in */
Dstr *Stash; std::string Stash;
bool StashSpace; bool StashSpace;
int pre_column; /**< current column, used in PRE tags with tabs */ int pre_column; /**< current column, used in PRE tags with tabs */