示例#1
0
 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()))
                                          )));
     }
 }
示例#2
0
        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));
        }
示例#3
0
        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));
            }
        }
示例#4
0
        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));
            }
        }
示例#5
0
        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)));
        }
示例#6
0
 public static bool FnMatch(object /*!*/ self, [NotNull] MutableString /*!*/ pattern, [NotNull] MutableString /*!*/ path, [Optional] int flags)
 {
     return(Glob.FnMatch(pattern, path, flags));
 }