public static bool TryParse(string value, out POReferenceComment result) { if (value == null) { throw new ArgumentNullException(nameof(value)); } var withinQuotes = false; IEnumerable <string> parts = value .Split(c => { if (c == '"') { withinQuotes = !withinQuotes; } return(!withinQuotes && char.IsWhiteSpace(c)); }, StringSplitOptions.RemoveEmptyEntries) .Select(p => p.Trim()); var references = new List <POSourceReference>(); foreach (var part in parts) { if (POSourceReference.TryParse(part, out POSourceReference reference)) { references.Add(reference); } else { result = null; return(false); } } result = new POReferenceComment { References = references }; return(true); }
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); }