Skip to content

New Methods #7

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;
    }

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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