Skip to content

New Methods #7

@jtaylorme

Description

@jtaylorme

These might need touched up to fit your style but just to say thanks for the library, here are a couple new Methods some might find useful, if you want to include them.



shared_ptr<HtmlElement> GetSiblingNext() {
        shared_ptr<HtmlElement> el = shared_from_this();

        if (el->GetParent()) {
            auto& children = el->GetParent()->children;

            auto it = std::find(children.begin(), children.end(), el);

            if (it != children.end()) {
                if (it + 1 != children.end()) {
                    auto nextSibling = *(it + 1);
                    return nextSibling;
                }
            }
        }
        return nullptr;
    }


    shared_ptr<HtmlElement> GetSiblingPrev() {
        shared_ptr<HtmlElement> el = shared_from_this();

        if (el->GetParent()) {
            auto& children = el->GetParent()->children;

            auto it = std::find(children.begin(), children.end(), el);

            if (it != children.end()) {
                if (it != children.begin()) {
                    auto prevSibling = *(it - 1);
                    return prevSibling;
                }
            }
        }   
        return nullptr;
    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions