summaryrefslogtreecommitdiff
path: root/src/core/common
diff options
context:
space:
mode:
Diffstat (limited to 'src/core/common')
-rw-r--r--src/core/common/Location.cpp23
-rw-r--r--src/core/common/Utils.cpp23
-rw-r--r--src/core/common/Utils.hpp20
3 files changed, 66 insertions, 0 deletions
diff --git a/src/core/common/Location.cpp b/src/core/common/Location.cpp
new file mode 100644
index 0000000..6f9250a
--- /dev/null
+++ b/src/core/common/Location.cpp
@@ -0,0 +1,23 @@
+/*
+ Ousía
+ Copyright (C) 2014, 2015 Benjamin Paaßen, Andreas Stöckel
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#include "Location.hpp"
+
+namespace ousia {
+}
+
diff --git a/src/core/common/Utils.cpp b/src/core/common/Utils.cpp
index 5fde29c..c8fcdc6 100644
--- a/src/core/common/Utils.cpp
+++ b/src/core/common/Utils.cpp
@@ -17,7 +17,9 @@
*/
#include <algorithm>
+#include <cctype>
#include <limits>
+#include <string>
#include "Utils.hpp"
@@ -74,5 +76,26 @@ std::vector<std::string> Utils::split(const std::string &s, char delim)
return res;
}
+std::string Utils::toLower(std::string s)
+{
+ std::transform(s.begin(), s.end(), s.begin(), tolower);
+ return s;
+}
+
+std::string Utils::extractFileExtension(const std::string &filename)
+{
+ size_t n = 0;
+ for (ssize_t i = filename.size() - 1; i >= 0; i--) {
+ if (filename[i] == '/' || filename[i] == '\\') {
+ return std::string{};
+ }
+ if (filename[i] == '.') {
+ return toLower(filename.substr(i + 1, n));
+ }
+ n++;
+ }
+ return std::string{};
+}
+
}
diff --git a/src/core/common/Utils.hpp b/src/core/common/Utils.hpp
index 1f7f142..22e0fd3 100644
--- a/src/core/common/Utils.hpp
+++ b/src/core/common/Utils.hpp
@@ -114,6 +114,26 @@ public:
* @return a vector of strings containing the splitted sub-strings.
*/
static std::vector<std::string> split(const std::string &s, char delim);
+
+ /**
+ * Converts the given string to lowercase (only works for ANSI characters).
+ *
+ * @param s is the string that should be converted to lowercase.
+ * @return s in lowercase.
+ */
+ static std::string toLower(std::string s);
+
+ /**
+ * Reads the file extension of the given filename.
+ *
+ * @param filename is the filename from which the extension should be
+ * extracted.
+ * @return the extension, excluding any leading dot. The extension is
+ * defined as the substring after the last dot in the given string, if the
+ * dot is after a slash or backslash. The extension is converted to
+ * lowercase.
+ */
+ static std::string extractFileExtension(const std::string &filename);
};
}