Patch 8.2.4838
Problem: Checking for absolute path is not trivial.
Solution: Add isabsolutepath(). (closes #10303)
Files: runtime/doc/builtin.txt, runtime/doc/usr_41.txt, src/evalfunc.c,
src/filepath.c, src/proto/filepath.pro,
src/testdir/test_functions.vim
*** ../vim-8.2.4837/runtime/doc/builtin.txt 2022-04-25 14:37:42.406308494
+0100
--- runtime/doc/builtin.txt 2022-04-28 15:21:04.203128360 +0100
***************
*** 295,300 ****
--- 295,301 ----
insert({object}, {item} [, {idx}]) List insert {item} in {object}
[before {idx}]
interrupt() none interrupt script execution
invert({expr}) Number bitwise invert
+ isabsolutepath({path}) Number |TRUE| if {path} is an absolute
path
isdirectory({directory}) Number |TRUE| if {directory} is a directory
isinf({expr}) Number determine if {expr} is infinity value
(positive or negative)
***************
*** 4657,4662 ****
--- 4673,4696 ----
< Can also be used as a |method|: >
:let bits = bits->invert()
+ isabsolutepath({directory}) *isabsolutepath()*
+ The result is a Number, which is |TRUE| when {path} is an
+ absolute path.
+ < On Unix, a path is considered absolute when it starts with '/'.
+ On MS-Windows, it is considered absolute when it starts with an
+ optional drive prefix and is followed by a '\' or '/'. UNC paths
+ are always absolute.
+ Example: >
+ echo isabsolutepath('/usr/share/') " 1
+ echo isabsolutepath('./foobar') " 0
+ echo isabsolutepath('C:\Windows') " 1
+ echo isabsolutepath('foobar') " 0
+ echo isabsolutepath('\\remote\file') " 1
+
+ Can also be used as a |method|: >
+ GetName()->isabsolutepath()
+
+
isdirectory({directory}) *isdirectory()*
The result is a Number, which is |TRUE| when a directory
with the name {directory} exists. If {directory} doesn't
*** ../vim-8.2.4837/runtime/doc/usr_41.txt 2022-04-25 14:37:42.406308494
+0100
--- runtime/doc/usr_41.txt 2022-04-28 15:21:04.203128360 +0100
***************
*** 813,818 ****
--- 904,910 ----
getfperm() get the permissions of a file
setfperm() set the permissions of a file
getftype() get the kind of a file
+ isabsolutepath() check if a path is absolute
isdirectory() check if a directory exists
getfsize() get the size of a file
getcwd() get the current working directory
*** ../vim-8.2.4837/src/evalfunc.c 2022-04-25 14:37:42.410308492 +0100
--- src/evalfunc.c 2022-04-28 15:21:04.203128360 +0100
***************
*** 1969,1974 ****
--- 1969,1976 ----
ret_void, f_interrupt},
{"invert", 1, 1, FEARG_1, arg1_number,
ret_number, f_invert},
+ {"isabsolutepath", 1, 1, FEARG_1, arg1_string,
+ ret_number_bool, f_isabsolutepath},
{"isdirectory", 1, 1, FEARG_1, arg1_string,
ret_number_bool, f_isdirectory},
{"isinf", 1, 1, FEARG_1, arg1_float_or_nr,
*** ../vim-8.2.4837/src/filepath.c 2022-04-04 15:16:50.738014123 +0100
--- src/filepath.c 2022-04-28 15:21:04.203128360 +0100
***************
*** 1417,1422 ****
--- 1417,1434 ----
}
/*
+ * "isabsolutepath()" function
+ */
+ void
+ f_isabsolutepath(typval_T *argvars, typval_T *rettv)
+ {
+ if (in_vim9script() && check_for_string_arg(argvars, 0) == FAIL)
+ return;
+
+ rettv->vval.v_number = mch_isFullName(tv_get_string_strict(&argvars[0]));
+ }
+
+ /*
* Create the directory in which "dir" is located, and higher levels when
* needed.
* Return OK or FAIL.
*** ../vim-8.2.4837/src/proto/filepath.pro 2022-03-31 11:37:54.259367941
+0100
--- src/proto/filepath.pro 2022-04-28 15:21:04.203128360 +0100
***************
*** 22,27 ****
--- 22,28 ----
void f_glob2regpat(typval_T *argvars, typval_T *rettv);
void f_globpath(typval_T *argvars, typval_T *rettv);
void f_isdirectory(typval_T *argvars, typval_T *rettv);
+ void f_isabsolutepath(typval_T *argvars, typval_T *rettv);
void f_mkdir(typval_T *argvars, typval_T *rettv);
void f_pathshorten(typval_T *argvars, typval_T *rettv);
void f_readdir(typval_T *argvars, typval_T *rettv);
*** ../vim-8.2.4837/src/testdir/test_functions.vim 2022-04-05
15:30:56.312425624 +0100
--- src/testdir/test_functions.vim 2022-04-28 15:21:04.207128357 +0100
***************
*** 2887,2891 ****
--- 2887,2909 ----
call assert_equal("function('g:Test_funcref_to_string')", string(Fn))
endfunc
+ " Test for isabsolutepath()
+ func Test_isabsolutepath()
+ call assert_false(isabsolutepath(''))
+ call assert_false(isabsolutepath('.'))
+ call assert_false(isabsolutepath('../Foo'))
+ call assert_false(isabsolutepath('Foo/'))
+ if has('win32')
+ call assert_true(isabsolutepath('A:\'))
+ call assert_true(isabsolutepath('A:\Foo'))
+ call assert_true(isabsolutepath('A:/Foo'))
+ call assert_false(isabsolutepath('A:Foo'))
+ call assert_false(isabsolutepath('\Windows'))
+ call assert_true(isabsolutepath('\\Server2\Share\Test\Foo.txt'))
+ else
+ call assert_true(isabsolutepath('/'))
+ call assert_true(isabsolutepath('/usr/share/'))
+ endif
+ endfunc
" vim: shiftwidth=2 sts=2 expandtab
*** ../vim-8.2.4837/src/version.c 2022-04-28 14:09:56.075947128 +0100
--- src/version.c 2022-04-28 15:23:38.099059585 +0100
***************
*** 748,749 ****
--- 748,751 ----
{ /* Add new patch number below this line */
+ /**/
+ 4838,
/**/
--
Ed's Radiator Shop: The Best Place in Town to Take a Leak.
/// Bram Moolenaar -- [email protected] -- http://www.Moolenaar.net \\\
/// \\\
\\\ sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///
--
--
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
---
You received this message because you are subscribed to the Google Groups
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/vim_dev/20220428142722.A5AA31C1606%40moolenaar.net.