Beispiel #1
0
        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);
        }
Beispiel #2
0
        public static bool TryParse(string value, out POSourceReference result)
        {
            if (value == null)
            {
                throw new ArgumentNullException(nameof(value));
            }

            var index = value.LastIndexOf(':');
            int line;

            if (index >= 0 && int.TryParse(value.Substring(index + 1), out line))
            {
                value = value.Remove(index);
            }
            else
            {
                line = default(int);
            }

            var length = value.Length;

            if (length > 0 && value[0] == '"')
            {
                if (length > 1 && value[length - 1] == '"')
                {
                    value = value.Substring(1, length - 2);
                }
                else
                {
                    result = default(POSourceReference);
                    return(false);
                }
            }

            result = new POSourceReference(value, line);
            return(true);
        }