HTML Object nearly RAII complete.
This commit is contained in:
52
src/html.cc
52
src/html.cc
@ -505,8 +505,6 @@ DilloHtml::DilloHtml(BrowserWindow *p_bw, const DilloUrl *url,
|
|||||||
|
|
||||||
Num_HTML = Num_HEAD = Num_BODY = Num_TITLE = 0;
|
Num_HTML = Num_HEAD = Num_BODY = Num_TITLE = 0;
|
||||||
|
|
||||||
attr_data = dStr_sized_new(1024);
|
|
||||||
|
|
||||||
non_css_link_color = -1;
|
non_css_link_color = -1;
|
||||||
non_css_visited_color = -1;
|
non_css_visited_color = -1;
|
||||||
visited_color = -1;
|
visited_color = -1;
|
||||||
@ -542,8 +540,6 @@ DilloHtml::~DilloHtml()
|
|||||||
{
|
{
|
||||||
_MSG("::~DilloHtml(this=%p)\n", this);
|
_MSG("::~DilloHtml(this=%p)\n", this);
|
||||||
|
|
||||||
freeParseData();
|
|
||||||
|
|
||||||
a_Bw_remove_doc(bw, this);
|
a_Bw_remove_doc(bw, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -592,14 +588,6 @@ int DilloHtml::getCurrLineNumber()
|
|||||||
return line;
|
return line;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Free parsing data.
|
|
||||||
*/
|
|
||||||
void DilloHtml::freeParseData()
|
|
||||||
{
|
|
||||||
dStr_free(attr_data, TRUE);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Finish parsing a HTML page. Close the parser and close the client.
|
* Finish parsing a HTML page. Close the parser and close the client.
|
||||||
* The class is not deleted here, it remains until the widget is destroyed.
|
* The class is not deleted here, it remains until the widget is destroyed.
|
||||||
@ -2577,20 +2565,20 @@ static const char* Html_get_javascript_link(DilloHtml *html)
|
|||||||
{
|
{
|
||||||
size_t i;
|
size_t i;
|
||||||
char ch, *p1, *p2;
|
char ch, *p1, *p2;
|
||||||
Dstr *Buf = html->attr_data;
|
std::string &Buf = html->attr_data;
|
||||||
|
|
||||||
if (dStrnAsciiCasecmp("javascript", Buf->str, 10) == 0) {
|
if (dStrnAsciiCasecmp("javascript", Buf.c_str(), 10) == 0) {
|
||||||
i = strcspn(Buf->str, "'\"");
|
i = strcspn(Buf.c_str(), "'\"");
|
||||||
ch = Buf->str[i];
|
ch = Buf.at( i );
|
||||||
if ((ch == '"' || ch == '\'') &&
|
if ((ch == '"' || ch == '\'') &&
|
||||||
(p2 = strchr(Buf->str + i + 1 , ch))) {
|
(p2 = strchr(Buf.data() + i + 1 , ch))) {
|
||||||
p1 = Buf->str + i;
|
p1 = Buf.data() + i;
|
||||||
BUG_MSG("Link depends on javascript().");
|
BUG_MSG("Link depends on javascript().");
|
||||||
dStr_truncate(Buf, p2 - Buf->str);
|
while( Buf.size() > ( p2 - Buf.c_str() ) ) Buf.pop_back();
|
||||||
dStr_erase(Buf, 0, p1 - Buf->str + 1);
|
Buf.erase( 0, p1 - Buf.c_str() + 1 );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return Buf->str;
|
return Buf.c_str();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -4085,12 +4073,12 @@ static const char *Html_get_attr2(DilloHtml *html,
|
|||||||
int tag_parsing_flags)
|
int tag_parsing_flags)
|
||||||
{
|
{
|
||||||
int i, entsize, Found = 0, delimiter = 0, attr_pos = 0;
|
int i, entsize, Found = 0, delimiter = 0, attr_pos = 0;
|
||||||
Dstr *Buf = html->attr_data;
|
std::string &Buf = html->attr_data;
|
||||||
DilloHtmlTagParsingState state = SEEK_ATTR_START;
|
DilloHtmlTagParsingState state = SEEK_ATTR_START;
|
||||||
|
|
||||||
dReturn_val_if_fail(*attrname, NULL);
|
dReturn_val_if_fail(*attrname, NULL);
|
||||||
|
|
||||||
dStr_truncate(Buf, 0);
|
Buf.clear();
|
||||||
|
|
||||||
for (i = 1; i < tagsize; ++i) {
|
for (i = 1; i < tagsize; ++i) {
|
||||||
switch (state) {
|
switch (state) {
|
||||||
@ -4148,17 +4136,17 @@ static const char *Html_get_attr2(DilloHtml *html,
|
|||||||
|
|
||||||
if ((entstr = Html_parse_entity(html, tag+i, tagsize-i, &entsize,
|
if ((entstr = Html_parse_entity(html, tag+i, tagsize-i, &entsize,
|
||||||
is_attr))) {
|
is_attr))) {
|
||||||
dStr_append(Buf, entstr);
|
Buf+= entstr;
|
||||||
i += entsize-1;
|
i += entsize-1;
|
||||||
} else {
|
} else {
|
||||||
dStr_append_c(Buf, tag[i]);
|
Buf+= tag[i];
|
||||||
}
|
}
|
||||||
} else if (tag[i] == '\r' || tag[i] == '\t') {
|
} else if (tag[i] == '\r' || tag[i] == '\t') {
|
||||||
dStr_append_c(Buf, ' ');
|
Buf+= ' ';
|
||||||
} else if (tag[i] == '\n') {
|
} else if (tag[i] == '\n') {
|
||||||
/* ignore */
|
/* ignore */
|
||||||
} else {
|
} else {
|
||||||
dStr_append_c(Buf, tag[i]);
|
Buf+= tag[i];
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -4169,13 +4157,13 @@ static const char *Html_get_attr2(DilloHtml *html,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (tag_parsing_flags & HTML_LeftTrim)
|
if (tag_parsing_flags & HTML_LeftTrim)
|
||||||
while (isspace(Buf->str[0]))
|
while (isspace(Buf.front()))
|
||||||
dStr_erase(Buf, 0, 1);
|
Buf.erase( 0, 1 );
|
||||||
if (tag_parsing_flags & HTML_RightTrim)
|
if (tag_parsing_flags & HTML_RightTrim)
|
||||||
while (Buf->len && isspace(Buf->str[Buf->len - 1]))
|
while (Buf.size() && isspace( Buf.back() ))
|
||||||
dStr_truncate(Buf, Buf->len - 1);
|
Buf.pop_back();
|
||||||
|
|
||||||
return (Found) ? Buf->str : NULL;
|
return (Found) ? Buf.c_str() : NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -214,7 +214,7 @@ public: //BUG: for now everything is public
|
|||||||
* ATM they're used as three state flags {0,1,>1} */
|
* ATM they're used as three state flags {0,1,>1} */
|
||||||
uchar_t Num_HTML, Num_HEAD, Num_BODY, Num_TITLE;
|
uchar_t Num_HTML, Num_HEAD, Num_BODY, Num_TITLE;
|
||||||
|
|
||||||
Dstr *attr_data; /**< Buffer for attribute value */
|
std::string attr_data; /**< Buffer for attribute value */
|
||||||
|
|
||||||
int32_t non_css_link_color; /**< as provided by link attribute in BODY */
|
int32_t non_css_link_color; /**< as provided by link attribute in BODY */
|
||||||
int32_t non_css_visited_color; /**< as provided by vlink attribute in BODY */
|
int32_t non_css_visited_color; /**< as provided by vlink attribute in BODY */
|
||||||
@ -230,7 +230,6 @@ public: //BUG: for now everything is public
|
|||||||
dw::ImageMapsList maps;
|
dw::ImageMapsList maps;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void freeParseData();
|
|
||||||
void initDw(); /* Used by the constructor */
|
void initDw(); /* Used by the constructor */
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|||||||
Reference in New Issue
Block a user