]> git.localhorst.tv Git - l2e.git/blob - src/loader/utility.cpp
f5011e6fe243ea97685ffefab3eb7421b93d8aa2
[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         // unix version
19         char *str(new char[path.size() + 1]);
20         std::memcpy(str, path.c_str(), path.size());
21         str[path.size()] = '\0';
22         string dn(dirname(str));
23         delete[] str;
24         return dn;
25 }
26
27 string CatPath(const string &lhs, const string &rhs) {
28         // unix version
29         string path(lhs);
30         if (!path.empty() && path[path.size() - 1] != '/') {
31                 path += '/';
32         }
33         if (!rhs.empty() && rhs[0] == '/') {
34                 path.append(rhs, 1, string::npos);
35         } else {
36                 path += rhs;
37         }
38         return path;
39 }
40
41 }