diff --git a/src/form.cc b/src/form.cc index a4251e3..aaadaea 100644 --- a/src/form.cc +++ b/src/form.cc @@ -674,7 +674,6 @@ void Html_tag_content_textarea(DilloHtml *html, const char *tag, int tagsize) */ void Html_tag_close_textarea(DilloHtml *html) { - char *str; int i; if (html->InFlags & IN_TEXTAREA && !S_TOP(html)->display_none) { @@ -696,11 +695,11 @@ void Html_tag_close_textarea(DilloHtml *html) } /* The HTML3.2 spec says it can have "text and character entities". */ - str = a_Html_parse_entities(html, html->Stash->str, html->Stash->len); + auto str = a_Html_parse_entities(html, html->Stash->str, html->Stash->len); auto input = Html_get_current_input(*html); if (input) { input->init_str = str; - ((MultiLineTextResource *)input->embed->getResource ())->setText(str); + ((MultiLineTextResource *)input->embed->getResource ())->setText(str.c_str()); } } diff --git a/src/html.cc b/src/html.cc index 9ed1519..2f96140 100644 --- a/src/html.cc +++ b/src/html.cc @@ -1036,20 +1036,20 @@ static const char *Html_parse_entity(DilloHtml *html, const char *token, * Parse all the entities in a token. Takes the token and its length, and * returns a newly allocated string. */ -char *a_Html_parse_entities(DilloHtml *html, const char *token, int toksize) +std::string +a_Html_parse_entities(DilloHtml *html, const char *token, int toksize) { const char *esc_set = "&"; int i, s, entsize; - char *str; s = strcspn(token, esc_set); if (s >= toksize) { /* no ampersands */ - str = dStrndup(token, toksize); + return std::string{ token, token + toksize }; } else { - Dstr *ds = dStr_sized_new(toksize); - - dStr_append_l(ds, token, s); + std::string ds; + ds+= token; + ds+= s; for (i = s; i < toksize; i++) { const char *entstr; @@ -1058,16 +1058,14 @@ char *a_Html_parse_entities(DilloHtml *html, const char *token, int toksize) if (token[i] == '&' && (entstr = Html_parse_entity(html, token+i, toksize-i, &entsize, is_attr))) { - dStr_append(ds, entstr); + ds+= entstr; i += entsize-1; } else { - dStr_append_c(ds, token[i]); + ds+= token[i]; } } - str = ds->str; - dStr_free(ds, 0); + return ds; } - return str; } /** @@ -1185,7 +1183,6 @@ static void Html_process_space(DilloHtml *html, const char *space, static void Html_process_word(DilloHtml *html, const char *word, int size) { int i, j, start; - char *Pword; DilloHtmlParseMode parse_mode = S_TOP(html)->parse_mode; if (S_TOP(html)->display_none) @@ -1201,9 +1198,8 @@ static void Html_process_word(DilloHtml *html, const char *word, int size) dStr_append_c(html->Stash, ' '); html->StashSpace = false; } - Pword = a_Html_parse_entities(html, word, size); - dStr_append(html->Stash, Pword); - dFree(Pword); + const std::string Pword= a_Html_parse_entities(html, word, size); + dStr_append(html->Stash, Pword.c_str()); } else if (parse_mode == DILLO_HTML_PARSE_MODE_VERBATIM) { /* word goes in untouched, it is not processed here. */ @@ -1216,23 +1212,21 @@ static void Html_process_word(DilloHtml *html, const char *word, int size) } else if (parse_mode == DILLO_HTML_PARSE_MODE_PRE) { /* all this overhead is to catch white-space entities */ - Pword = a_Html_parse_entities(html, word, size); + std::string Pword = a_Html_parse_entities(html, word, size); for (start = i = 0; Pword[i]; start = i) if (isspace(Pword[i])) { while (Pword[++i] && isspace(Pword[i])) ; - Html_process_space(html, Pword + start, i - start); + Html_process_space(html, Pword.c_str() + start, i - start); } else { while (Pword[++i] && !isspace(Pword[i])) ; - HT2TB(html)->addText(Pword + start, i - start, html->wordStyle ()); + HT2TB(html)->addText(Pword.c_str() + start, i - start, html->wordStyle ()); html->pre_column += i - start; html->PreFirstChar = false; } - dFree(Pword); - } else { const char *word2, *beyond_word2; - Pword = NULL; + std::string Pword; if (!memchr(word,'&', size)) { /* No entities */ word2 = word; @@ -1250,7 +1244,7 @@ static void Html_process_word(DilloHtml *html, const char *word, int size) ; } } - word2 = Pword; + word2 = Pword.c_str(); beyond_word2 = word2 + strlen(word2); } for (start = i = 0; word2[i]; start = i) { @@ -1275,8 +1269,6 @@ static void Html_process_word(DilloHtml *html, const char *word, int size) HT2TB(html)->addText(word2 + start, i - start, html->wordStyle ()); } } - if (Pword == word2) - dFree(Pword); } } @@ -1978,7 +1970,6 @@ static void Html_tag_content_br(DilloHtml *html, const char *tag, int tagsize) static void Html_tag_open_font(DilloHtml *html, const char *tag, int tagsize) { const char *attrbuf; - char *fontFamily = NULL; int32_t color; if ((attrbuf = a_Html_get_attr(html, tag, tagsize, "color"))) { diff --git a/src/html_common.hh b/src/html_common.hh index 4bdf5ed..0b375be 100644 --- a/src/html_common.hh +++ b/src/html_common.hh @@ -289,7 +289,7 @@ std::unique_ptr< DilloUrl > a_Html_url_new(DilloHtml *html, void a_Html_common_image_attrs(DilloHtml *html, const char *tag, int tagsize); std::shared_ptr< DilloImage > a_Html_image_new(DilloHtml *html, const char *tag, int tagsize); -char *a_Html_parse_entities(DilloHtml *html, const char *token, int toksize); +std::string a_Html_parse_entities(DilloHtml *html, const char *token, int toksize); void a_Html_pop_tag(DilloHtml *html, int TagIdx); void a_Html_stash_init(DilloHtml *html); int32_t a_Html_color_parse(DilloHtml *html, const char *str,