Esempio n. 1
0
        public static bool TryParse(string value, out POPreviousValueComment result)
        {
            if (value == null)
            {
                throw new ArgumentNullException(nameof(value));
            }

            string idKindToken = null;

            value = value.Trim();
            var index = value.FindIndex(char.IsWhiteSpace);

            if (index >= 0)
            {
                idKindToken = value.Remove(index);
                value       = value.Substring(index + 1).TrimStart();
            }

            int           length;
            POIdKind      idKind;
            StringBuilder sb;

            if (index < 0 ||
                (length = value.Length) < 2 || value[0] != '"' || value[length - 1] != '"' ||
                (idKind = POKey.GetIdKind(idKindToken)) == POIdKind.Unknown ||
                POString.Decode(sb = new StringBuilder(), value, 1, length - 2) >= 0)
            {
                result = null;
                return(false);
            }

            result = new POPreviousValueComment {
                IdKind = idKind, Value = sb.ToString()
            };
            return(true);
        }
Esempio n. 2
0
 public static bool TryParse(string value, POStringDecodingOptions options, out POPreviousValueComment result)
 {
     return(TryParse(value, POString.NewLine(options?.KeepKeyStringsPlatformIndependent ?? false), out result));
 }
Esempio n. 3
0
        private List <POComment> ParseComments()
        {
            var result = new List <POComment>();

            KeyValuePair <TextLocation, string> commentKvp;
            string comment;
            int    commentLength;
            var    n = _commentBuffer.Count;

            for (var i = 0; i < n; i++)
            {
                if ((commentLength = (comment = (commentKvp = _commentBuffer[i]).Value).Length) > 0)
                {
                    var           index = 0;
                    var           c     = comment[index++];
                    POCommentKind kind;
                    switch (c)
                    {
                    case '.': kind = POCommentKind.Extracted; break;

                    case ':': kind = POCommentKind.Reference; break;

                    case ',': kind = POCommentKind.Flags; break;

                    case '|': kind = POCommentKind.PreviousValue; break;

                    default:
                        if (char.IsWhiteSpace(c))
                        {
                            kind = POCommentKind.Translator;
                            break;
                        }
                        else
                        {
                            continue;
                        }
                    }

                    if (kind != POCommentKind.Translator &&
                        (index >= commentLength || !char.IsWhiteSpace(comment[index++])))
                    {
                        continue;
                    }

                    comment = comment.Substring(index);
                    switch (kind)
                    {
                    case POCommentKind.Translator:
                        result.Add(new POTranslatorComment {
                            Text = comment.Trim()
                        });
                        break;

                    case POCommentKind.Extracted:
                        result.Add(new POExtractedComment {
                            Text = comment.Trim()
                        });
                        break;

                    case POCommentKind.Reference:
                        if (POReferenceComment.TryParse(comment, out POReferenceComment referenceComment))
                        {
                            result.Add(referenceComment);
                        }
                        else
                        {
                            AddWarning(DiagnosticCodes.MalformedComment, commentKvp.Key);
                        }
                        break;

                    case POCommentKind.Flags:
                        result.Add(POFlagsComment.Parse(comment));
                        break;

                    case POCommentKind.PreviousValue:
                        if (POPreviousValueComment.TryParse(comment, out POPreviousValueComment previousValueComment))
                        {
                            result.Add(previousValueComment);
                        }
                        else
                        {
                            AddWarning(DiagnosticCodes.MalformedComment, commentKvp.Key);
                        }
                        break;
                    }
                }
            }

            return(result);
        }
Esempio n. 4
0
 public static bool TryParse(string value, out POPreviousValueComment result)
 {
     return(TryParse(value, (POStringDecodingOptions)null, out result));
 }