4545#include " itertools.hh"
4646#include " lnav_log.hh"
4747#include " opt_util.hh"
48+ #include " pcrepp/pcre2pp.hh"
4849#include " scn/scan.h"
4950#include " short_alloc.h"
5051
@@ -147,6 +148,9 @@ escape_path(const std::filesystem::path& p, path_type pt)
147148 case ' ?' :
148149 switch (pt) {
149150 case path_type::normal:
151+ case path_type::windows:
152+ case path_type::remote:
153+ case path_type::url:
150154 retval.push_back (' \\ ' );
151155 break ;
152156 case path_type::pattern:
@@ -162,6 +166,59 @@ escape_path(const std::filesystem::path& p, path_type pt)
162166 return retval;
163167}
164168
169+ bool
170+ is_url (const std::string& fn)
171+ {
172+ static const auto url_re
173+ = lnav::pcre2pp::code::from_const (" ^(file|https?|ftps?|scp|sftp):.*" );
174+
175+ return url_re.find_in (fn).ignore_error ().has_value ();
176+ }
177+
178+ path_type
179+ determine_path_type (const std::string& arg)
180+ {
181+ if (is_glob (arg)) {
182+ return path_type::pattern;
183+ }
184+
185+ if (is_url (arg)) {
186+ return path_type::url;
187+ }
188+
189+ switch (arg.find (' :' )) {
190+ case 0 :
191+ return path_type::normal;
192+ case 1 :
193+ return path_type::windows;
194+ default :
195+ return path_type::remote;
196+ }
197+ }
198+
199+ std::filesystem::path
200+ to_posix_path (std::string arg)
201+ {
202+ if (cget (arg, 1 ).value_or (' \0 ' ) != ' :' ) {
203+ return {arg};
204+ }
205+
206+ switch (cget (arg, 2 ).value_or (' \0 ' )) {
207+ case ' \\ ' :
208+ case ' /' :
209+ arg.erase (1 , 1 );
210+ break ;
211+ default :
212+ arg[1 ] = ' /' ;
213+ break ;
214+ }
215+
216+ arg.insert (arg.begin (), ' /' );
217+ std::replace (arg.begin (), arg.end (), ' \\ ' , ' /' );
218+
219+ return {arg};
220+ }
221+
165222std::pair<std::string, file_location_t >
166223split_file_location (const std::string& file_path_str)
167224{
0 commit comments