예제 #1
0
        public PkgdefRegistryKeyPathSegment(IReadOnlyList <PkgdefToken> tokens)
        {
            PreCondition.AssertNotNullAndNotEmpty(tokens, nameof(tokens));
            PreCondition.AssertEqual(tokens[0].GetTokenType(), PkgdefTokenType.LeftSquareBracket, "tokens[0].GetTokenType()");

            this.tokens = tokens;
        }
        public PkgdefRegistryKeySegment(IReadOnlyList <PkgdefSegment> segments)
        {
            PreCondition.AssertNotNullAndNotEmpty(segments, nameof(segments));
            PreCondition.AssertEqual(segments[0].GetSegmentType(), PkgdefSegmentType.RegistryKeyPath, "segments[0].GetSegmentType()");

            this.segments = segments;
        }
예제 #3
0
        public static void AssertOneOf <T>(T value, IEnumerable <T> possibleValues, string valueName)
        {
            PreCondition.AssertNotNullAndNotEmpty(possibleValues, nameof(possibleValues));

            if (!possibleValues.Contains(value))
            {
                StringBuilder message = new StringBuilder();
                message.Append($"{valueName} ({value}) must be ");

                int possibleValueCount = possibleValues.Count();
                if (possibleValueCount == 1)
                {
                    message.Append(Strings.Escape(possibleValues.First().ToString()));
                }
                else
                {
                    message.Append("either ");
                    if (possibleValueCount == 2)
                    {
                        message.Append($"{Strings.Escape(possibleValues.First().ToString())} ");
                    }
                    else
                    {
                        foreach (T possibleValue in possibleValues.Take(possibleValueCount - 1))
                        {
                            message.Append($"{Strings.Escape(possibleValue.ToString())}, ");
                        }
                    }
                    message.Append($"or {Strings.Escape(possibleValues.Last().ToString())}");
                }
                message.Append('.');

                throw new PreConditionException(message.ToString());
            }
        }
        public PkgdefRegistryKeyDataItemNameSegment(IReadOnlyList <PkgdefToken> tokens)
        {
            PreCondition.AssertNotNullAndNotEmpty(tokens, nameof(tokens));
            PreCondition.AssertOneOf(tokens[0].GetTokenType(), new[] { PkgdefTokenType.AtSign, PkgdefTokenType.DoubleQuote }, "tokens[0].GetTokenType()");

            this.tokens = tokens;
        }
예제 #5
0
        public PkgdefRegistryKeyDataItemSegment(IReadOnlyList <PkgdefToken> tokens)
        {
            PreCondition.AssertNotNullAndNotEmpty(tokens, nameof(tokens));
            PreCondition.AssertOneOf(tokens.First().GetTokenType(), new[] { PkgdefTokenType.AtSign, PkgdefTokenType.DoubleQuote }, "tokens.First().GetTokenType()");

            this.tokens = tokens;

            List <PkgdefToken> nameSegmentTokens = new List <PkgdefToken>()
            {
                tokens[0]
            };

            if (tokens[0].GetTokenType() == PkgdefTokenType.DoubleQuote)
            {
                for (int i = 1; i < tokens.Count; i++)
                {
                    nameSegmentTokens.Add(tokens[i]);
                    if (tokens[i].GetTokenType() == PkgdefTokenType.DoubleQuote)
                    {
                        break;
                    }
                }
            }
            this.nameSegment = new PkgdefRegistryKeyDataItemNameSegment(nameSegmentTokens);
        }
예제 #6
0
        public PkgdefToken(int startIndex, string text, PkgdefTokenType tokenType)
        {
            PreCondition.AssertGreaterThanOrEqualTo(startIndex, 0, nameof(startIndex));
            PreCondition.AssertNotNullAndNotEmpty(text, nameof(text));

            this.startIndex = startIndex;
            this.text       = text;
            this.tokenType  = tokenType;
        }
예제 #7
0
        /// <summary>
        /// Create a new PkgdefIssue object.
        /// </summary>
        /// <param name="startIndex">The character index that the issue starts on.</param>
        /// <param name="length">The number of characters that the issue spans over.</param>
        /// <param name="message">The message that describes the issue.</param>
        public PkgdefIssue(int startIndex, int length, string message)
        {
            PreCondition.AssertGreaterThanOrEqualTo(startIndex, 0, nameof(startIndex));
            PreCondition.AssertGreaterThanOrEqualTo(length, 1, nameof(length));
            PreCondition.AssertNotNullAndNotEmpty(message, nameof(message));

            this.startIndex = startIndex;
            this.length     = length;
            this.message    = message;
        }
예제 #8
0
        internal static PkgdefRegistryKeyDataItemSegment ParseRegistryKeyDataItem(int startIndex, string text)
        {
            PreCondition.AssertGreaterThanOrEqualTo(startIndex, 0, nameof(startIndex));
            PreCondition.AssertNotNullAndNotEmpty(text, nameof(text));
            PreCondition.AssertOneOf(text[0], "@\"", "text[0]");

            Action <PkgdefIssue> onIssue   = PkgdefDocument.IgnoreIssue;
            PkgdefTokenizer      tokenizer = PkgdefTokenizer.Create(startIndex, text, onIssue);

            tokenizer.Next();
            return(PkgdefDocument.ParseRegistryKeyDataItem(tokenizer, onIssue));
        }
예제 #9
0
        public static string GetText(IEnumerable <PkgdefToken> tokens)
        {
            PreCondition.AssertNotNullAndNotEmpty(tokens, nameof(tokens));

            return(string.Join("", tokens.Select(token => token.GetText())));
        }
예제 #10
0
        public static int GetEndIndex(IEnumerable <PkgdefToken> tokens)
        {
            PreCondition.AssertNotNullAndNotEmpty(tokens, nameof(tokens));

            return(PkgdefToken.GetAfterEndIndex(tokens) - 1);
        }
예제 #11
0
        public static int GetStartIndex(IEnumerable <PkgdefToken> tokens)
        {
            PreCondition.AssertNotNullAndNotEmpty(tokens, nameof(tokens));

            return(tokens.First().GetStartIndex());
        }