public bool DoCommand(FileInfo file)
        {
            var match =
                Regexp.Match(IncludeExtension
                                        ? file.ChangedFilename
                                        : Path.GetFileNameWithoutExtension(file.ChangedFilename));

            try
            {
                var ext = !IncludeExtension?Path.GetExtension(file.ChangedFilename) : "";

                var group    = match.Groups;
                var groupArr = new object[group.Count];
                for (var i = 0; i < groupArr.Length; i++)
                {
                    groupArr[i] = group[i].Value.Trim();
                }
                file.ChangedFilename = $"{string.Format(FormatString, groupArr)}{ext}";
            }
            catch
            {
                return(false);
            }

            return(true);
        }
Ejemplo n.º 2
0
        public void Scanner_MatchTest()
        {
            byte[] data = new byte[] {
                0x30, 0x34, 0x32, 0x12, 0x55, 0xC3, 0xB8, 0x34, 0x00
            };

            Regexp re = Regexp.Compile(".*55C3");

            Assert.IsTrue(re.Match(data, 0), "Should have matched");
        }
Ejemplo n.º 3
0
        // ---- parse & validate ------------------------

        /// <summary>
        /// Creates a new URI from a string, e.g. `http://www.msft.com/some/path`,
        /// `file:///usr/home`, or `scheme:with/path`.
        ///
        /// @param value A string which represents an URI (see `URI#toString`).
        /// </summary>
        public static DocumentUri Parse(string value, bool strict = false)
        {
            if (string.IsNullOrWhiteSpace(value))
            {
                throw new UriFormatException("Given uri is null or empty");
            }
            var match = Regexp.Match(value);

            if (!match.Success)
            {
                return(new DocumentUri(Empty, Empty, Empty, Empty, Empty));
            }

            return(new DocumentUri(
                       match.Groups[2].Value ?? Empty,
                       PercentDecode(match.Groups[4].Value ?? Empty),
                       PercentDecode(match.Groups[5].Value ?? Empty),
                       PercentDecode(match.Groups[7].Value ?? Empty),
                       PercentDecode(match.Groups[9].Value ?? Empty),
                       strict
                       ));
        }