Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions source/svgelement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

namespace lunasvg {

ElementID elementid(const std::string_view& name)
ElementID elementid(std::string_view name)
{
static const struct {
std::string_view name;
Expand Down Expand Up @@ -129,23 +129,23 @@ SVGElement::SVGElement(Document* document, ElementID id)
{
}

bool SVGElement::hasAttribute(const std::string_view& name) const
bool SVGElement::hasAttribute(std::string_view name) const
{
auto id = propertyid(name);
if(id == PropertyID::Unknown)
return false;
return hasAttribute(id);
}

const std::string& SVGElement::getAttribute(const std::string_view& name) const
const std::string& SVGElement::getAttribute(std::string_view name) const
{
auto id = propertyid(name);
if(id == PropertyID::Unknown)
return emptyString;
return getAttribute(id);
}

bool SVGElement::setAttribute(const std::string_view& name, const std::string& value)
bool SVGElement::setAttribute(std::string_view name, const std::string& value)
{
auto id = propertyid(name);
if(id == PropertyID::Unknown)
Expand Down Expand Up @@ -326,31 +326,31 @@ Rect SVGElement::paintBoundingBox() const
return m_paintBoundingBox;
}

SVGMarkerElement* SVGElement::getMarker(const std::string_view& id) const
SVGMarkerElement* SVGElement::getMarker(std::string_view id) const
{
auto element = rootElement()->getElementById(id);
if(element && element->id() == ElementID::Marker)
return static_cast<SVGMarkerElement*>(element);
return nullptr;
}

SVGClipPathElement* SVGElement::getClipper(const std::string_view& id) const
SVGClipPathElement* SVGElement::getClipper(std::string_view id) const
{
auto element = rootElement()->getElementById(id);
if(element && element->id() == ElementID::ClipPath)
return static_cast<SVGClipPathElement*>(element);
return nullptr;
}

SVGMaskElement* SVGElement::getMasker(const std::string_view& id) const
SVGMaskElement* SVGElement::getMasker(std::string_view id) const
{
auto element = rootElement()->getElementById(id);
if(element && element->id() == ElementID::Mask)
return static_cast<SVGMaskElement*>(element);
return nullptr;
}

SVGPaintElement* SVGElement::getPainter(const std::string_view& id) const
SVGPaintElement* SVGElement::getPainter(std::string_view id) const
{
auto element = rootElement()->getElementById(id);
if(element && element->isPaintElement())
Expand Down Expand Up @@ -683,7 +683,7 @@ SVGRootElement* SVGRootElement::layoutIfNeeded()
return this;
}

SVGElement* SVGRootElement::getElementById(const std::string_view& id) const
SVGElement* SVGRootElement::getElementById(std::string_view id) const
{
auto it = m_idCache.find(id);
if(it == m_idCache.end())
Expand Down
18 changes: 9 additions & 9 deletions source/svgelement.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ enum class ElementID : uint8_t {
Use
};

ElementID elementid(const std::string_view& name);
ElementID elementid(std::string_view name);

using SVGNodeList = std::list<std::unique_ptr<SVGNode>>;
using SVGPropertyList = std::forward_list<SVGProperty*>;
Expand All @@ -129,9 +129,9 @@ class SVGElement : public SVGNode {
SVGElement(Document* document, ElementID id);
virtual ~SVGElement() = default;

bool hasAttribute(const std::string_view& name) const;
const std::string& getAttribute(const std::string_view& name) const;
bool setAttribute(const std::string_view& name, const std::string& value);
bool hasAttribute(std::string_view name) const;
const std::string& getAttribute(std::string_view name) const;
bool setAttribute(std::string_view name, const std::string& value);

const Attribute* findAttribute(PropertyID id) const;
bool hasAttribute(PropertyID id) const;
Expand Down Expand Up @@ -159,10 +159,10 @@ class SVGElement : public SVGNode {
virtual Rect strokeBoundingBox() const;
virtual Rect paintBoundingBox() const;

SVGMarkerElement* getMarker(const std::string_view& id) const;
SVGClipPathElement* getClipper(const std::string_view& id) const;
SVGMaskElement* getMasker(const std::string_view& id) const;
SVGPaintElement* getPainter(const std::string_view& id) const;
SVGMarkerElement* getMarker(std::string_view id) const;
SVGClipPathElement* getClipper(std::string_view id) const;
SVGMaskElement* getMasker(std::string_view id) const;
SVGPaintElement* getPainter(std::string_view id) const;

SVGElement* elementFromPoint(float x, float y);

Expand Down Expand Up @@ -346,7 +346,7 @@ class SVGRootElement final : public SVGSVGElement {

SVGRootElement* layoutIfNeeded();

SVGElement* getElementById(const std::string_view& id) const;
SVGElement* getElementById(std::string_view id) const;
void addElementById(const std::string& id, SVGElement* element);
void layout(SVGLayoutState& state) final;

Expand Down
40 changes: 20 additions & 20 deletions source/svglayoutstate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,15 +110,15 @@ static float parseNumberOrPercentage(std::string_view input, bool allowPercentag
return value;
}

static Length parseLength(const std::string_view& input, LengthNegativeMode mode, const Length& defaultValue)
static Length parseLength(std::string_view input, LengthNegativeMode mode, const Length& defaultValue)
{
Length value;
if(!value.parse(input, mode))
value = defaultValue;
return value;
}

static BaselineShift parseBaselineShift(const std::string_view& input)
static BaselineShift parseBaselineShift(std::string_view input)
{
if(input.compare("baseline") == 0)
return BaselineShift::Type::Baseline;
Expand Down Expand Up @@ -167,7 +167,7 @@ static float parseFontSize(std::string_view input, const SVGLayoutState* state)
}

template<typename Enum, unsigned int N>
static Enum parseEnumValue(const std::string_view& input, const SVGEnumerationEntry<Enum>(&entries)[N], Enum defaultValue)
static Enum parseEnumValue(std::string_view input, const SVGEnumerationEntry<Enum>(&entries)[N], Enum defaultValue)
{
for(const auto& entry : entries) {
if(input == entry.second) {
Expand All @@ -178,7 +178,7 @@ static Enum parseEnumValue(const std::string_view& input, const SVGEnumerationEn
return defaultValue;
}

static Display parseDisplay(const std::string_view& input)
static Display parseDisplay(std::string_view input)
{
static const SVGEnumerationEntry<Display> entries[] = {
{Display::Inline, "inline"},
Expand All @@ -188,7 +188,7 @@ static Display parseDisplay(const std::string_view& input)
return parseEnumValue(input, entries, Display::Inline);
}

static Visibility parseVisibility(const std::string_view& input)
static Visibility parseVisibility(std::string_view input)
{
static const SVGEnumerationEntry<Visibility> entries[] = {
{Visibility::Visible, "visible"},
Expand All @@ -199,7 +199,7 @@ static Visibility parseVisibility(const std::string_view& input)
return parseEnumValue(input, entries, Visibility::Visible);
}

static Overflow parseOverflow(const std::string_view& input)
static Overflow parseOverflow(std::string_view input)
{
static const SVGEnumerationEntry<Overflow> entries[] = {
{Overflow::Visible, "visible"},
Expand All @@ -209,7 +209,7 @@ static Overflow parseOverflow(const std::string_view& input)
return parseEnumValue(input, entries, Overflow::Visible);
}

static PointerEvents parsePointerEvents(const std::string_view& input)
static PointerEvents parsePointerEvents(std::string_view input)
{
static const SVGEnumerationEntry<PointerEvents> entries[] = {
{PointerEvents::None,"none"},
Expand All @@ -228,7 +228,7 @@ static PointerEvents parsePointerEvents(const std::string_view& input)
return parseEnumValue(input, entries, PointerEvents::Auto);
}

static FontWeight parseFontWeight(const std::string_view& input)
static FontWeight parseFontWeight(std::string_view input)
{
static const SVGEnumerationEntry<FontWeight> entries[] = {
{FontWeight::Normal, "normal"},
Expand All @@ -249,7 +249,7 @@ static FontWeight parseFontWeight(const std::string_view& input)
return parseEnumValue(input, entries, FontWeight::Normal);
}

static FontStyle parseFontStyle(const std::string_view& input)
static FontStyle parseFontStyle(std::string_view input)
{
static const SVGEnumerationEntry<FontStyle> entries[] = {
{FontStyle::Normal, "normal"},
Expand All @@ -260,7 +260,7 @@ static FontStyle parseFontStyle(const std::string_view& input)
return parseEnumValue(input, entries, FontStyle::Normal);
}

static AlignmentBaseline parseAlignmentBaseline(const std::string_view& input)
static AlignmentBaseline parseAlignmentBaseline(std::string_view input)
{
static const SVGEnumerationEntry<AlignmentBaseline> entries[] = {
{AlignmentBaseline::Auto, "auto"},
Expand All @@ -280,7 +280,7 @@ static AlignmentBaseline parseAlignmentBaseline(const std::string_view& input)
return parseEnumValue(input, entries, AlignmentBaseline::Auto);
}

static DominantBaseline parseDominantBaseline(const std::string_view& input)
static DominantBaseline parseDominantBaseline(std::string_view input)
{
static const SVGEnumerationEntry<DominantBaseline> entries[] = {
{DominantBaseline::Auto, "auto"},
Expand All @@ -300,7 +300,7 @@ static DominantBaseline parseDominantBaseline(const std::string_view& input)
return parseEnumValue(input, entries, DominantBaseline::Auto);
}

static Direction parseDirection(const std::string_view& input)
static Direction parseDirection(std::string_view input)
{
static const SVGEnumerationEntry<Direction> entries[] = {
{Direction::Ltr, "ltr"},
Expand All @@ -310,7 +310,7 @@ static Direction parseDirection(const std::string_view& input)
return parseEnumValue(input, entries, Direction::Ltr);
}

static WritingMode parseWritingMode(const std::string_view& input)
static WritingMode parseWritingMode(std::string_view input)
{
static const SVGEnumerationEntry<WritingMode> entries[] = {
{WritingMode::Horizontal, "horizontal-tb"},
Expand All @@ -327,7 +327,7 @@ static WritingMode parseWritingMode(const std::string_view& input)
return parseEnumValue(input, entries, WritingMode::Horizontal);
}

static TextOrientation parseTextOrientation(const std::string_view& input)
static TextOrientation parseTextOrientation(std::string_view input)
{
static const SVGEnumerationEntry<TextOrientation> entries[] = {
{TextOrientation::Mixed, "mixed"},
Expand All @@ -337,7 +337,7 @@ static TextOrientation parseTextOrientation(const std::string_view& input)
return parseEnumValue(input, entries, TextOrientation::Mixed);
}

static TextAnchor parseTextAnchor(const std::string_view& input)
static TextAnchor parseTextAnchor(std::string_view input)
{
static const SVGEnumerationEntry<TextAnchor> entries[] = {
{TextAnchor::Start, "start"},
Expand All @@ -348,7 +348,7 @@ static TextAnchor parseTextAnchor(const std::string_view& input)
return parseEnumValue(input, entries, TextAnchor::Start);
}

static WhiteSpace parseWhiteSpace(const std::string_view& input)
static WhiteSpace parseWhiteSpace(std::string_view input)
{
static const SVGEnumerationEntry<WhiteSpace> entries[] = {
{WhiteSpace::Default, "default"},
Expand All @@ -363,7 +363,7 @@ static WhiteSpace parseWhiteSpace(const std::string_view& input)
return parseEnumValue(input, entries, WhiteSpace::Default);
}

static MaskType parseMaskType(const std::string_view& input)
static MaskType parseMaskType(std::string_view input)
{
static const SVGEnumerationEntry<MaskType> entries[] = {
{MaskType::Luminance, "luminance"},
Expand All @@ -373,7 +373,7 @@ static MaskType parseMaskType(const std::string_view& input)
return parseEnumValue(input, entries, MaskType::Luminance);
}

static FillRule parseFillRule(const std::string_view& input)
static FillRule parseFillRule(std::string_view input)
{
static const SVGEnumerationEntry<FillRule> entries[] = {
{FillRule::NonZero, "nonzero"},
Expand All @@ -383,7 +383,7 @@ static FillRule parseFillRule(const std::string_view& input)
return parseEnumValue(input, entries, FillRule::NonZero);
}

static LineCap parseLineCap(const std::string_view& input)
static LineCap parseLineCap(std::string_view input)
{
static const SVGEnumerationEntry<LineCap> entries[] = {
{LineCap::Butt, "butt"},
Expand All @@ -394,7 +394,7 @@ static LineCap parseLineCap(const std::string_view& input)
return parseEnumValue(input, entries, LineCap::Butt);
}

static LineJoin parseLineJoin(const std::string_view& input)
static LineJoin parseLineJoin(std::string_view input)
{
static const SVGEnumerationEntry<LineJoin> entries[] = {
{LineJoin::Miter, "miter"},
Expand Down
14 changes: 7 additions & 7 deletions source/svgparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,17 +102,17 @@ inline bool operator<(const RuleData& a, const RuleData& b) { return a.isLessTha

using RuleDataList = std::vector<RuleData>;

constexpr bool equals(const std::string_view& value, const std::string_view& subvalue)
constexpr bool equals(std::string_view value, std::string_view subvalue)
{
return value.compare(subvalue) == 0;
}

constexpr bool contains(const std::string_view& value, const std::string_view& subvalue)
constexpr bool contains(std::string_view value, std::string_view subvalue)
{
return value.find(subvalue) != std::string_view::npos;
}

constexpr bool includes(const std::string_view& value, const std::string_view& subvalue)
constexpr bool includes(std::string_view value, std::string_view subvalue)
{
if(subvalue.empty() || subvalue.length() > value.length())
return false;
Expand All @@ -130,21 +130,21 @@ constexpr bool includes(const std::string_view& value, const std::string_view& s
return false;
}

constexpr bool startswith(const std::string_view& value, const std::string_view& subvalue)
constexpr bool startswith(std::string_view value, std::string_view subvalue)
{
if(subvalue.empty() || subvalue.length() > value.length())
return false;
return subvalue == value.substr(0, subvalue.size());
}

constexpr bool endswith(const std::string_view& value, const std::string_view& subvalue)
constexpr bool endswith(std::string_view value, std::string_view subvalue)
{
if(subvalue.empty() || subvalue.length() > value.length())
return false;
return subvalue == value.substr(value.size() - subvalue.size(), subvalue.size());
}

constexpr bool dashequals(const std::string_view& value, const std::string_view& subvalue)
constexpr bool dashequals(std::string_view value, std::string_view subvalue)
{
if(startswith(value, subvalue))
return (value.length() == subvalue.length() || value.at(subvalue.length()) == '-');
Expand Down Expand Up @@ -717,7 +717,7 @@ bool Document::parse(const char* data, size_t length)
std::string styleSheet;
SVGElement* currentElement = nullptr;
int ignoring = 0;
auto handleText = [&](const std::string_view& text, bool in_cdata) {
auto handleText = [&](std::string_view text, bool in_cdata) {
if(text.empty() || currentElement == nullptr || ignoring > 0)
return;
if(currentElement->id() != ElementID::Text && currentElement->id() != ElementID::Tspan && currentElement->id() != ElementID::Style) {
Expand Down
2 changes: 1 addition & 1 deletion source/svgparserutils.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ constexpr bool skipDelimiter(std::string_view& input, char delimiter)
return false;
}

constexpr bool skipString(std::string_view& input, const std::string_view& value)
constexpr bool skipString(std::string_view& input, std::string_view value)
{
if(input.size() >= value.size() && value == input.substr(0, value.size())) {
input.remove_prefix(value.size());
Expand Down
4 changes: 2 additions & 2 deletions source/svgproperty.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

namespace lunasvg {

PropertyID propertyid(const std::string_view& name)
PropertyID propertyid(std::string_view name)
{
static const struct {
std::string_view name;
Expand Down Expand Up @@ -67,7 +67,7 @@ PropertyID propertyid(const std::string_view& name)
return it->value;
}

PropertyID csspropertyid(const std::string_view& name)
PropertyID csspropertyid(std::string_view name)
{
static const struct {
std::string_view name;
Expand Down
4 changes: 2 additions & 2 deletions source/svgproperty.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ enum class PropertyID : uint8_t {
Y2
};

PropertyID propertyid(const std::string_view& name);
PropertyID csspropertyid(const std::string_view& name);
PropertyID propertyid(std::string_view name);
PropertyID csspropertyid(std::string_view name);

class SVGElement;

Expand Down