26 #if defined(_WIN32) || defined(_WIN64)
30 #include <utf8cpp/utf8.h>
31 #if 0 && __has_include(<utf8cpp/cpp17.h>)
32 #include <utf8cpp/cpp17.h>
33 #define LIBXCKS_UTF8CPP_HAS_STRING_VIEW
49 using namespace std::filesystem;
64 std::vector<std::filesystem::path>
getDirectories(
const std::filesystem::path& p)
67 path pp = p.relative_path().parent_path();
68 copy(pp.begin(), pp.end(), back_inserter(paths));
84 path pp = p.relative_path().parent_path();
111 #if defined(_WIN32) || defined(_WIN64)
113 utf8::utf8to16(fn1.begin(), fn1.end(), back_inserter(wfn1));
114 utf8::utf8to16(fn2.begin(), fn2.end(), back_inserter(wfn2));
116 res = CompareStringEx(LOCALE_NAME_USER_DEFAULT, NORM_IGNORECASE, wfn1.c_str(), wfn1.size(), wfn2.c_str(), wfn2.size(),
nullptr,
nullptr, 0) - CSTR_EQUAL;
119 res = fn1.compare(fn2);
141 #if defined(_WIN32) || defined(_WIN64)
142 wstring wfn1 = p1.filename().wstring();
143 wstring wfn2 = p2.filename().wstring();
145 res = CompareStringEx(LOCALE_NAME_USER_DEFAULT, NORM_IGNORECASE, wfn1.c_str(), wfn1.size(), wfn2.c_str(), wfn2.size(),
nullptr,
nullptr, 0) - CSTR_EQUAL;
148 u32string fn1 = p1.filename().u32string();
149 u32string fn2 = p2.filename().u32string();
150 res = fn1.compare(fn2);
172 const char32_t sep = U
'/';
174 for (
const string& d : dirs)
178 #if defined(_MSC_VER)
179 utf8::utf8to32(d.c_str(), d.c_str() + d.size(), back_inserter(p));
181 p += utf8::utf8to32(d);
184 if (!filename.empty())
188 #if defined(_MSC_VER)
189 utf8::utf8to32(filename.c_str(), filename.c_str() + filename.size(), back_inserter(p));
191 p += utf8::utf8to32(filename);
195 return path(p).make_preferred();
211 u32string
generic = p.generic_u32string();
212 if (
generic.back() == U
'/')
213 return path(p).make_preferred();
216 generic.push_back(U
'/');
217 return path(
generic).make_preferred();
268 if (filename.empty())
271 #if defined(__unix__) || defined(__unix) || defined(_WIN32) || defined(_WIN64)
272 if ((filename ==
".") || (filename ==
".."))
276 #if defined(__APPLE__) && !(defined(__unix__) || defined(__unix))
277 char invalidChars[] = {
'/',
':',
'\0' };
278 #elif defined(_WIN32) || defined(_WIN64)
279 char invalidChars[] = {
'<',
'>',
':',
'"',
'/',
'\\',
'|',
'?',
'*',
281 '\x01',
'\x01',
'\x02',
'\x03',
'\x04',
'\x05',
'\x06',
'\x07',
282 '\x08',
'\x09',
'\x0A',
'\x0B',
'\x0C',
'\x0D',
'\x0E',
'\x0F',
283 '\x10',
'\x11',
'\x11',
'\x12',
'\x13',
'\x14',
'\x15',
'\x16',
'\x17',
284 '\x18',
'\x19',
'\x1A',
'\x1B',
'\x1C',
'\x1D',
'\x1E',
'\x1F' };
285 #elif defined(__unix__) || defined(__unix)
286 #if defined(__APPLE__)
287 char invalidChars[] = {
'/',
':',
'\0' };
289 char invalidChars[] = {
'/',
'\0' };
292 #error Unknow OS. :-(
297 while (valid && (i < (
sizeof(invalidChars) /
sizeof(invalidChars[0]))))
299 valid = (filename.find(invalidChars[i]) == string::npos);
303 #if defined(_WIN32) || defined(_WIN64)
306 const char& last = filename.back();
307 if ((last ==
' ') || (last ==
'.'))
312 invalidNames.emplace_back(
string(
"CON"));
313 invalidNames.emplace_back(
string(
"PRN"));
314 invalidNames.emplace_back(
string(
"AUX"));
315 invalidNames.emplace_back(
string(
"NUL"));
316 for (
int i = 1; i <= 9; i++)
319 snprintf(buf, 5,
"COM%d", i);
320 invalidNames.emplace_back(
string(buf));
321 snprintf(buf, 5,
"LPT%d", i);
322 invalidNames.emplace_back(
string(buf));
326 while (valid && (i < invalidNames.size()))
bool isFileNameValid(const std::string &filename)
Checks if the name of the file is valid.
std::vector< std::filesystem::path > getDirectories(const std::filesystem::path &p)
Gets directories of a path.
int compareFileName(const std::string &fn1, const std::string &fn2)
Compares two file names.
std::filesystem::path constructPath(const ArrayString &dirs, const std::string &filename)
Constructs a path from an array of directories and an optional filename.
ArrayString getDirectoriesAsArrayString(const std::filesystem::path &p)
Gets directories of a path.
std::filesystem::path ensureEndsWithPathSeparator(const std::filesystem::path &p)
Ensures the path ends with a path separator.
std::string from_u8string(const std::string &s)
Returns an UTF-8 encoded string in an object of type std::string (C++17).
std::vector< std::string > ArrayString
Array of strings.