[mlpack-git] master: Convenience function for extracting extensions. (b100468)

gitdub at big.cc.gt.atl.ga.us gitdub at big.cc.gt.atl.ga.us
Fri Jul 10 18:59:06 EDT 2015


Repository : https://github.com/mlpack/mlpack

On branch  : master
Link       : https://github.com/mlpack/mlpack/compare/4a97187bbba7ce8a6191b714949dd818ef0f37d2...e5905e62c15d1bcff21e6359b11efcd7ab6d7ca0

>---------------------------------------------------------------

commit b1004686b2678e9566033937674e3f4dee3ed76b
Author: ryan <ryan at ratml.org>
Date:   Wed Apr 15 11:58:02 2015 -0400

    Convenience function for extracting extensions.


>---------------------------------------------------------------

b1004686b2678e9566033937674e3f4dee3ed76b
 src/mlpack/core/data/extension.hpp | 33 +++++++++++++++++++++++++++++++++
 1 file changed, 33 insertions(+)

diff --git a/src/mlpack/core/data/extension.hpp b/src/mlpack/core/data/extension.hpp
new file mode 100644
index 0000000..0d82aea
--- /dev/null
+++ b/src/mlpack/core/data/extension.hpp
@@ -0,0 +1,33 @@
+/**
+ * @file extension.hpp
+ * @author Ryan Curtin
+ *
+ * Given a filename, extract its extension.  This is used by data::Load() and
+ * data::Save().
+ */
+#ifndef __MLPACK_CORE_DATA_EXTENSION_HPP
+#define __MLPACK_CORE_DATA_EXTENSION_HPP
+
+#include <mlpack/prereqs.hpp>
+
+namespace mlpack {
+namespace data {
+
+std::string Extension(const std::string& filename)
+{
+  const size_t ext = filename.rfind('.');
+  std::string extension;
+  if (ext == std::string::npos)
+    return extension;
+
+  extension = filename.substr(ext + 1);
+  std::transform(extension.begin(), extension.end(), extension.begin(),
+      ::tolower);
+
+  return extension;
+}
+
+} // namespace data
+} // namespace mlpack
+
+#endif



More information about the mlpack-git mailing list