Пример #1
0
            CompositeSegment ParseInsertionPoint()
            {
                char?formatSpecifier = null;

                if (!TryParse(_compositeFormatString, _currentIndex, 5, out uint arg, out int consumed))
                {
                    throw new Exception("invalid insertion point");
                }
                _currentIndex += consumed;
                if (_currentIndex >= _compositeFormatString.Length)
                {
                    throw new Exception("missing end bracket");
                }

                if (_compositeFormatString[_currentIndex] == ':')
                {
                    _currentIndex++;
                    formatSpecifier = _compositeFormatString[_currentIndex];
                    _currentIndex++;
                }

                if (_compositeFormatString[_currentIndex] != '}')
                {
                    throw new Exception("missing end bracket");
                }

                _currentIndex++;
                var StandardFormat = (formatSpecifier.HasValue && formatSpecifier.Value != 0) ? new StandardFormat(formatSpecifier.Value) : default;

                return(CompositeSegment.InsertionPoint(arg, StandardFormat));
            }
Пример #2
0
 public CompositeSegment?Next()
 {
     while (_currentIndex < _compositeFormatString.Length)
     {
         char c = _compositeFormatString[_currentIndex];
         if (c == '{')
         {
             if (_state == State.Literal)
             {
                 _state = State.New;
                 return(CompositeSegment.Literal(_spanStart, _currentIndex));
             }
             _currentIndex++;
             return(ParseInsertionPoint());
         }
         else
         {
             if (_state != State.Literal)
             {
                 _state     = State.Literal;
                 _spanStart = _currentIndex;
             }
         }
         _currentIndex++;
     }
     if (_state == State.Literal)
     {
         _state = State.New;
         return(CompositeSegment.Literal(_spanStart, _currentIndex));
     }
     return(null);
 }
Пример #3
0
            CompositeSegment ParseInsertionPoint()
            {
                uint arg;
                int  consumed;
                char?formatSpecifier = null;

                if (!TryParse(_compositeFormatString, _currentIndex, 5, out arg, out consumed))
                {
                    throw new Exception("invalid insertion point");
                }
                _currentIndex += consumed;
                if (_currentIndex >= _compositeFormatString.Length)
                {
                    throw new Exception("missing end bracket");
                }

                if (_compositeFormatString[_currentIndex] == ':')
                {
                    _currentIndex++;
                    formatSpecifier = _compositeFormatString[_currentIndex];
                    _currentIndex++;
                }

                if (_compositeFormatString[_currentIndex] != '}')
                {
                    throw new Exception("missing end bracket");
                }

                _currentIndex++;
                var parsedFormat = formatSpecifier.HasValue ? System.Text.Formatting.Format.Parse(formatSpecifier.Value): default(System.Text.Formatting.Format.Parsed);

                return(CompositeSegment.InsertionPoint(arg, parsedFormat));
            }
Пример #4
0
        public void TestComposite()
        {
            List <Point> pillar = new List <Point>();
            Point        p1     = new Point();

            p1.X = 1;
            p1.Y = 1;
            Point p2 = new Point();

            p2.X = 2;
            p2.Y = 2;
            pillar.Add(p1);
            pillar.Add(p2);
            ISegment segment = new Segment(new BezierCurve(), pillar);

            pillar = new List <Point>();
            p1     = new Point();
            p1.X   = 3;
            p1.Y   = 3;
            p2     = new Point();
            p2.X   = 4;
            p2.Y   = 4;
            pillar.Add(p1);
            pillar.Add(p2);
            ISegment segment2 = new Segment(new BezierCurve(), pillar);

            ISegment compositeSegment = new CompositeSegment();

            compositeSegment.Add(segment);
            compositeSegment.Add(segment2);
            Assert.AreEqual(compositeSegment.GetPillar().Count(), 4);
            Assert.AreEqual(compositeSegment.GetCurvePoint(0.48), segment.GetCurvePoint(0.96));
            Assert.AreEqual(compositeSegment.GetCurvePoint(0.75), segment2.GetCurvePoint(0.5));
        }
Пример #5
0
 public CompositeSegment?Next()
 {
     while (_currentIndex < _compositeFormatString.Length)
     {
         char c = _compositeFormatString[_currentIndex];
         if (c == '{')
         {
             if (_state == State.Literal)
             {
                 _state = State.New;
                 return(CompositeSegment.Literal(_spanStart, _currentIndex));
             }
             if ((_currentIndex + 1 < _compositeFormatString.Length) && (_compositeFormatString[_currentIndex + 1] == c))
             {
                 _state = State.Literal;
                 _currentIndex++;
                 _spanStart = _currentIndex;
             }
             else
             {
                 _currentIndex++;
                 return(ParseInsertionPoint());
             }
         }
         else if (c == '}')
         {
             if ((_currentIndex + 1 < _compositeFormatString.Length) && (_compositeFormatString[_currentIndex + 1] == c))
             {
                 if (_state == State.Literal)
                 {
                     _state = State.New;
                     return(CompositeSegment.Literal(_spanStart, _currentIndex));
                 }
                 _state = State.Literal;
                 _currentIndex++;
                 _spanStart = _currentIndex;
             }
             else
             {
                 throw new Exception("missing start bracket");
             }
         }
         else
         {
             if (_state != State.Literal)
             {
                 _state     = State.Literal;
                 _spanStart = _currentIndex;
             }
         }
         _currentIndex++;
     }
     if (_state == State.Literal)
     {
         _state = State.New;
         return(CompositeSegment.Literal(_spanStart, _currentIndex));
     }
     return(null);
 }