/// <summary>
        /// Разбор записи в клиентском представлении и слияние
        /// с уже имеющимися полями.
        /// </summary>
        public IrbisRecord MergeParse
        (
            string[] text,
            int skipLines
        )
        {
            if (skipLines > 0)
            {
                text = text.Skip(skipLines).ToArray();
            }

            if (text.Length > 2)
            {
                Regex regex = new Regex(@"^(-?\d+)\#(\d*)?");
                Match match = regex.Match(text[0]);
                Mfn = Math.Abs(FastNumber.ParseInt32(match.Groups[1].Value));
                if (match.Groups[2].Length > 0)
                {
                    Status = (RecordStatus)FastNumber.ParseInt32(match.Groups[2].Value);
                }
                match = regex.Match(text[1]);
                if (match.Groups[2].Length > 0)
                {
                    Version = FastNumber.ParseInt32(match.Groups[2].Value);
                }
            }

            foreach (string line in text.Skip(2))
            {
                RecordField field = RecordField.Parse(line);
                if (field != null)
                {
                    Fields.Add(field);
                }
            }

            return(this);
        }
Example #2
0
        public FieldReference(string originalText)
            : this()
        {
            _originalText = originalText;

            if (string.IsNullOrEmpty(originalText))
            {
                return;
            }

            Regex regex = _GetRegex();
            Match match = regex.Match(originalText);

            if (!match.Success)
            {
                throw new ArgumentException();
            }

            string text = match.Groups["precond"].Value;

            if (!string.IsNullOrEmpty(text))
            {
                PreConditional = _StripEnds(text);
            }
            text = match.Groups["prerep"].Value;
            if (!string.IsNullOrEmpty(text))
            {
                if (text.EndsWith("+"))
                {
                    PrePlus = true;
                    text    = text.Substring
                              (
                        0,
                        text.Length - 1
                              );
                }
                PreRepeatable = _StripEnds(text);
            }
            text = match.Groups["field"].Value;
#if PocketPC
            Dvn = char.ToUpper(text[0]);
#else
            Dvn = char.ToUpperInvariant(text[0]);
#endif
            Field = text.Substring(1);
            text  = match.Groups["embedded"].Value;
            if (!string.IsNullOrEmpty(text))
            {
                Embedded = text.Substring(1);
            }
            text = match.Groups["subfield"].Value;
            if (!string.IsNullOrEmpty(text))
            {
                SubField = text[1];
            }
            text = match.Groups["number"].Value;
            if (!string.IsNullOrEmpty(text))
            {
                NumberPresent = true;
                text          = _StripEnds(text);
                Regex numRegex = new Regex(@"(?<from>\d+)(?:-(?<to>\d+))?");
                Match numMatch = numRegex.Match(text);
                if (!numMatch.Success)
                {
                    throw new ArgumentException();
                }
                NumberFrom = FastNumber.ParseInt32(numMatch.Groups["from"].Value);
                text       = numMatch.Groups["to"].Value;
                NumberTo   = string.IsNullOrEmpty(text)
                               ? NumberFrom
                               : FastNumber.ParseInt32(text);
                if (NumberFrom > NumberTo)
                {
                    throw new ArgumentException();
                }
            }
            text = match.Groups["offset"].Value;
            if (!string.IsNullOrEmpty(text))
            {
                Offset = FastNumber.ParseInt32(text.Substring(1));
            }
            text = match.Groups["length"].Value;
            if (!string.IsNullOrEmpty(text))
            {
                Length = FastNumber.ParseInt32(text.Substring(1));
            }
            text = match.Groups["occur"].Value;
            if (!string.IsNullOrEmpty(text))
            {
                NumberFrom    = NumberTo = FastNumber.ParseInt32(text.Substring(1));
                NumberPresent = true;
            }
            text = match.Groups["postrep"].Value;
            if (!string.IsNullOrEmpty(text))
            {
                if (text.StartsWith("+"))
                {
                    PostPlus = true;
                    text     = text.Substring(1);
                }
                PostReapeatable = _StripEnds(text);
            }
            text = match.Groups["postcond"].Value;
            if (!string.IsNullOrEmpty(text))
            {
                PostConditional = _StripEnds(text);
            }
        }