diff --git a/include/sdf/Types.hh b/include/sdf/Types.hh index b8ab9a2d4..d1bc921a4 100644 --- a/include/sdf/Types.hh +++ b/include/sdf/Types.hh @@ -232,10 +232,19 @@ namespace sdf /// \return Lowercase equilvalent of _in. std::string SDFORMAT_VISIBLE lowercase(const std::string &_in); + /// \brief Split a name into a two strings based on the '::' delimeter + /// \param[in] _absoluteName The fully qualified absolute name + /// \return A pair with the absolute name minus the leaf node name, and the + /// leaf name SDFORMAT_VISIBLE std::pair SplitName( const std::string &_absoluteName); + /// \brief Join two strings with the '::' delimiter. + /// This checks for edge cases and is safe to use with any valid names + /// \param[in] _scopeName the left-hand-side component + /// \param[in] _localName the right-hand-side component + /// \return A full string with the names joined by the '::' delimeter. SDFORMAT_VISIBLE std::string JoinName( const std::string &_scopeName, const std::string &_localName); diff --git a/src/Types.cc b/src/Types.cc index 212a624d9..fb33c5c5d 100644 --- a/src/Types.cc +++ b/src/Types.cc @@ -111,8 +111,9 @@ static bool EndsWithDelimiter(const std::string &_s) if (_s.size() < kSdfScopeDelimiter.size()) return false; - const size_t findStartPosition = _s.size() - kSdfScopeDelimiter.size(); - return _s.substr(findStartPosition) == kSdfScopeDelimiter; + const size_t startPosition = _s.size() - kSdfScopeDelimiter.size(); + return _s.compare( + startPosition, kSdfScopeDelimiter.size(), kSdfScopeDelimiter) == 0; } static bool StartsWithDelimiter(const std::string &_s) @@ -120,7 +121,7 @@ static bool StartsWithDelimiter(const std::string &_s) if (_s.size() < kSdfScopeDelimiter.size()) return false; - return _s.substr(0, kSdfScopeDelimiter.size()) == kSdfScopeDelimiter; + return _s.compare(0, kSdfScopeDelimiter.size(), kSdfScopeDelimiter) == 0; } // Join an scope name prefix with a local name using the scope delimeter