Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 5 additions & 7 deletions src/util-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,13 @@
#include <cstring>
#include <locale>
#include <ranges>
#include <regex> // NOLINT(build/c++11)
#include "node_revert.h"
#include "util.h"

#ifdef _WIN32
#include <regex> // NOLINT(build/c++11)
#endif // _WIN32

#define CHAR_TEST(bits, name, expr) \
template <typename T> \
bool name(const T ch) { \
Expand Down Expand Up @@ -588,9 +591,8 @@ constexpr std::string_view FastStringKey::as_string_view() const {
return name_;
}

// Inline so the compiler can fully optimize it away on Unix platforms.
bool IsWindowsBatchFile(const char* filename) {
#ifdef _WIN32
inline bool IsWindowsBatchFile(const char* filename) {
std::string file_with_extension = filename;
// Regex to match the last extension part after the last dot, ignoring
// trailing spaces and dots
Expand All @@ -603,12 +605,8 @@ bool IsWindowsBatchFile(const char* filename) {
}

return !extension.empty() && (extension == "cmd" || extension == "bat");
#else
return false;
#endif // _WIN32
}

#ifdef _WIN32
inline std::wstring ConvertToWideString(const std::string& str,
UINT code_page) {
int size_needed = MultiByteToWideChar(
Expand Down
3 changes: 3 additions & 0 deletions src/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -1026,9 +1026,12 @@ v8::Maybe<int> GetValidFileMode(Environment* env,
v8::Local<v8::Value> input,
uv_fs_type type);

#ifdef _WIN32
// Returns true if OS==Windows and filename ends in .bat or .cmd,
// case insensitive.
inline bool IsWindowsBatchFile(const char* filename);
inline std::wstring ConvertToWideString(const std::string& str, UINT code_page);
#endif // _WIN32

} // namespace node

Expand Down
Loading