Esempio n. 1
0
        public override ErrorInfo TryParseData(IDataModel model, string name, int dataIndex, ref IFormattedRun run)
        {
            var pointerSources = model.GetUnmappedSourcesToAnchor(name);
            var errorInfo      = ArrayRun.TryParse(model, name, Format, dataIndex, pointerSources, out var arrayRun);

            if (errorInfo == ErrorInfo.NoError)
            {
                run = arrayRun;
            }
            else if (Format != string.Empty)
            {
                return(new ErrorInfo($"Format {Format} was not understood."));
            }

            return(ErrorInfo.NoError);
        }
        public static bool TryParseTableStream(IDataModel model, int start, SortedSpan <int> sources, string fieldName, string content, IReadOnlyList <ArrayRunElementSegment> sourceSegments, out TableStreamRun tableStream)
        {
            tableStream = null;

            if (content.Length < 4 || content[0] != '[')
            {
                return(false);
            }
            var close = content.LastIndexOf(']');

            if (close == -1)
            {
                return(false);
            }
            try {
                var segmentContent = content.Substring(1, close - 1);
                var segments       = ArrayRun.ParseSegments(segmentContent, model);
                var endStream      = ParseEndStream(model, fieldName, content.Substring(close + 1), segments, sourceSegments);
                if (endStream == null)
                {
                    return(false);
                }
                if (segments.Count == 0)
                {
                    return(false);
                }
                tableStream = new TableStreamRun(model, start, sources, content, segments, endStream);
            } catch (ArrayRunParseException) {
                return(false);
            }

            if (start < 0)
            {
                return(false);        // not a valid data location, so the data can't possibly be valid
            }
            if (model.GetUnmappedSourcesToAnchor(fieldName).Count > 0)
            {
                // we're pasting this format and something else is expecting it. Don't expect the content to match yet.
                return(tableStream.ElementCount > 0);
            }

            // if the first 90% matches, we don't need to check the last 10%
            var mostElementsCount = (int)Math.Ceiling(tableStream.ElementCount * .85);

            return(DataMatches(model, tableStream, mostElementsCount));
        }
        public override ErrorInfo TryParseData(IDataModel model, string name, int dataIndex, ref IFormattedRun run)
        {
            var pointerSources = model.GetUnmappedSourcesToAnchor(name);

            pointerSources = new SortedSpan <int>(pointerSources.Where(source => model.ReadValue(source) == 0).ToList());
            var errorInfo = ArrayRun.TryParse(model, name, Format, dataIndex, pointerSources, out var arrayRun);

            if (errorInfo == ErrorInfo.NoError)
            {
                run = arrayRun;
            }
            else if (Format != string.Empty)
            {
                return(new ErrorInfo($"Format {Format} was not understood: " + errorInfo.ErrorMessage));
            }

            return(ErrorInfo.NoError);
        }