public static MutableString /*!*/ ExpandPath(RubyContext /*!*/ context, RubyClass /*!*/ self, [DefaultProtocol, NotNull] MutableString /*!*/ path, [DefaultProtocol, Optional] MutableString basePath) { // We ignore basePath parameter if first string starts with a ~ if (basePath == null || path.GetFirstChar() == '~') { return(ExpandPath(context, path)); } else { return(Glob.CanonicalizePath(MutableString.Create( Path.GetFullPath(Path.Combine(ExpandPath(context, basePath).ConvertToString(), path.ConvertToString())) ))); } }
public static MutableString /*!*/ Basename(RubyClass /*!*/ self, [DefaultProtocol, NotNull] MutableString /*!*/ path, [DefaultProtocol, NotNull, Optional] MutableString extensionFilter) { if (path.IsEmpty) { return(path); } MutableString trimmedPath = TrimTrailingSlashes(path); // Special cases of drive letters C:\\ or C:/ if (trimmedPath.Length == 2) { if (Char.IsLetter(trimmedPath.GetChar(0)) && trimmedPath.GetChar(1) == ':') { var result = (path.Length > 2 ? MutableString.Create(path.GetChar(2).ToString()) : MutableString.CreateMutable()); return(result.TaintBy(path)); } } string trimmedPathAsString = trimmedPath.ConvertToString(); if (trimmedPathAsString == "/") { return(trimmedPath); } string filename = Path.GetFileName(trimmedPath.ConvertToString()); // Handle UNC host names correctly string root = Path.GetPathRoot(trimmedPath.ConvertToString()); if (MutableString.IsNullOrEmpty(extensionFilter)) { return(MutableString.Create(trimmedPathAsString == root ? root : filename)); } string fileExtension = Path.GetExtension(filename); string basename = Path.GetFileNameWithoutExtension(filename); string strResult = WildcardExtensionMatch(fileExtension, extensionFilter.ConvertToString()) ? basename : filename; return(Glob.CanonicalizePath(MutableString.Create(strResult)).TaintBy(path)); }
private void ExpandArgument(RubyArray /*!*/ args, string /*!*/ arg, RubyEncoding /*!*/ encoding) { if (arg.IndexOf('*') != -1 || arg.IndexOf('?') != -1) { bool added = false; foreach (string path in Glob.GetMatches(_context.DomainManager.Platform, arg, 0)) { args.Add(MutableString.Create(path, encoding)); added = true; } if (!added) { args.Add(MutableString.Create(arg, encoding)); } } else { args.Add(MutableString.Create(arg, encoding)); } }
private void ExpandArgument(RubyArray /*!*/ args, string /*!*/ arg) { if (arg.IndexOf('*') != -1 || arg.IndexOf('?') != -1) { bool added = false; foreach (string path in Glob.GlobResults(_context, arg, 0)) { args.Add(MutableString.Create(path)); added = true; } if (!added) { args.Add(MutableString.Create(arg)); } } else { args.Add(MutableString.Create(arg)); } }
public static MutableString /*!*/ DirName(RubyClass /*!*/ self, MutableString /*!*/ path) { string directoryName = path.ConvertToString(); if (IsValidPath(path.ConvertToString())) { directoryName = Path.GetDirectoryName(path.ConvertToString()); string fileName = Path.GetFileName(path.ConvertToString()); if (!String.IsNullOrEmpty(fileName)) { directoryName = StripPathCharacters(path.ConvertToString().Replace(fileName, "")); } } else { if (directoryName.Length > 1) { directoryName = "//"; } } return(Glob.CanonicalizePath(MutableString.Create(String.IsNullOrEmpty(directoryName) ? "." : directoryName))); }
public static bool FnMatch(object /*!*/ self, [NotNull] MutableString /*!*/ pattern, [NotNull] MutableString /*!*/ path, [Optional] int flags) { return(Glob.FnMatch(pattern, path, flags)); }