[Release] wrt-commons_0.2.135
[framework/web/wrt-commons.git] / modules / utils / src / path.cpp
index 5f36011..51b54aa 100644 (file)
@@ -314,6 +314,27 @@ bool Path::isSubPath(const Path & other) const
     return true;
 }
 
+bool Path::hasExtension(const std::string& extension) const
+{
+    LogDebug("Looking for extension " << extension << " in: " << this->Filename());
+
+    size_t extLen = extension.length();
+
+    if(m_parts.empty()) return false;
+    if(extLen == 0) return false;
+
+    const std::string& last = *--m_parts.end();
+    size_t lastLen = last.length();
+
+    if(lastLen < (1 + extLen)) return false;
+
+    const char last_tmp = last[ lastLen - (1 + extLen) ];
+    if(last_tmp != '.') return false;
+
+    if(last.substr(lastLen - extLen) != extension) return false;
+    return true;
+}
+
 void MakeDir(const Path & path, mode_t mode)
 {
     path.RootGuard();