mirror of
https://github.com/RGBCube/serenity
synced 2025-05-20 06:15:06 +00:00
LibHTML: Collapse all-whitespace LayoutText into a single ' ' char.
This commit is contained in:
parent
8a0e21b22b
commit
0522a8f71c
3 changed files with 21 additions and 1 deletions
|
@ -1,4 +1,5 @@
|
|||
#include <LibHTML/LayoutText.h>
|
||||
#include <ctype.h>
|
||||
|
||||
LayoutText::LayoutText(const Text& text)
|
||||
: LayoutNode(&text)
|
||||
|
@ -8,3 +9,20 @@ LayoutText::LayoutText(const Text& text)
|
|||
LayoutText::~LayoutText()
|
||||
{
|
||||
}
|
||||
|
||||
static bool is_all_whitespace(const String& string)
|
||||
{
|
||||
for (int i = 0; i < string.length(); ++i) {
|
||||
if (!isspace(string[i]))
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
const String& LayoutText::text() const
|
||||
{
|
||||
static String one_space = " ";
|
||||
if (is_all_whitespace(node().data()))
|
||||
return one_space;
|
||||
return node().data();
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue