Exemplo n.º 1
0
        /// <summary>
        /// Helper function to parse the Localization.Comments value into multiple pairs
        /// </summary>
        /// <param name="input">content of Localization.Comments</param>
        internal static PropertyComment[] ParsePropertyComments(string input)
        {
            //
            // Localization comments consist of repeating "[PropertyName]([Value])"
            // e.g. $Content (abc) FontSize(def)
            //
            if (input == null) return null;

            List<PropertyComment> tokens  = new List<PropertyComment>(8);
            StringBuilder tokenBuffer = new StringBuilder();
            PropertyComment currentPair   = new PropertyComment();
            bool escaped              = false;

            for (int i = 0; i < input.Length; i++)
            {
                if (currentPair.PropertyName == null)
                {
                    // parsing "PropertyName" section
                    if (Char.IsWhiteSpace(input[i]) && !escaped)
                    {
                        if (tokenBuffer.Length > 0)
                        {
                            // terminate the PropertyName by an unesacped whitespace
                            currentPair.PropertyName = tokenBuffer.ToString();
                            tokenBuffer        = new StringBuilder();
                        }

                        // else ignore whitespace at the beginning of the PropertyName name
                    }
                    else
                    {
                        if (input[i] == CommentStart && !escaped)
                        {
                            if (i > 0)
                            {
                                // terminate the PropertyName by an unescaped CommentStart char
                                currentPair.PropertyName = tokenBuffer.ToString();
                                tokenBuffer = new StringBuilder();
                                i--; // put back this char and continue
                            }
                            else
                            {

                                // can't begin with unescaped comment start char.
                                throw new FormatException(SR.Get(SRID.InvalidLocCommentTarget, input));
                            }
                        }
                        else if (input[i] == EscapeChar && !escaped)
                        {
                            escaped = true;
                        }
                        else
                        {
                            tokenBuffer.Append(input[i]);
                            escaped = false;
                        }
                    }
                }
                else
                {
                    // parsing the "Value" part
                    if (tokenBuffer.Length == 0)
                    {
                        if (input[i] == CommentStart && !escaped)
                        {
                            // comment must begin with unescaped CommentStart
                            tokenBuffer.Append(input[i]);
                            escaped = false;
                        }
                        else if (!Char.IsWhiteSpace(input[i]))
                        {
                            // else, only white space is allows before an unescaped comment start char
                            throw new FormatException(SR.Get(SRID.InvalidLocCommentValue, currentPair.PropertyName, input));
                        }
                    }
                    else
                    {
                        // inside the comment
                        if (input[i] == CommentEnd)
                        {
                            if (!escaped)
                            {
                                // terminated by unescaped Comment
                                currentPair.Value = tokenBuffer.ToString().Substring(1);
                                tokens.Add(currentPair);
                                tokenBuffer = new StringBuilder();
                                currentPair = new PropertyComment();
                            }
                            else
                            {
                                // continue on escaped end char
                                tokenBuffer.Append(input[i]);
                                escaped = false;
                            }
                        }
                        else if (input[i] == CommentStart && !escaped)
                        {
                            // throw if there is unescape start in comment
                            throw new FormatException(SR.Get(SRID.InvalidLocCommentValue, currentPair.PropertyName, input));
                        }
                        else
                        {
                            // comment
                            if (input[i] == EscapeChar && !escaped)
                            {
                                escaped = true;
                            }
                            else
                            {
                                tokenBuffer.Append(input[i]);
                                escaped = false;
                            }
                        }
                    }
                }
            }

            if (currentPair.PropertyName != null || tokenBuffer.Length != 0)
            {
                // unmatched PropertyName and Value pair
                throw new FormatException(SR.Get(SRID.UnmatchedLocComment, input));
            }

            return tokens.ToArray();
        }
        // Token: 0x06006EC0 RID: 28352 RVA: 0x001FD5B8 File Offset: 0x001FB7B8
        internal static PropertyComment[] ParsePropertyComments(string input)
        {
            if (input == null)
            {
                return(null);
            }
            List <PropertyComment> list            = new List <PropertyComment>(8);
            StringBuilder          stringBuilder   = new StringBuilder();
            PropertyComment        propertyComment = new PropertyComment();
            bool flag = false;

            for (int i = 0; i < input.Length; i++)
            {
                if (propertyComment.PropertyName == null)
                {
                    if (char.IsWhiteSpace(input[i]) && !flag)
                    {
                        if (stringBuilder.Length > 0)
                        {
                            propertyComment.PropertyName = stringBuilder.ToString();
                            stringBuilder = new StringBuilder();
                        }
                    }
                    else if (input[i] == '(' && !flag)
                    {
                        if (i <= 0)
                        {
                            throw new FormatException(SR.Get("InvalidLocCommentTarget", new object[]
                            {
                                input
                            }));
                        }
                        propertyComment.PropertyName = stringBuilder.ToString();
                        stringBuilder = new StringBuilder();
                        i--;
                    }
                    else if (input[i] == '\\' && !flag)
                    {
                        flag = true;
                    }
                    else
                    {
                        stringBuilder.Append(input[i]);
                        flag = false;
                    }
                }
                else if (stringBuilder.Length == 0)
                {
                    if (input[i] == '(' && !flag)
                    {
                        stringBuilder.Append(input[i]);
                        flag = false;
                    }
                    else if (!char.IsWhiteSpace(input[i]))
                    {
                        throw new FormatException(SR.Get("InvalidLocCommentValue", new object[]
                        {
                            propertyComment.PropertyName,
                            input
                        }));
                    }
                }
                else if (input[i] == ')')
                {
                    if (!flag)
                    {
                        propertyComment.Value = stringBuilder.ToString().Substring(1);
                        list.Add(propertyComment);
                        stringBuilder   = new StringBuilder();
                        propertyComment = new PropertyComment();
                    }
                    else
                    {
                        stringBuilder.Append(input[i]);
                        flag = false;
                    }
                }
                else
                {
                    if (input[i] == '(' && !flag)
                    {
                        throw new FormatException(SR.Get("InvalidLocCommentValue", new object[]
                        {
                            propertyComment.PropertyName,
                            input
                        }));
                    }
                    if (input[i] == '\\' && !flag)
                    {
                        flag = true;
                    }
                    else
                    {
                        stringBuilder.Append(input[i]);
                        flag = false;
                    }
                }
            }
            if (propertyComment.PropertyName != null || stringBuilder.Length != 0)
            {
                throw new FormatException(SR.Get("UnmatchedLocComment", new object[]
                {
                    input
                }));
            }
            return(list.ToArray());
        }
Exemplo n.º 3
0
        /// <summary>
        /// Helper function to parse the Localization.Comments value into multiple pairs
        /// </summary>
        /// <param name="input">content of Localization.Comments</param>
        internal static PropertyComment[] ParsePropertyComments(string input)
        {
            //
            // Localization comments consist of repeating "[PropertyName]([Value])"
            // e.g. $Content (abc) FontSize(def)
            //
            if (input == null)
            {
                return(null);
            }

            List <PropertyComment> tokens      = new List <PropertyComment>(8);
            StringBuilder          tokenBuffer = new StringBuilder();
            PropertyComment        currentPair = new PropertyComment();
            bool escaped = false;

            for (int i = 0; i < input.Length; i++)
            {
                if (currentPair.PropertyName == null)
                {
                    // parsing "PropertyName" section
                    if (Char.IsWhiteSpace(input[i]) && !escaped)
                    {
                        if (tokenBuffer.Length > 0)
                        {
                            // terminate the PropertyName by an unesacped whitespace
                            currentPair.PropertyName = tokenBuffer.ToString();
                            tokenBuffer = new StringBuilder();
                        }

                        // else ignore whitespace at the beginning of the PropertyName name
                    }
                    else
                    {
                        if (input[i] == CommentStart && !escaped)
                        {
                            if (i > 0)
                            {
                                // terminate the PropertyName by an unescaped CommentStart char
                                currentPair.PropertyName = tokenBuffer.ToString();
                                tokenBuffer = new StringBuilder();
                                i--; // put back this char and continue
                            }
                            else
                            {
                                // can't begin with unescaped comment start char.
                                throw new FormatException(SR.Get(SRID.InvalidLocCommentTarget, input));
                            }
                        }
                        else if (input[i] == EscapeChar && !escaped)
                        {
                            escaped = true;
                        }
                        else
                        {
                            tokenBuffer.Append(input[i]);
                            escaped = false;
                        }
                    }
                }
                else
                {
                    // parsing the "Value" part
                    if (tokenBuffer.Length == 0)
                    {
                        if (input[i] == CommentStart && !escaped)
                        {
                            // comment must begin with unescaped CommentStart
                            tokenBuffer.Append(input[i]);
                            escaped = false;
                        }
                        else if (!Char.IsWhiteSpace(input[i]))
                        {
                            // else, only white space is allows before an unescaped comment start char
                            throw new FormatException(SR.Get(SRID.InvalidLocCommentValue, currentPair.PropertyName, input));
                        }
                    }
                    else
                    {
                        // inside the comment
                        if (input[i] == CommentEnd)
                        {
                            if (!escaped)
                            {
                                // terminated by unescaped Comment
                                currentPair.Value = tokenBuffer.ToString().Substring(1);
                                tokens.Add(currentPair);
                                tokenBuffer = new StringBuilder();
                                currentPair = new PropertyComment();
                            }
                            else
                            {
                                // continue on escaped end char
                                tokenBuffer.Append(input[i]);
                                escaped = false;
                            }
                        }
                        else if (input[i] == CommentStart && !escaped)
                        {
                            // throw if there is unescape start in comment
                            throw new FormatException(SR.Get(SRID.InvalidLocCommentValue, currentPair.PropertyName, input));
                        }
                        else
                        {
                            // comment
                            if (input[i] == EscapeChar && !escaped)
                            {
                                escaped = true;
                            }
                            else
                            {
                                tokenBuffer.Append(input[i]);
                                escaped = false;
                            }
                        }
                    }
                }
            }

            if (currentPair.PropertyName != null || tokenBuffer.Length != 0)
            {
                // unmatched PropertyName and Value pair
                throw new FormatException(SR.Get(SRID.UnmatchedLocComment, input));
            }

            return(tokens.ToArray());
        }