Last bit of string cleanup. string.h finally gone.

This commit is contained in:
Ben Vanik
2014-08-17 11:48:29 -07:00
parent 383d3acbb0
commit 24fe169f36
28 changed files with 148 additions and 236 deletions

View File

@@ -51,6 +51,22 @@ std::wstring to_absolute_path(const std::wstring& path) {
#endif // XE_LIKE_WIN32
}
std::vector<std::string> split_path(const std::string& path) {
std::vector<std::string> parts;
size_t n = 0;
size_t last = 0;
while ((n = path.find_first_of("\\/", last)) != path.npos) {
if (last != n) {
parts.push_back(path.substr(last, n - last));
}
last = n + 1;
}
if (last != path.size()) {
parts.push_back(path.substr(last));
}
return parts;
}
std::wstring join_paths(const std::wstring& left, const std::wstring& right,
wchar_t sep) {
if (!left.size()) {

View File

@@ -10,13 +10,16 @@
#ifndef POLY_STRING_H_
#define POLY_STRING_H_
#include <cstdio>
#include <string>
#include <vector>
#include <poly/platform.h>
#if XE_LIKE_WIN32
#define strcasecmp _stricmp
#define strncasecmp _strnicmp
#define snprintf _snprintf
#endif // XE_LIKE_WIN32
namespace poly {
@@ -31,6 +34,9 @@ std::string::size_type find_first_of_case(const std::string& target,
// Converts the given path to an absolute path based on cwd.
std::wstring to_absolute_path(const std::wstring& path);
// Splits the given path on any valid path separator and returns all parts.
std::vector<std::string> split_path(const std::string& path);
// Joins two path segments with the given separator.
std::wstring join_paths(const std::wstring& left, const std::wstring& right,
wchar_t sep = poly::path_separator);