Permalink
Browse files

path, feat: add path.toNamespacedPath (#375)

  • Loading branch information...
ngot authored and xicilion committed Nov 8, 2017
1 parent fc7b7b9 commit e067af4a1768afcab44c5aaf78a647a7a531b13d
View
@@ -29,6 +29,7 @@ class path_base : public object_base {
static result_t isAbsolute(exlib::string path, bool& retVal);
static result_t join(OptArgs ps, exlib::string& retVal);
static result_t resolve(OptArgs ps, exlib::string& retVal);
static result_t toNamespacedPath(v8::Local<v8::Value> path, v8::Local<v8::Value>& retVal);
static result_t get_sep(exlib::string& retVal);
static result_t get_delimiter(exlib::string& retVal);
static result_t get_posix(v8::Local<v8::Object>& retVal);
@@ -54,6 +55,7 @@ class path_base : public object_base {
static void s_isAbsolute(const v8::FunctionCallbackInfo<v8::Value>& args);
static void s_join(const v8::FunctionCallbackInfo<v8::Value>& args);
static void s_resolve(const v8::FunctionCallbackInfo<v8::Value>& args);
static void s_toNamespacedPath(const v8::FunctionCallbackInfo<v8::Value>& args);
static void s_get_sep(v8::Local<v8::String> property, const v8::PropertyCallbackInfo<v8::Value>& args);
static void s_get_delimiter(v8::Local<v8::String> property, const v8::PropertyCallbackInfo<v8::Value>& args);
static void s_get_posix(v8::Local<v8::String> property, const v8::PropertyCallbackInfo<v8::Value>& args);
@@ -72,7 +74,8 @@ inline ClassInfo& path_base::class_info()
{ "fullpath", s_fullpath, true },
{ "isAbsolute", s_isAbsolute, true },
{ "join", s_join, true },
{ "resolve", s_resolve, true }
{ "resolve", s_resolve, true },
{ "toNamespacedPath", s_toNamespacedPath, true }
};
static ClassData::ClassProperty s_property[] = {
@@ -221,6 +224,22 @@ inline void path_base::s_resolve(const v8::FunctionCallbackInfo<v8::Value>& args
METHOD_RETURN();
}
inline void path_base::s_toNamespacedPath(const v8::FunctionCallbackInfo<v8::Value>& args)
{
v8::Local<v8::Value> vr;
METHOD_NAME("path.toNamespacedPath");
METHOD_ENTER();
METHOD_OVER(1, 0);
OPT_ARG(v8::Local<v8::Value>, 0, v8::Undefined(isolate));
hr = toNamespacedPath(v0, vr);
METHOD_RETURN();
}
inline void path_base::s_get_sep(v8::Local<v8::String> property, const v8::PropertyCallbackInfo<v8::Value>& args)
{
exlib::string vr;
@@ -29,6 +29,7 @@ class path_posix_base : public object_base {
static result_t isAbsolute(exlib::string path, bool& retVal);
static result_t join(OptArgs ps, exlib::string& retVal);
static result_t resolve(OptArgs ps, exlib::string& retVal);
static result_t toNamespacedPath(v8::Local<v8::Value> path, v8::Local<v8::Value>& retVal);
static result_t get_sep(exlib::string& retVal);
static result_t get_delimiter(exlib::string& retVal);
static result_t get_posix(v8::Local<v8::Object>& retVal);
@@ -54,6 +55,7 @@ class path_posix_base : public object_base {
static void s_isAbsolute(const v8::FunctionCallbackInfo<v8::Value>& args);
static void s_join(const v8::FunctionCallbackInfo<v8::Value>& args);
static void s_resolve(const v8::FunctionCallbackInfo<v8::Value>& args);
static void s_toNamespacedPath(const v8::FunctionCallbackInfo<v8::Value>& args);
static void s_get_sep(v8::Local<v8::String> property, const v8::PropertyCallbackInfo<v8::Value>& args);
static void s_get_delimiter(v8::Local<v8::String> property, const v8::PropertyCallbackInfo<v8::Value>& args);
static void s_get_posix(v8::Local<v8::String> property, const v8::PropertyCallbackInfo<v8::Value>& args);
@@ -72,7 +74,8 @@ inline ClassInfo& path_posix_base::class_info()
{ "fullpath", s_fullpath, true },
{ "isAbsolute", s_isAbsolute, true },
{ "join", s_join, true },
{ "resolve", s_resolve, true }
{ "resolve", s_resolve, true },
{ "toNamespacedPath", s_toNamespacedPath, true }
};
static ClassData::ClassProperty s_property[] = {
@@ -221,6 +224,22 @@ inline void path_posix_base::s_resolve(const v8::FunctionCallbackInfo<v8::Value>
METHOD_RETURN();
}
inline void path_posix_base::s_toNamespacedPath(const v8::FunctionCallbackInfo<v8::Value>& args)
{
v8::Local<v8::Value> vr;
METHOD_NAME("path_posix.toNamespacedPath");
METHOD_ENTER();
METHOD_OVER(1, 0);
OPT_ARG(v8::Local<v8::Value>, 0, v8::Undefined(isolate));
hr = toNamespacedPath(v0, vr);
METHOD_RETURN();
}
inline void path_posix_base::s_get_sep(v8::Local<v8::String> property, const v8::PropertyCallbackInfo<v8::Value>& args)
{
exlib::string vr;
@@ -29,6 +29,7 @@ class path_win32_base : public object_base {
static result_t isAbsolute(exlib::string path, bool& retVal);
static result_t join(OptArgs ps, exlib::string& retVal);
static result_t resolve(OptArgs ps, exlib::string& retVal);
static result_t toNamespacedPath(v8::Local<v8::Value> path, v8::Local<v8::Value>& retVal);
static result_t get_sep(exlib::string& retVal);
static result_t get_delimiter(exlib::string& retVal);
static result_t get_posix(v8::Local<v8::Object>& retVal);
@@ -54,6 +55,7 @@ class path_win32_base : public object_base {
static void s_isAbsolute(const v8::FunctionCallbackInfo<v8::Value>& args);
static void s_join(const v8::FunctionCallbackInfo<v8::Value>& args);
static void s_resolve(const v8::FunctionCallbackInfo<v8::Value>& args);
static void s_toNamespacedPath(const v8::FunctionCallbackInfo<v8::Value>& args);
static void s_get_sep(v8::Local<v8::String> property, const v8::PropertyCallbackInfo<v8::Value>& args);
static void s_get_delimiter(v8::Local<v8::String> property, const v8::PropertyCallbackInfo<v8::Value>& args);
static void s_get_posix(v8::Local<v8::String> property, const v8::PropertyCallbackInfo<v8::Value>& args);
@@ -72,7 +74,8 @@ inline ClassInfo& path_win32_base::class_info()
{ "fullpath", s_fullpath, true },
{ "isAbsolute", s_isAbsolute, true },
{ "join", s_join, true },
{ "resolve", s_resolve, true }
{ "resolve", s_resolve, true },
{ "toNamespacedPath", s_toNamespacedPath, true }
};
static ClassData::ClassProperty s_property[] = {
@@ -221,6 +224,22 @@ inline void path_win32_base::s_resolve(const v8::FunctionCallbackInfo<v8::Value>
METHOD_RETURN();
}
inline void path_win32_base::s_toNamespacedPath(const v8::FunctionCallbackInfo<v8::Value>& args)
{
v8::Local<v8::Value> vr;
METHOD_NAME("path_win32.toNamespacedPath");
METHOD_ENTER();
METHOD_OVER(1, 0);
OPT_ARG(v8::Local<v8::Value>, 0, v8::Undefined(isolate));
hr = toNamespacedPath(v0, vr);
METHOD_RETURN();
}
inline void path_win32_base::s_get_sep(v8::Local<v8::String> property, const v8::PropertyCallbackInfo<v8::Value>& args)
{
exlib::string vr;
View
@@ -588,6 +588,18 @@ inline result_t _resolve_win32(OptArgs ps, exlib::string& retVal)
return _normalize_win32(p.str(), retVal, true);
}
inline result_t _resolve_win32(exlib::string& path)
{
exlib::string str;
process_base::cwd(str);
Path p;
p.resolveWin32(str);
p.resolveWin32(path);
return _normalize_win32(p.str(), path, true);
}
inline result_t _sep(exlib::string& retVal)
{
retVal.assign(1, PATH_SLASH);
@@ -55,6 +55,13 @@ result_t path_posix_base::resolve(OptArgs ps, exlib::string& retVal)
return _resolve(ps, retVal);
}
result_t path_posix_base::toNamespacedPath(v8::Local<v8::Value> path,
v8::Local<v8::Value>& retVal)
{
retVal = path;
return 0;
}
result_t path_posix_base::get_sep(exlib::string& retVal)
{
retVal.assign(1, PATH_SLASH_POSIX);
@@ -68,6 +68,41 @@ result_t path_win32_base::resolve(OptArgs ps, exlib::string& retVal)
return _resolve_win32(ps, retVal);
}
result_t path_win32_base::toNamespacedPath(v8::Local<v8::Value> path,
v8::Local<v8::Value>& retVal)
{
if (!path->IsString()) {
retVal = path;
return 0;
}
exlib::string str;
GetArgumentValue(path, str);
if (str.length() >= 3) {
Isolate* isolate = Isolate::current();
result_t hr = _resolve_win32(str);
if (hr < 0)
return hr;
if (str[0] == '\\' && str[1] == '\\') {
if (str[2] != '?' && str[2] != '.') {
str = "\\\\?\\UNC" + str.substr(1);
retVal = GetReturnValue(isolate->m_isolate, str);
return 0;
}
} else if (qisascii(str[0])) {
if (str[1] == ':' && str[2] == '\\') {
str = "\\\\?\\" + str.substr(0);
retVal = GetReturnValue(isolate->m_isolate, str);
return 0;
}
}
}
retVal = path;
return 0;
}
result_t path_win32_base::get_sep(exlib::string& retVal)
{
retVal.assign(1, PATH_SLASH_WIN32);
View
@@ -58,6 +58,13 @@ module path
*/
static String resolve(...);
/*! @brief returns an equivalent namespace-prefixed path for the given path.Only available on Windows.
see: https://msdn.microsoft.com/library/windows/desktop/aa365247(v=vs.85).aspx#namespaces
@param path given path.
@return new path.
*/
static Value toNamespacedPath(Value path = undefined);
/*! @brief Get system directory separator, posix returns '/', windows returns '\\'
*/
static readonly String sep;
View
@@ -0,0 +1,75 @@
/*! @brief File path module
To use it:
@code
var path = require('path');
@endcode
*/
module path_posix
{
/*! @brief Normalize path
@param path Original path
@return Return normalized path
*/
static String normalize(String path);
/*! @brief Get file name in path, ignore extension with file has it
@param path Original path
@param ext Given extension
@return Return file name
*/
static String basename(String path, String ext = "");
/*! @brief Get file extension
@param path Original path
@return Return file extension
*/
static String extname(String path);
/*! @brief Get directory in path
@param path Original path
@return Return directory
*/
static String dirname(String path);
/*! @brief Get full path
@param path Original path
@return Return full path
*/
static String fullpath(String path);
/*! @brief Merge multiple paths to a single relative path
@param ... One or more relative paths
@return Return new relative path
*/
static String join(...);
/*! @brief Merge multiple paths to a single absolute path
@param ... One or more relative paths
@return Return new absolute path
*/
static String resolve(...);
/*! @brief returns an equivalent namespace-prefixed path for the given path.Only available on Windows.
see: https://msdn.microsoft.com/library/windows/desktop/aa365247(v=vs.85).aspx#namespaces
@param path given path.
@return new path.
*/
static Value toNamespacedPath(Value path = undefined);
/*! @brief Get system directory separator, posix returns '/', windows returns '\\'
*/
static readonly String sep;
/*! @brief Get system path delimiter, posix returns ':', windows returns ';'
*/
static readonly String delimiter;
};
View
@@ -0,0 +1,75 @@
/*! @brief File path module
To use it:
@code
var path = require('path');
@endcode
*/
module path_win32
{
/*! @brief Normalize path
@param path Original path
@return Return normalized path
*/
static String normalize(String path);
/*! @brief Get file name in path, ignore extension with file has it
@param path Original path
@param ext Given extension
@return Return file name
*/
static String basename(String path, String ext = "");
/*! @brief Get file extension
@param path Original path
@return Return file extension
*/
static String extname(String path);
/*! @brief Get directory in path
@param path Original path
@return Return directory
*/
static String dirname(String path);
/*! @brief Get full path
@param path Original path
@return Return full path
*/
static String fullpath(String path);
/*! @brief Merge multiple paths to a single relative path
@param ... One or more relative paths
@return Return new relative path
*/
static String join(...);
/*! @brief Merge multiple paths to a single absolute path
@param ... One or more relative paths
@return Return new absolute path
*/
static String resolve(...);
/*! @brief returns an equivalent namespace-prefixed path for the given path.Only available on Windows.
see: https://msdn.microsoft.com/library/windows/desktop/aa365247(v=vs.85).aspx#namespaces
@param path given path.
@return new path.
*/
static Value toNamespacedPath(Value path = undefined);
/*! @brief Get system directory separator, posix returns '/', windows returns '\\'
*/
static readonly String sep;
/*! @brief Get system path delimiter, posix returns ':', windows returns ';'
*/
static readonly String delimiter;
};
Oops, something went wrong.

0 comments on commit e067af4

Please sign in to comment.