summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorKarsten Heimrich <karsten.heimrich@qt.io>2020-07-01 21:18:47 +0200
committerKarsten Heimrich <karsten.heimrich@qt.io>2020-07-02 23:08:17 +0200
commit98f6f96c1730d087bc2eee43f6a1a23378c1b4f4 (patch)
tree05a578a04677ef5bdf69fec0a27a8ee98e4b02ce /src
parentec1ffeaf47bb9ca41812b7c89540247eff4dc20f (diff)
downloadqtsvg-98f6f96c1730d087bc2eee43f6a1a23378c1b4f4.tar.gz
Port QtSvg from QStringRef to QStringView
Task-number: QTBUG-84319 Change-Id: I6358030d1d7e0e023453edea10da535707320ea4 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src')
-rw-r--r--src/svg/qsvggenerator.cpp2
-rw-r--r--src/svg/qsvghandler.cpp308
-rw-r--r--src/svg/qsvghandler_p.h4
3 files changed, 138 insertions, 176 deletions
diff --git a/src/svg/qsvggenerator.cpp b/src/svg/qsvggenerator.cpp
index 2a56e8a..ce2780e 100644
--- a/src/svg/qsvggenerator.cpp
+++ b/src/svg/qsvggenerator.cpp
@@ -238,7 +238,7 @@ public:
QString savePatternBrush(const QString &color, const QBrush &brush)
{
- QString patternId = QString(QStringLiteral("fillpattern%1_")).arg(brush.style()) + color.midRef(1);
+ QString patternId = QString(QStringLiteral("fillpattern%1_")).arg(brush.style()) + QStringView{color}.mid(1);
if (!d_func()->savedPatternBrushes.contains(patternId)) {
QString maskId = savePatternMask(brush.style());
QString geo(QStringLiteral("x=\"0\" y=\"0\" width=\"8\" height=\"8\""));
diff --git a/src/svg/qsvghandler.cpp b/src/svg/qsvghandler.cpp
index 4895cbd..e65c063 100644
--- a/src/svg/qsvghandler.cpp
+++ b/src/svg/qsvghandler.cpp
@@ -177,7 +177,7 @@ bool qsvg_get_hex_rgb(const QChar *str, int len, QRgb *rgb)
// ======== end of qcolor_p duplicate
-static bool parsePathDataFast(const QStringRef &data, QPainterPath &path);
+static bool parsePathDataFast(QStringView data, QPainterPath &path);
static inline QString someId(const QXmlStreamAttributes &attributes)
{
@@ -193,34 +193,34 @@ struct QSvgAttributes
QString id;
- QStringRef color;
- QStringRef colorOpacity;
- QStringRef fill;
- QStringRef fillRule;
- QStringRef fillOpacity;
- QStringRef stroke;
- QStringRef strokeDashArray;
- QStringRef strokeDashOffset;
- QStringRef strokeLineCap;
- QStringRef strokeLineJoin;
- QStringRef strokeMiterLimit;
- QStringRef strokeOpacity;
- QStringRef strokeWidth;
- QStringRef vectorEffect;
- QStringRef fontFamily;
- QStringRef fontSize;
- QStringRef fontStyle;
- QStringRef fontWeight;
- QStringRef fontVariant;
- QStringRef textAnchor;
- QStringRef transform;
- QStringRef visibility;
- QStringRef opacity;
- QStringRef compOp;
- QStringRef display;
- QStringRef offset;
- QStringRef stopColor;
- QStringRef stopOpacity;
+ QStringView color;
+ QStringView colorOpacity;
+ QStringView fill;
+ QStringView fillRule;
+ QStringView fillOpacity;
+ QStringView stroke;
+ QStringView strokeDashArray;
+ QStringView strokeDashOffset;
+ QStringView strokeLineCap;
+ QStringView strokeLineJoin;
+ QStringView strokeMiterLimit;
+ QStringView strokeOpacity;
+ QStringView strokeWidth;
+ QStringView vectorEffect;
+ QStringView fontFamily;
+ QStringView fontSize;
+ QStringView fontStyle;
+ QStringView fontWeight;
+ QStringView fontVariant;
+ QStringView textAnchor;
+ QStringView transform;
+ QStringView visibility;
+ QStringView opacity;
+ QStringView compOp;
+ QStringView display;
+ QStringView offset;
+ QStringView stopColor;
+ QStringView stopOpacity;
#ifndef QT_NO_CSSPARSER
QList<QSvgCssAttribute> m_cssAttributes;
@@ -230,13 +230,13 @@ struct QSvgAttributes
QSvgAttributes::QSvgAttributes(const QXmlStreamAttributes &xmlAttributes, QSvgHandler *handler)
{
#ifndef QT_NO_CSSPARSER
- QStringRef style = xmlAttributes.value(QLatin1String("style"));
+ QStringView style = xmlAttributes.value(QLatin1String("style"));
if (!style.isEmpty()) {
handler->parseCSStoXMLAttrs(style.toString(), &m_cssAttributes);
for (int j = 0; j < m_cssAttributes.count(); ++j) {
const QSvgCssAttribute &attribute = m_cssAttributes.at(j);
- QStringRef name(&attribute.name);
- QStringRef value(&attribute.value);
+ QStringView name = attribute.name;
+ QStringView value = attribute.value;
if (name.isEmpty())
continue;
@@ -283,8 +283,8 @@ QSvgAttributes::QSvgAttributes(const QXmlStreamAttributes &xmlAttributes, QSvgHa
break;
case 's':
- if (name.length() > 5 && QStringRef(name.string(), name.position() + 1, 5) == QLatin1String("troke")) {
- QStringRef strokeRef(name.string(), name.position() + 6, name.length() - 6);
+ if (name.length() > 5 && name.mid(1, 5) == QLatin1String("troke")) {
+ QStringView strokeRef = name.mid(6, name.length() - 6);
if (strokeRef.isEmpty())
stroke = value;
else if (strokeRef == QLatin1String("-dasharray"))
@@ -333,10 +333,10 @@ QSvgAttributes::QSvgAttributes(const QXmlStreamAttributes &xmlAttributes, QSvgHa
for (int i = 0; i < xmlAttributes.count(); ++i) {
const QXmlStreamAttribute &attribute = xmlAttributes.at(i);
- QStringRef name = attribute.qualifiedName();
+ QStringView name = attribute.qualifiedName();
if (name.isEmpty())
continue;
- QStringRef value = attribute.value();
+ QStringView value = attribute.value();
switch (name.at(0).unicode()) {
@@ -386,8 +386,8 @@ QSvgAttributes::QSvgAttributes(const QXmlStreamAttributes &xmlAttributes, QSvgHa
break;
case 's':
- if (name.length() > 5 && QStringRef(name.string(), name.position() + 1, 5) == QLatin1String("troke")) {
- QStringRef strokeRef(name.string(), name.position() + 6, name.length() - 6);
+ if (name.length() > 5 && name.mid(1, 5) == QLatin1String("troke")) {
+ QStringView strokeRef = name.mid(6, name.length() - 6);
if (strokeRef.isEmpty())
stroke = value;
else if (strokeRef == QLatin1String("-dasharray"))
@@ -676,23 +676,13 @@ static qreal toDouble(const QChar *&str)
return val;
}
-static qreal toDouble(const QString &str, bool *ok = NULL)
-{
- const QChar *c = str.constData();
- qreal res = toDouble(c);
- if (ok) {
- *ok = ((*c) == QLatin1Char('\0'));
- }
- return res;
-}
-static qreal toDouble(const QStringRef &str, bool *ok = NULL)
+static qreal toDouble(QStringView str, bool *ok = NULL)
{
const QChar *c = str.constData();
- qreal res = toDouble(c);
- if (ok) {
+ qreal res = (c == nullptr ? qreal{} : toDouble(c));
+ if (ok)
*ok = (c == (str.constData() + str.length()));
- }
return res;
}
@@ -806,35 +796,13 @@ static QString idFromUrl(const QString &url)
return id;
}
-static inline QStringRef trimRef(const QStringRef &str)
-{
- if (str.isEmpty())
- return QStringRef();
- const QChar *s = str.string()->constData() + str.position();
- int end = str.length() - 1;
- if (!s[0].isSpace() && !s[end].isSpace())
- return str;
-
- int start = 0;
- while (start<=end && s[start].isSpace()) // skip white space from start
- start++;
- if (start <= end) { // only white space
- while (s[end].isSpace()) // skip white space from end
- end--;
- }
- int l = end - start + 1;
- if (l <= 0)
- return QStringRef();
- return QStringRef(str.string(), str.position() + start, l);
-}
-
/**
- * returns true when successfuly set the color. false signifies
+ * returns true when successfully set the color. false signifies
* that the color should be inherited
*/
-static bool resolveColor(const QStringRef &colorStr, QColor &color, QSvgHandler *handler)
+static bool resolveColor(QStringView colorStr, QColor &color, QSvgHandler *handler)
{
- QStringRef colorStrTr = trimRef(colorStr);
+ QStringView colorStrTr = colorStr.trimmed();
if (colorStrTr.isEmpty())
return false;
@@ -845,7 +813,7 @@ static bool resolveColor(const QStringRef &colorStr, QColor &color, QSvgHandler
// #rrggbb is very very common, so let's tackle it here
// rather than falling back to QColor
QRgb rgb;
- bool ok = qsvg_get_hex_rgb(colorStrTr.unicode(), colorStrTr.length(), &rgb);
+ bool ok = qsvg_get_hex_rgb(colorStrTr.constData(), colorStrTr.length(), &rgb);
if (ok)
color.setRgb(rgb);
return ok;
@@ -856,7 +824,7 @@ static bool resolveColor(const QStringRef &colorStr, QColor &color, QSvgHandler
{
// starts with "rgb(", ends with ")" and consists of at least 7 characters "rgb(,,)"
if (colorStrTr.length() >= 7 && colorStrTr.at(colorStrTr.length() - 1) == QLatin1Char(')')
- && QStringRef(colorStrTr.string(), colorStrTr.position(), 4) == QLatin1String("rgb(")) {
+ && colorStrTr.mid(0, 4) == QLatin1String("rgb(")) {
const QChar *s = colorStrTr.constData() + 4;
QList<qreal> compo = parseNumbersList(s);
//1 means that it failed after reaching non-parsable
@@ -897,7 +865,7 @@ static bool resolveColor(const QStringRef &colorStr, QColor &color, QSvgHandler
return color.isValid();
}
-static bool constructColor(const QStringRef &colorStr, const QStringRef &opacity,
+static bool constructColor(QStringView colorStr, QStringView opacity,
QColor &color, QSvgHandler *handler)
{
if (!resolveColor(colorStr, color, handler))
@@ -912,11 +880,10 @@ static bool constructColor(const QStringRef &colorStr, const QStringRef &opacity
return true;
}
-template <class String> // QString/QStringRef
-static qreal parseLength(const String &str, QSvgHandler::LengthType &type,
+static qreal parseLength(QStringView str, QSvgHandler::LengthType &type,
QSvgHandler *handler, bool *ok = NULL)
{
- String numStr = str.trimmed();
+ QStringView numStr = str.trimmed();
if (numStr.endsWith(QLatin1Char('%'))) {
numStr.chop(1);
@@ -948,10 +915,10 @@ static qreal parseLength(const String &str, QSvgHandler::LengthType &type,
return len;
}
-static inline qreal convertToNumber(const QStringRef &str, QSvgHandler *handler, bool *ok = NULL)
+static inline qreal convertToNumber(QStringView str, QSvgHandler *handler, bool *ok = NULL)
{
QSvgHandler::LengthType type;
- qreal num = parseLength(str, type, handler, ok);
+ qreal num = parseLength(str.toString(), type, handler, ok);
if (type == QSvgHandler::LT_PERCENT) {
num = num/100.0;
}
@@ -960,9 +927,9 @@ static inline qreal convertToNumber(const QStringRef &str, QSvgHandler *handler,
static bool createSvgGlyph(QSvgFont *font, const QXmlStreamAttributes &attributes)
{
- QStringRef uncStr = attributes.value(QLatin1String("unicode"));
- QStringRef havStr = attributes.value(QLatin1String("horiz-adv-x"));
- QStringRef pathStr = attributes.value(QLatin1String("d"));
+ QStringView uncStr = attributes.value(QLatin1String("unicode"));
+ QStringView havStr = attributes.value(QLatin1String("horiz-adv-x"));
+ QStringView pathStr = attributes.value(QLatin1String("d"));
QChar unicode = (uncStr.isEmpty()) ? 0 : uncStr.at(0);
qreal havx = (havStr.isEmpty()) ? -1 : toDouble(havStr);
@@ -1038,17 +1005,15 @@ static void parseBrush(QSvgNode *node,
prop->setFillRule(Qt::WindingFill);
}
- //fill-opacity atttribute handling
+ //fill-opacity attribute handling
if (!attributes.fillOpacity.isEmpty() && attributes.fillOpacity != QT_INHERIT) {
prop->setFillOpacity(qMin(qreal(1.0), qMax(qreal(0.0), toDouble(attributes.fillOpacity))));
}
//fill attribute handling
if ((!attributes.fill.isEmpty()) && (attributes.fill != QT_INHERIT) ) {
- if (attributes.fill.length() > 3 &&
- QStringRef(attributes.fill.string(), attributes.fill.position(), 3) == QLatin1String("url")) {
- QStringRef urlRef(attributes.fill.string(), attributes.fill.position() + 3, attributes.fill.length() - 3);
- QString value = urlRef.toString();
+ if (attributes.fill.length() > 3 && attributes.fill.mid(0, 3) == QLatin1String("url")) {
+ QString value = attributes.fill.mid(3, attributes.fill.length() - 3).toString();
QSvgStyleProperty *style = styleFromUrl(node, value);
if (style) {
if (style->type() == QSvgStyleProperty::SOLID_COLOR || style->type() == QSvgStyleProperty::GRADIENT)
@@ -1072,7 +1037,7 @@ static void parseBrush(QSvgNode *node,
-static QTransform parseTransformationMatrix(const QStringRef &value)
+static QTransform parseTransformationMatrix(QStringView value)
{
if (value.isEmpty())
return QTransform();
@@ -1218,10 +1183,8 @@ static void parsePen(QSvgNode *node,
//stroke attribute handling
if ((!attributes.stroke.isEmpty()) && (attributes.stroke != QT_INHERIT) ) {
- if (attributes.stroke.length() > 3 &&
- QStringRef(attributes.stroke.string(), attributes.stroke.position(), 3) == QLatin1String("url")) {
- QStringRef urlRef(attributes.stroke.string(), attributes.stroke.position() + 3, attributes.stroke.length() - 3);
- QString value = urlRef.toString();
+ if (attributes.stroke.length() > 3 && attributes.stroke.mid(0, 3) == QLatin1String("url")) {
+ QString value = attributes.stroke.mid(3, attributes.stroke.length() - 3).toString();
QSvgStyleProperty *style = styleFromUrl(node, value);
if (style) {
if (style->type() == QSvgStyleProperty::SOLID_COLOR || style->type() == QSvgStyleProperty::GRADIENT)
@@ -1313,7 +1276,7 @@ static const qreal sizeTable[] =
Q_STATIC_ASSERT(sizeof(sizeTable)/sizeof(sizeTable[0]) == FontSizeNone);
-static FontSizeSpec fontSizeSpec(const QStringRef &spec)
+static FontSizeSpec fontSizeSpec(QStringView spec)
{
switch (spec.at(0).unicode()) {
case 'x':
@@ -1442,7 +1405,7 @@ static void parseTransform(QSvgNode *node,
{
if (attributes.transform.isEmpty())
return;
- QTransform matrix = parseTransformationMatrix(trimRef(attributes.transform));
+ QTransform matrix = parseTransformationMatrix(attributes.transform.trimmed());
if (!matrix.isIdentity()) {
node->appendStyleProperty(new QSvgTransformStyle(QTransform(matrix)), attributes.id);
@@ -1603,7 +1566,7 @@ static void pathArc(QPainterPath &path,
}
}
-static bool parsePathDataFast(const QStringRef &dataStr, QPainterPath &path)
+static bool parsePathDataFast(QStringView dataStr, QPainterPath &path)
{
qreal x0 = 0, y0 = 0; // starting point
qreal x = 0, y = 0; // current point
@@ -1618,7 +1581,7 @@ static bool parsePathDataFast(const QStringRef &dataStr, QPainterPath &path)
QChar pathElem = *str;
++str;
QChar endc = *end;
- *const_cast<QChar *>(end) = 0; // parseNumbersArray requires 0-termination that QStringRef cannot guarantee
+ *const_cast<QChar *>(end) = 0; // parseNumbersArray requires 0-termination that QStringView cannot guarantee
QVarLengthArray<qreal, 8> arg;
parseNumbersArray(str, arg);
*const_cast<QChar *>(end) = endc;
@@ -2098,10 +2061,10 @@ static bool parseCoreNode(QSvgNode *node,
for (int i = 0; i < attributes.count(); ++i) {
const QXmlStreamAttribute &attribute = attributes.at(i);
- QStringRef name = attribute.qualifiedName();
+ QStringView name = attribute.qualifiedName();
if (name.isEmpty())
continue;
- QStringRef value = attribute.value();
+ QStringView value = attribute.value();
switch (name.at(0).unicode()) {
case 'c':
if (name == QLatin1String("class"))
@@ -2144,7 +2107,7 @@ static void parseOpacity(QSvgNode *node,
if (attributes.opacity.isEmpty())
return;
- const QStringRef value = attributes.opacity.trimmed();
+ const QStringView value = attributes.opacity.trimmed();
bool ok = false;
qreal op = value.toDouble(&ok);
@@ -2352,8 +2315,8 @@ static bool parseAnimateColorNode(QSvgNode *parent,
const QXmlStreamAttributes &attributes,
QSvgHandler *handler)
{
- QStringRef fromStr = attributes.value(QLatin1String("from"));
- QStringRef toStr = attributes.value(QLatin1String("to"));
+ QStringView fromStr = attributes.value(QLatin1String("from"));
+ QStringView toStr = attributes.value(QLatin1String("to"));
QString valuesStr = attributes.value(QLatin1String("values")).toString();
QString beginStr = attributes.value(QLatin1String("begin")).toString();
QString durStr = attributes.value(QLatin1String("dur")).toString();
@@ -2375,8 +2338,7 @@ static bool parseAnimateColorNode(QSvgNode *parent,
QStringList::const_iterator itr;
for (itr = str.constBegin(); itr != str.constEnd(); ++itr) {
QColor color;
- QString str = *itr;
- resolveColor(QStringRef(&str), color, handler);
+ resolveColor(*itr, color, handler);
colors.append(color);
}
}
@@ -2554,9 +2516,9 @@ static QSvgNode *createCircleNode(QSvgNode *parent,
const QXmlStreamAttributes &attributes,
QSvgHandler *)
{
- const QStringRef cx = attributes.value(QLatin1String("cx"));
- const QStringRef cy = attributes.value(QLatin1String("cy"));
- const QStringRef r = attributes.value(QLatin1String("r"));
+ const QStringView cx = attributes.value(QLatin1String("cx"));
+ const QStringView cy = attributes.value(QLatin1String("cy"));
+ const QStringView r = attributes.value(QLatin1String("r"));
qreal ncx = toDouble(cx);
qreal ncy = toDouble(cy);
qreal nr = toDouble(r);
@@ -2595,10 +2557,10 @@ static QSvgNode *createEllipseNode(QSvgNode *parent,
const QXmlStreamAttributes &attributes,
QSvgHandler *)
{
- const QStringRef cx = attributes.value(QLatin1String("cx"));
- const QStringRef cy = attributes.value(QLatin1String("cy"));
- const QStringRef rx = attributes.value(QLatin1String("rx"));
- const QStringRef ry = attributes.value(QLatin1String("ry"));
+ const QStringView cx = attributes.value(QLatin1String("cx"));
+ const QStringView cy = attributes.value(QLatin1String("cy"));
+ const QStringView rx = attributes.value(QLatin1String("rx"));
+ const QStringView ry = attributes.value(QLatin1String("ry"));
qreal ncx = toDouble(cx);
qreal ncy = toDouble(cy);
qreal nrx = toDouble(rx);
@@ -2613,7 +2575,7 @@ static QSvgStyleProperty *createFontNode(QSvgNode *parent,
const QXmlStreamAttributes &attributes,
QSvgHandler *)
{
- const QStringRef hax = attributes.value(QLatin1String("horiz-adv-x"));
+ const QStringView hax = attributes.value(QLatin1String("horiz-adv-x"));
QString myId = someId(attributes);
qreal horizAdvX = toDouble(hax);
@@ -2646,7 +2608,7 @@ static bool parseFontFaceNode(QSvgStyleProperty *parent,
QSvgFontStyle *style = static_cast<QSvgFontStyle*>(parent);
QSvgFont *font = style->svgFont();
QString name = attributes.value(QLatin1String("font-family")).toString();
- const QStringRef unitsPerEmStr = attributes.value(QLatin1String("units-per-em"));
+ const QStringView unitsPerEmStr = attributes.value(QLatin1String("units-per-em"));
qreal unitsPerEm = toDouble(unitsPerEmStr);
if (!unitsPerEm)
@@ -2752,18 +2714,18 @@ static QSvgNode *createImageNode(QSvgNode *parent,
const QXmlStreamAttributes &attributes,
QSvgHandler *handler)
{
- const QStringRef x = attributes.value(QLatin1String("x"));
- const QStringRef y = attributes.value(QLatin1String("y"));
- const QStringRef width = attributes.value(QLatin1String("width"));
- const QStringRef height = attributes.value(QLatin1String("height"));
+ const QStringView x = attributes.value(QLatin1String("x"));
+ const QStringView y = attributes.value(QLatin1String("y"));
+ const QStringView width = attributes.value(QLatin1String("width"));
+ const QStringView height = attributes.value(QLatin1String("height"));
QString filename = attributes.value(QLatin1String("xlink:href")).toString();
qreal nx = toDouble(x);
qreal ny = toDouble(y);
QSvgHandler::LengthType type;
- qreal nwidth = parseLength(width, type, handler);
+ qreal nwidth = parseLength(width.toString(), type, handler);
nwidth = convertToPixels(nwidth, true, type);
- qreal nheight = parseLength(height, type, handler);
+ qreal nheight = parseLength(height.toString(), type, handler);
nheight = convertToPixels(nheight, false, type);
filename = filename.trimmed();
@@ -2820,10 +2782,10 @@ static QSvgNode *createLineNode(QSvgNode *parent,
const QXmlStreamAttributes &attributes,
QSvgHandler *)
{
- const QStringRef x1 = attributes.value(QLatin1String("x1"));
- const QStringRef y1 = attributes.value(QLatin1String("y1"));
- const QStringRef x2 = attributes.value(QLatin1String("x2"));
- const QStringRef y2 = attributes.value(QLatin1String("y2"));
+ const QStringView x1 = attributes.value(QLatin1String("x1"));
+ const QStringView y1 = attributes.value(QLatin1String("y1"));
+ const QStringView x2 = attributes.value(QLatin1String("x2"));
+ const QStringView y2 = attributes.value(QLatin1String("y2"));
qreal nx1 = toDouble(x1);
qreal ny1 = toDouble(y1);
qreal nx2 = toDouble(x2);
@@ -2841,11 +2803,11 @@ static void parseBaseGradient(QSvgNode *node,
QSvgHandler *handler)
{
QString link = attributes.value(QLatin1String("xlink:href")).toString();
- QStringRef trans = attributes.value(QLatin1String("gradientTransform"));
+ QStringView trans = attributes.value(QLatin1String("gradientTransform"));
QString spread = attributes.value(QLatin1String("spreadMethod")).toString();
QString units = attributes.value(QLatin1String("gradientUnits")).toString();
- QStringRef colorStr = attributes.value(QLatin1String("color"));
- QStringRef colorOpacityStr = attributes.value(QLatin1String("color-opacity"));
+ QStringView colorStr = attributes.value(QLatin1String("color"));
+ QStringView colorOpacityStr = attributes.value(QLatin1String("color-opacity"));
QColor color;
if (constructColor(colorStr, colorOpacityStr, color, handler)) {
@@ -2900,10 +2862,10 @@ static QSvgStyleProperty *createLinearGradientNode(QSvgNode *node,
const QXmlStreamAttributes &attributes,
QSvgHandler *handler)
{
- const QStringRef x1 = attributes.value(QLatin1String("x1"));
- const QStringRef y1 = attributes.value(QLatin1String("y1"));
- const QStringRef x2 = attributes.value(QLatin1String("x2"));
- const QStringRef y2 = attributes.value(QLatin1String("y2"));
+ const QStringView x1 = attributes.value(QLatin1String("x1"));
+ const QStringView y1 = attributes.value(QLatin1String("y1"));
+ const QStringView x2 = attributes.value(QLatin1String("x2"));
+ const QStringView y2 = attributes.value(QLatin1String("y2"));
qreal nx1 = 0.0;
qreal ny1 = 0.0;
@@ -2966,7 +2928,7 @@ static QSvgNode *createPathNode(QSvgNode *parent,
const QXmlStreamAttributes &attributes,
QSvgHandler *)
{
- QStringRef data = attributes.value(QLatin1String("d"));
+ QStringView data = attributes.value(QLatin1String("d"));
QPainterPath qpath;
qpath.setFillRule(Qt::WindingFill);
@@ -3022,11 +2984,11 @@ static QSvgStyleProperty *createRadialGradientNode(QSvgNode *node,
const QXmlStreamAttributes &attributes,
QSvgHandler *handler)
{
- const QStringRef cx = attributes.value(QLatin1String("cx"));
- const QStringRef cy = attributes.value(QLatin1String("cy"));
- const QStringRef r = attributes.value(QLatin1String("r"));
- const QStringRef fx = attributes.value(QLatin1String("fx"));
- const QStringRef fy = attributes.value(QLatin1String("fy"));
+ const QStringView cx = attributes.value(QLatin1String("cx"));
+ const QStringView cy = attributes.value(QLatin1String("cy"));
+ const QStringView r = attributes.value(QLatin1String("r"));
+ const QStringView fx = attributes.value(QLatin1String("fx"));
+ const QStringView fy = attributes.value(QLatin1String("fy"));
qreal ncx = 0.5;
qreal ncy = 0.5;
@@ -3058,20 +3020,20 @@ static QSvgNode *createRectNode(QSvgNode *parent,
const QXmlStreamAttributes &attributes,
QSvgHandler *handler)
{
- const QStringRef x = attributes.value(QLatin1String("x"));
- const QStringRef y = attributes.value(QLatin1String("y"));
- const QStringRef width = attributes.value(QLatin1String("width"));
- const QStringRef height = attributes.value(QLatin1String("height"));
- const QStringRef rx = attributes.value(QLatin1String("rx"));
- const QStringRef ry = attributes.value(QLatin1String("ry"));
+ const QStringView x = attributes.value(QLatin1String("x"));
+ const QStringView y = attributes.value(QLatin1String("y"));
+ const QStringView width = attributes.value(QLatin1String("width"));
+ const QStringView height = attributes.value(QLatin1String("height"));
+ const QStringView rx = attributes.value(QLatin1String("rx"));
+ const QStringView ry = attributes.value(QLatin1String("ry"));
bool ok = true;
QSvgHandler::LengthType type;
- qreal nwidth = parseLength(width, type, handler, &ok);
+ qreal nwidth = parseLength(width.toString(), type, handler, &ok);
if (!ok)
return nullptr;
nwidth = convertToPixels(nwidth, true, type);
- qreal nheight = parseLength(height, type, handler, &ok);
+ qreal nheight = parseLength(height.toString(), type, handler, &ok);
if (!ok)
return nullptr;
nheight = convertToPixels(nheight, true, type);
@@ -3128,8 +3090,8 @@ static QSvgStyleProperty *createSolidColorNode(QSvgNode *parent,
QSvgHandler *handler)
{
Q_UNUSED(parent); Q_UNUSED(attributes);
- QStringRef solidColorStr = attributes.value(QLatin1String("solid-color"));
- QStringRef solidOpacityStr = attributes.value(QLatin1String("solid-opacity"));
+ QStringView solidColorStr = attributes.value(QLatin1String("solid-color"));
+ QStringView solidOpacityStr = attributes.value(QLatin1String("solid-opacity"));
if (solidOpacityStr.isEmpty())
solidOpacityStr = attributes.value(QLatin1String("opacity"));
@@ -3187,7 +3149,7 @@ static bool parseStopNode(QSvgStyleProperty *parent,
QSvgGradientStyle *style =
static_cast<QSvgGradientStyle*>(parent);
- QStringRef colorStr = attrs.stopColor;
+ QStringView colorStr = attrs.stopColor;
QColor color;
bool ok = true;
@@ -3196,7 +3158,7 @@ static bool parseStopNode(QSvgStyleProperty *parent,
offset = 0.0;
QString black = QString::fromLatin1("#000000");
if (colorStr.isEmpty()) {
- colorStr = QStringRef(&black);
+ colorStr = black;
}
constructColor(colorStr, attrs.stopOpacity, color, handler);
@@ -3235,7 +3197,7 @@ static bool parseStyleNode(QSvgNode *parent,
Q_UNUSED(attributes);
Q_UNUSED(handler);
#else
- const QStringRef type = attributes.value(QLatin1String("type"));
+ const QStringView type = attributes.value(QLatin1String("type"));
if (type.compare(QLatin1String("text/css"), Qt::CaseInsensitive) == 0 || type.isNull())
handler->setInStyle(true);
#endif
@@ -3250,21 +3212,21 @@ static QSvgNode *createSvgNode(QSvgNode *parent,
Q_UNUSED(parent); Q_UNUSED(attributes);
QSvgTinyDocument *node = new QSvgTinyDocument();
- const QStringRef widthStr = attributes.value(QLatin1String("width"));
- const QStringRef heightStr = attributes.value(QLatin1String("height"));
+ const QStringView widthStr = attributes.value(QLatin1String("width"));
+ const QStringView heightStr = attributes.value(QLatin1String("height"));
QString viewBoxStr = attributes.value(QLatin1String("viewBox")).toString();
QSvgHandler::LengthType type = QSvgHandler::LT_PX; // FIXME: is the default correct?
qreal width = 0;
if (!widthStr.isEmpty()) {
- width = parseLength(widthStr, type, handler);
+ width = parseLength(widthStr.toString(), type, handler);
if (type != QSvgHandler::LT_PT)
width = convertToPixels(width, true, type);
node->setWidth(int(width), type == QSvgHandler::LT_PERCENT);
}
qreal height = 0;
if (!heightStr.isEmpty()) {
- height = parseLength(heightStr, type, handler);
+ height = parseLength(heightStr.toString(), type, handler);
if (type != QSvgHandler::LT_PT)
height = convertToPixels(height, false, type);
node->setHeight(int(height), type == QSvgHandler::LT_PERCENT);
@@ -3327,12 +3289,12 @@ static QSvgNode *createTextNode(QSvgNode *parent,
const QXmlStreamAttributes &attributes,
QSvgHandler *handler)
{
- const QStringRef x = attributes.value(QLatin1String("x"));
- const QStringRef y = attributes.value(QLatin1String("y"));
+ const QStringView x = attributes.value(QLatin1String("x"));
+ const QStringView y = attributes.value(QLatin1String("y"));
//### editable and rotate not handled
QSvgHandler::LengthType type;
- qreal nx = parseLength(x, type, handler);
- qreal ny = parseLength(y, type, handler);
+ qreal nx = parseLength(x.toString(), type, handler);
+ qreal ny = parseLength(y.toString(), type, handler);
QSvgNode *text = new QSvgText(parent, QPointF(nx, ny));
return text;
@@ -3372,8 +3334,8 @@ static QSvgNode *createUseNode(QSvgNode *parent,
QSvgHandler *handler)
{
QString linkId = attributes.value(QLatin1String("xlink:href")).toString().remove(0, 1);
- const QStringRef xStr = attributes.value(QLatin1String("x"));
- const QStringRef yStr = attributes.value(QLatin1String("y"));
+ const QStringView xStr = attributes.value(QLatin1String("x"));
+ const QStringView yStr = attributes.value(QLatin1String("y"));
QSvgStructureNode *group = 0;
if (linkId.isEmpty())
@@ -3393,10 +3355,10 @@ static QSvgNode *createUseNode(QSvgNode *parent,
QPointF pt;
if (!xStr.isNull() || !yStr.isNull()) {
QSvgHandler::LengthType type;
- qreal nx = parseLength(xStr, type, handler);
+ qreal nx = parseLength(xStr.toString(), type, handler);
nx = convertToPixels(nx, true, type);
- qreal ny = parseLength(yStr, type, handler);
+ qreal ny = parseLength(yStr.toString(), type, handler);
ny = convertToPixels(ny, true, type);
pt = QPointF(nx, ny);
}
@@ -3432,7 +3394,7 @@ static FactoryMethod findGroupFactory(const QString &name)
if (name.isEmpty())
return 0;
- QStringRef ref(&name, 1, name.length() - 1);
+ QStringView ref = QStringView{name}.mid(1, name.length() - 1);
switch (name.at(0).unicode()) {
case 'd':
if (ref == QLatin1String("efs")) return createDefsNode;
@@ -3455,7 +3417,7 @@ static FactoryMethod findGraphicsFactory(const QString &name)
if (name.isEmpty())
return 0;
- QStringRef ref(&name, 1, name.length() - 1);
+ QStringView ref = QStringView{name}.mid(1, name.length() - 1);
switch (name.at(0).unicode()) {
case 'a':
if (ref == QLatin1String("nimation")) return createAnimationNode;
@@ -3504,7 +3466,7 @@ static ParseMethod findUtilFactory(const QString &name)
if (name.isEmpty())
return 0;
- QStringRef ref(&name, 1, name.length() - 1);
+ QStringView ref = QStringView{name}.mid(1, name.length() - 1);
switch (name.at(0).unicode()) {
case 'a':
if (ref.isEmpty()) return parseAnchorNode;
@@ -3556,7 +3518,7 @@ static StyleFactoryMethod findStyleFactoryMethod(const QString &name)
if (name.isEmpty())
return 0;
- QStringRef ref(&name, 1, name.length() - 1);
+ QStringView ref = QStringView{name}.mid(1, name.length() - 1);
switch (name.at(0).unicode()) {
case 'f':
if (ref == QLatin1String("ont")) return createFontNode;
@@ -3585,7 +3547,7 @@ static StyleParseMethod findStyleUtilFactoryMethod(const QString &name)
if (name.isEmpty())
return 0;
- QStringRef ref(&name, 1, name.length() - 1);
+ QStringView ref = QStringView{name}.mid(1, name.length() - 1);
switch (name.at(0).unicode()) {
case 'f':
if (ref == QLatin1String("ont-face")) return parseFontFaceNode;
@@ -3692,7 +3654,7 @@ bool QSvgHandler::startElement(const QString &localName,
/* The xml:space attribute may appear on any element. We do
* a lookup by the qualified name here, but this is namespace aware, since
* the XML namespace can only be bound to prefix "xml." */
- const QStringRef xmlSpace(attributes.value(QLatin1String("xml:space")));
+ const QStringView xmlSpace(attributes.value(QLatin1String("xml:space")));
if (xmlSpace.isNull()) {
// This element has no xml:space attribute.
m_whitespaceMode.push(m_whitespaceMode.isEmpty() ? QSvgText::Default : m_whitespaceMode.top());
@@ -3837,7 +3799,7 @@ bool QSvgHandler::startElement(const QString &localName,
return true;
}
-bool QSvgHandler::endElement(const QStringRef &localName)
+bool QSvgHandler::endElement(const QStringView localName)
{
CurrentNode node = m_skipNodes.top();
m_skipNodes.pop();
@@ -3931,7 +3893,7 @@ void QSvgHandler::resolveNodes()
m_resolveNodes.clear();
}
-bool QSvgHandler::characters(const QStringRef &str)
+bool QSvgHandler::characters(const QStringView str)
{
#ifndef QT_NO_CSSPARSER
if (m_inStyle) {
diff --git a/src/svg/qsvghandler_p.h b/src/svg/qsvghandler_p.h
index 5ff5b88..86b9fa4 100644
--- a/src/svg/qsvghandler_p.h
+++ b/src/svg/qsvghandler_p.h
@@ -136,8 +136,8 @@ public:
public:
bool startElement(const QString &localName, const QXmlStreamAttributes &attributes);
- bool endElement(const QStringRef &localName);
- bool characters(const QStringRef &str);
+ bool endElement(QStringView localName);
+ bool characters(QStringView str);
bool processingInstruction(const QString &target, const QString &data);
private: