14.3 round 1: print sizes tie to even; one trim of Foundation's .whitespaces, U+200B included, for New Canvas, validDimension and hex
This commit is contained in:
8 files changed
+38
-26
No files matched your search
@@ -20,14 +20,8 @@ QString PaletteColor::hex() const
|
||||
|
||||
std::optional<PaletteColor> PaletteColor::fromHex(const QString &hex)
|
||||
{
|
||||
// Swift trims spaces and tabs, not line breaks.
|
||||
const auto blank = [](QChar character) { return character.category() == QChar::Separator_Space || character == u'\t'; };
|
||||
qsizetype start = 0, end = hex.size();
|
||||
while (start < end && blank(hex.at(start)))
|
||||
++start;
|
||||
while (end > start && blank(hex.at(end - 1)))
|
||||
--end;
|
||||
QString text = hex.mid(start, end - start);
|
||||
// Swift trims .whitespaces, never line breaks.
|
||||
QString text = trimmedWhitespaces(hex);
|
||||
if (text.startsWith(u'#'))
|
||||
text.remove(0, 1);
|
||||
if (text.size() == 3)
|
||||
|
||||
@@ -59,7 +59,7 @@ namespace {
|
||||
// Swift's CharacterSet.whitespaces: category Zs and tab.
|
||||
bool isWhitespace(QChar character)
|
||||
{
|
||||
return character == u'\t' || character.category() == QChar::Separator_Space;
|
||||
return character == u'\t' || character == QChar(0x200B) || character.category() == QChar::Separator_Space;
|
||||
}
|
||||
|
||||
// Swift's Int(String): optional sign, then ASCII digits only.
|
||||
@@ -78,14 +78,19 @@ std::optional<int> wholeNumber(QStringView text)
|
||||
}
|
||||
}
|
||||
|
||||
QString trimmedWhitespaces(const QString &text)
|
||||
{
|
||||
qsizetype first = 0, last = text.size();
|
||||
while (first < last && isWhitespace(text[first]))
|
||||
++first;
|
||||
while (last > first && isWhitespace(text[last - 1]))
|
||||
--last;
|
||||
return text.mid(first, last - first);
|
||||
}
|
||||
|
||||
std::optional<int> CanvasDocument::validDimension(const QString &value)
|
||||
{
|
||||
qsizetype first = 0, last = value.size();
|
||||
while (first < last && isWhitespace(value[first]))
|
||||
++first;
|
||||
while (last > first && isWhitespace(value[last - 1]))
|
||||
--last;
|
||||
const std::optional<int> number = wholeNumber(QStringView(value).mid(first, last - first));
|
||||
const std::optional<int> number = wholeNumber(trimmedWhitespaces(value));
|
||||
if (!number || *number < 1 || *number > DocumentLimits::maxSide)
|
||||
return std::nullopt;
|
||||
return number;
|
||||
|
||||
@@ -90,5 +90,7 @@ enum class NavigationTool {
|
||||
|
||||
// The rail's tooltip: the tool's name and its key.
|
||||
QString label(NavigationTool tool);
|
||||
// Swift's trim of .whitespaces: tab, space separators, U+200B.
|
||||
QString trimmedWhitespaces(const QString &text);
|
||||
bool isBrushTool(NavigationTool tool);
|
||||
bool isSelectionTool(NavigationTool tool);
|
||||
Reference in new issue
Block a user