name: partial Name comparison

refs #2090

Change-Id: I8de11b7064a2da894f9ddb4b4b1623a7b6d5c0ae
diff --git a/src/name.hpp b/src/name.hpp
index 9743a96..a9716e9 100644
--- a/src/name.hpp
+++ b/src/name.hpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /**
- * Copyright (c) 2013-2014 Regents of the University of California.
+ * Copyright (c) 2013-2015 Regents of the University of California.
  *
  * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
  *
@@ -223,20 +223,11 @@
    * 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.
+   *                    Use npos to get the sub Name until the end of this Name.
    * @return A new name.
    */
   Name
-  getSubName(size_t iStartComponent, size_t nComponents) const;
-
-  /**
-   * @brief 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;
+  getSubName(size_t iStartComponent, size_t nComponents = npos) const;
 
   /**
    * @brief Return a new Name with the first nComponents components of this Name.
@@ -460,14 +451,28 @@
    * std::sort gives: /a/b/d /a/b/cc /c /c/a /bb .  This is intuitive because all names with
    * the prefix /a are next to each other.  But it may be also be counter-intuitive because
    * /c comes before /bb according to NDN canonical ordering since it is shorter.  @param
-   * other The other Name to compare with.  @return 0 If they compare equal, -1 if *this
-   * comes before other in the canonical ordering, or 1 if *this comes after other in the
-   * canonical ordering.
+   * other The other Name to compare with.
+   *
+   * @retval 0 if they compare equal
+   * @retval -1 if *this comes before other in the canonical ordering
+   * @retval 1 if *this comes after other in the canonical ordering
    *
    * @see http://named-data.net/doc/ndn-tlv/name.html#canonical-order
    */
   int
-  compare(const Name& other) const;
+  compare(const Name& other) const
+  {
+    return this->compare(0, npos, other);
+  }
+
+  /** \brief compares [pos1, pos1+count1) components in this Name
+   *         to [pos2, pos2+count2) components in \p other
+   *
+   *  This is equivalent to this->getSubName(pos1, count1).compare(other.getSubName(pos2, count2));
+   */
+  int
+  compare(size_t pos1, size_t count1,
+          const Name& other, size_t pos2 = 0, size_t count2 = npos) const;
 
   /**
    * Append the component
@@ -591,6 +596,11 @@
     return const_reverse_iterator(begin());
   }
 
+public:
+  /** \brief indicates "until the end" in getSubName and compare
+   */
+  static const size_t npos;
+
 private:
   mutable Block m_nameBlock;
 };