示例#1
0
        private static void ValidateShareName(ParseContext context, string share, int startOfShare)
        {
            if (string.IsNullOrEmpty(share))
            {
                context.CreateError("UNC path must specify a share.", startOfShare);
            }
            var invalidShareNameCharacterIndex = share.IndexOfAny(invalidShareNameCharacters);

            if (invalidShareNameCharacterIndex >= 0)
            {
                context.CreateError("UNC share name contains invalid characters.", startOfShare + invalidShareNameCharacterIndex);
            }
        }
示例#2
0
        private static void ValidateMachineName(ParseContext context, string machine, int startOfMachine)
        {
            if (string.IsNullOrEmpty(machine))
            {
                throw context.CreateError("UNC machine name must be specified.", startOfMachine);
            }
            var invalidMachineNameCharacterIndex = machine.IndexOfAny(invalidMachineNameCharacters);

            if (invalidMachineNameCharacterIndex >= 0)
            {
                throw context.CreateError("UNC machine name contains invalid characters.", startOfMachine + invalidMachineNameCharacterIndex);
            }
        }
示例#3
0
        private static RootSegment ParseUNCRoot(ParseContext context, out int offset)
        {
            var endOfMachine = context.Pattern.IndexOf(GlobPathTokeniser.SegmentSeparator, 2);

            if (endOfMachine < 0)
            {
                throw context.CreateError("UNC path must specify a share.");
            }

            var machine = context.Pattern.Range(2, endOfMachine);

            ValidateMachineName(context, machine, 2);

            var startOfShare = endOfMachine + 1;
            var endOfShare   = context.Pattern.IndexOf(GlobPathTokeniser.SegmentSeparator, endOfMachine + 1);

            if (endOfShare < 0)
            {
                var share = context.Pattern.RangeFrom(startOfShare).Trim();
                ValidateShareName(context, share, startOfShare);
                // No remaining path. No possibility of repeated separators.
                offset = context.Pattern.Length;
                return(new UNCRootSegment(context.Pattern, machine, share));
            }
            else
            {
                var share = context.Pattern.Range(startOfShare, endOfShare).Trim();
                ValidateShareName(context, share, startOfShare);
                AssertNoRepeatedSeparators(context, endOfShare);
                offset = endOfShare + 1;
                return(new UNCRootSegment(context.Pattern.RangeTo(endOfShare), machine, share));
            }
        }
示例#4
0
        private static void AssertNoRepeatedSeparators(ParseContext context, int start)
        {
            var index = context.Pattern.IndexOf(GlobPathTokeniser.SegmentSeparator, start);

            while (index >= 0)
            {
                var nextIndex = context.Pattern.IndexOf(GlobPathTokeniser.SegmentSeparator, index + 1);
                if (nextIndex == index + 1)
                {
                    throw context.CreateError("Repeated path separators are invalid.", index);
                }
                index = nextIndex;
            }
        }