]> git.localhorst.tv Git - l2e.git/blob - src/loader/utility.cpp
6d336672de217889888b26c8600cf3a5dbd8fb92
[l2e.git] / src / loader / utility.cpp
1 /*
2  * utility.cpp
3  *
4  *  Created on: Sep 1, 2012
5  *      Author: holy
6  */
7
8 #include "utility.h"
9
10 #include <cstring>
11 #include <libgen.h>
12
13 using std::string;
14
15 namespace loader {
16
17 string Dirname(const string &path) {
18         char *str(new char[path.size() + 1]);
19         std::memcpy(str, path.c_str(), path.size());
20         str[path.size()] = '\0';
21         string dn(dirname(str));
22         delete[] str;
23         return dn;
24 }
25
26 string CatPath(const string &lhs, const string &rhs) {
27         string path(lhs);
28         if (!path.empty()
29                         && path[path.size() - 1] != '/'
30                         && path[path.size() - 1] != '\\') {
31                 path += '/';
32         }
33         if (!rhs.empty() && (rhs[0] == '/' || rhs[0] == '\\')) {
34                 path.append(rhs, 1, string::npos);
35         } else {
36                 path += rhs;
37         }
38         return path;
39 }
40
41 }