Name: Added getSubName.
diff --git a/ndn-cpp/name.cpp b/ndn-cpp/name.cpp
index 11d284c..1eb25de 100644
--- a/ndn-cpp/name.cpp
+++ b/ndn-cpp/name.cpp
@@ -239,6 +239,29 @@
return result.str();
}
+Name
+Name::getSubName(size_t iStartComponent, size_t nComponents) const
+{
+ Name result;
+
+ unsigned int iEnd = iStartComponent + nComponents;
+ for (unsigned int i = iStartComponent; i < iEnd && i < components_.size(); ++i)
+ result.components_.push_back(components_[i]);
+
+ return result;
+}
+
+Name
+Name::getSubName(size_t iStartComponent) const
+{
+ Name result;
+
+ for (unsigned int i = iStartComponent; i < components_.size(); ++i)
+ result.components_.push_back(components_[i]);
+
+ return result;
+}
+
bool
Name::match(const Name& name) const
{
diff --git a/ndn-cpp/name.hpp b/ndn-cpp/name.hpp
index 12fbe79..1a1cf53 100644
--- a/ndn-cpp/name.hpp
+++ b/ndn-cpp/name.hpp
@@ -83,7 +83,7 @@
* @param result the string stream to write to.
*/
void
- toEscapedString(std::ostringstream& result)
+ toEscapedString(std::ostringstream& result) const
{
Name::toEscapedString(*value_, result);
}
@@ -94,7 +94,7 @@
* @return The escaped string.
*/
std::string
- toEscapedString()
+ toEscapedString() const
{
return Name::toEscapedString(*value_);
}
@@ -241,6 +241,34 @@
getComponent(unsigned int i) const { return components_[i]; }
/**
+ * Get a new name, constructed as a subset of components.
+ * @param iStartComponent The index if the first component to get.
+ * @param nComponents The number of components starting at iStartComponent.
+ * @return A new name.
+ */
+ Name
+ getSubName(size_t iStartComponent, size_t nComponents) const;
+
+ /**
+ * Get a new name, constructed as a subset of components starting at iStartComponent until the end of the name.
+ * @param iStartComponent The index if the first component to get.
+ * @return A new name.
+ */
+ Name
+ getSubName(size_t iStartComponent) const;
+
+ /**
+ * Return a new Name with the first nComponents components of this Name.
+ * @param nComponents The number of prefix components.
+ * @return A new Name.
+ */
+ Name
+ getPrefix(size_t nComponents) const
+ {
+ return getSubName(0, nComponents);
+ }
+
+ /**
* Encode this name as a URI.
* @return The encoded URI.
*/