This source file includes following definitions.
- convertHTMLTextToInterchangeFormat
#include "config.h"
#include "core/editing/HTMLInterchange.h"
#include "core/dom/Text.h"
#include "core/editing/htmlediting.h"
#include "core/rendering/RenderObject.h"
#include "wtf/text/StringBuilder.h"
#include "wtf/unicode/CharacterNames.h"
namespace WebCore {
String convertHTMLTextToInterchangeFormat(const String& in, const Text& node)
{
if (node.renderer() && node.renderer()->style()->preserveNewline())
return in;
const char convertedSpaceString[] = "<span class=\"" AppleConvertedSpace "\">\xA0</span>";
COMPILE_ASSERT((static_cast<unsigned char>('\xA0') == noBreakSpace), ConvertedSpaceStringSpaceIsNoBreakSpace);
StringBuilder s;
unsigned i = 0;
unsigned consumed = 0;
while (i < in.length()) {
consumed = 1;
if (isCollapsibleWhitespace(in[i])) {
unsigned j = i + 1;
while (j < in.length() && isCollapsibleWhitespace(in[j]))
j++;
unsigned count = j - i;
consumed = count;
while (count) {
unsigned add = count % 3;
switch (add) {
case 0:
s.appendLiteral(convertedSpaceString);
s.append(' ');
s.appendLiteral(convertedSpaceString);
add = 3;
break;
case 1:
if (i == 0 || i + 1 == in.length())
s.appendLiteral(convertedSpaceString);
else
s.append(' ');
break;
case 2:
if (i == 0) {
s.appendLiteral(convertedSpaceString);
s.append(' ');
} else if (i + 2 == in.length()) {
s.appendLiteral(convertedSpaceString);
s.appendLiteral(convertedSpaceString);
} else {
s.appendLiteral(convertedSpaceString);
s.append(' ');
}
break;
}
count -= add;
}
} else
s.append(in[i]);
i += consumed;
}
return s.toString();
}
}