| // Copyright 2026 Google LLC |
| // |
| // Licensed under the Apache License, Version 2.0 (the "License"); |
| // you may not use this file except in compliance with the License. |
| // You may obtain a copy of the License at |
| // |
| // https://www.apache.org/licenses/LICENSE-2.0 |
| // |
| // Unless required by applicable law or agreed to in writing, software |
| // distributed under the License is distributed on an "AS IS" BASIS, |
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| // See the License for the specific language governing permissions and |
| // limitations under the License. |
| // |
| |
| #ifndef THIRD_PARTY_CREDENTIO_FORMATS_BMFF_XPATH_H_ |
| #define THIRD_PARTY_CREDENTIO_FORMATS_BMFF_XPATH_H_ |
| |
| #include <optional> |
| #include <string> |
| |
| #include "absl/strings/string_view.h" |
| |
| namespace credentio { |
| |
| // An XPath represents a path from the root to a BMFF box, with the formatted |
| // string according to https://www.w3.org/TR/xpath-10/. |
| class XPath { |
| public: |
| // Constructs an XPath with a parent and a name. |
| XPath(const XPath* parent, std::string name) : parent_(parent), name_(name) {} |
| |
| // Constructs an XPath with a parent, a name, and a position. |
| XPath(const XPath* parent, std::string name, int position) |
| : parent_(parent), name_(name), position_(position) {} |
| |
| // Sets the position of the element for this path. |
| void SetPosition(int position) { position_ = position; } |
| // Returns the string representation of this full path. |
| std::string ToString() const; |
| |
| private: |
| // The parent of this path. |
| const XPath* parent_; |
| // The name of the element pointed by this path. |
| std::string name_; |
| // The position of the element for this path. The position represents that |
| // this path is the Nth child with tag name in its parent. |
| std::optional<int> position_ = std::nullopt; |
| }; |
| |
| // A util class to match a XPath. |
| class XPathMatcher { |
| public: |
| explicit XPathMatcher(absl::string_view pattern) : pattern_(pattern) {} |
| bool Matches(absl::string_view path) const; |
| |
| private: |
| std::string pattern_; |
| }; |
| |
| } // namespace credentio |
| |
| #endif // THIRD_PARTY_CREDENTIO_FORMATS_BMFF_XPATH_H_ |