Added helper methods for writing numbers into HTMLBuilder.

This commit is contained in:
Relintai 2021-11-01 22:47:48 +01:00
parent aaa48e390b
commit 7fecc3e9ff
2 changed files with 49 additions and 6 deletions

View File

@ -1731,6 +1731,42 @@ HTMLBuilder *HTMLBuilder::w(const String &val) {
return this;
}
HTMLBuilder *HTMLBuilder::wn(const double val, int p_decimals) {
write_tag();
result += String::num(val, p_decimals);
return this;
}
HTMLBuilder *HTMLBuilder::wns(const double val) {
write_tag();
result += String::num_scientific(val);
return this;
}
HTMLBuilder *HTMLBuilder::wr(const double val, const bool p_trailing) {
write_tag();
result += String::num_real(val, p_trailing);
return this;
}
HTMLBuilder *HTMLBuilder::wi(const int64_t val, const int base, const bool capitalize_hex) {
write_tag();
result += String::num_int64(val, base, capitalize_hex);
return this;
}
HTMLBuilder *HTMLBuilder::wui(const uint64_t val, const int base, const bool capitalize_hex) {
write_tag();
result += String::num_uint64(val, base, capitalize_hex);
return this;
}
//TODO!
HTMLBuilder *HTMLBuilder::we(const String &val) {
printf("HTMLBuilder::write_excaped NYI!");

View File

@ -177,9 +177,9 @@ public:
HTMLTag *wbr();
//closing tags c prefix means close
//Note simple tags should not have these like <br>
//Note that I might have a few that shouldn't be here, those will be removed as I find them
HTMLBuilder *ca();
//Note simple tags should not have these like <br>
//Note that I might have a few that shouldn't be here, those will be removed as I find them
HTMLBuilder *ca();
HTMLBuilder *cabbr();
HTMLBuilder *cacronym();
HTMLBuilder *caddress();
@ -215,7 +215,7 @@ public:
HTMLBuilder *cdiv();
HTMLBuilder *cdl();
HTMLBuilder *cdt();
HTMLBuilder *cem();
HTMLBuilder *cembed();
HTMLBuilder *cfieldset();
@ -308,9 +308,16 @@ public:
void f();
//write
//write
HTMLBuilder *w(const String &val);
//write_escaped
HTMLBuilder *wn(const double val, int p_decimals = -1);
HTMLBuilder *wns(const double val);
HTMLBuilder *wr(const double val, const bool p_trailing = true);
HTMLBuilder *wi(const int64_t val, const int base = 10, const bool capitalize_hex = false);
HTMLBuilder *wui(const uint64_t val, const int base = 10, const bool capitalize_hex = false);
//write_escaped
HTMLBuilder *we(const String &val);
HTMLBuilder *write_tag();