mirror of
https://github.com/AxioDL/metaforce.git
synced 2025-08-18 08:11:30 +00:00
We can utilize std::char_traits to generically handle the defined character type. Since C++17, std::char_traits' length() function is constexpr, so we can also make StrLen constexpr.
58 lines
1.5 KiB
C++
58 lines
1.5 KiB
C++
#pragma once
|
|
|
|
#ifndef _WIN32
|
|
#include <cstdlib>
|
|
#include <unistd.h>
|
|
#include <sys/stat.h>
|
|
#else
|
|
#ifndef WIN32_LEAN_AND_MEAN
|
|
#define WIN32_LEAN_AND_MEAN 1
|
|
#endif
|
|
#ifndef NOMINMAX
|
|
#define NOMINMAX
|
|
#endif
|
|
#include <cwchar>
|
|
#endif
|
|
#include <string>
|
|
#include <string_view>
|
|
#include <cstring>
|
|
#include <algorithm>
|
|
|
|
namespace hecl {
|
|
|
|
#if _WIN32 && UNICODE
|
|
#define HECL_UCS2 1
|
|
#endif
|
|
|
|
#if HECL_UCS2
|
|
typedef wchar_t SystemChar;
|
|
typedef std::wstring SystemString;
|
|
typedef std::wstring_view SystemStringView;
|
|
static inline void ToLower(SystemString& str) { std::transform(str.begin(), str.end(), str.begin(), towlower); }
|
|
static inline void ToUpper(SystemString& str) { std::transform(str.begin(), str.end(), str.begin(), towupper); }
|
|
#ifndef _SYS_STR
|
|
#define _SYS_STR(val) L##val
|
|
#endif
|
|
typedef struct _stat Sstat;
|
|
#else
|
|
typedef char SystemChar;
|
|
typedef std::string SystemString;
|
|
typedef std::string_view SystemStringView;
|
|
static inline void ToLower(SystemString& str) {
|
|
std::transform(str.begin(), str.end(), str.begin(),
|
|
[](SystemChar c) { return std::tolower(static_cast<unsigned char>(c)); });
|
|
}
|
|
static inline void ToUpper(SystemString& str) {
|
|
std::transform(str.begin(), str.end(), str.begin(),
|
|
[](SystemChar c) { return std::toupper(static_cast<unsigned char>(c)); });
|
|
}
|
|
#ifndef _SYS_STR
|
|
#define _SYS_STR(val) val
|
|
#endif
|
|
typedef struct stat Sstat;
|
|
#endif
|
|
|
|
constexpr size_t StrLen(const SystemChar* str) { return std::char_traits<SystemChar>::length(str); }
|
|
|
|
} // namespace hecl
|