@@ -537,202 +537,6 @@ public static JsEngineLoadException WrapEngineLoadException(Exception exception,
537
537
538
538
#endregion
539
539
540
- #region Misc
541
-
542
- /// <summary>
543
- /// Gets a fragment from the source code
544
- /// </summary>
545
- /// <param name="sourceCode">Source code</param>
546
- /// <param name="lineNumber">Line number</param>
547
- /// <param name="columnNumber">Column number</param>
548
- /// <param name="maxFragmentLength">Maximum length of the source fragment</param>
549
- public static string GetSourceFragmentFromCode ( string sourceCode , int lineNumber , int columnNumber ,
550
- int maxFragmentLength = 100 )
551
- {
552
- if ( lineNumber <= 0 || string . IsNullOrEmpty ( sourceCode ) )
553
- {
554
- return string . Empty ;
555
- }
556
-
557
- int lineStartPosition ;
558
- int lineLength ;
559
- GetPositionOfLine ( sourceCode , lineNumber , out lineStartPosition , out lineLength ) ;
560
-
561
- string fragment = GetSourceFragment ( sourceCode , lineStartPosition , lineLength , columnNumber ,
562
- maxFragmentLength ) ;
563
-
564
- return fragment ;
565
- }
566
-
567
- /// <summary>
568
- /// Gets a fragment from the source line
569
- /// </summary>
570
- /// <param name="sourceLine">Content of the source line</param>
571
- /// <param name="columnNumber">Column number</param>
572
- /// <param name="maxFragmentLength">Maximum length of the source fragment</param>
573
- public static string GetSourceFragmentFromLine ( string sourceLine , int columnNumber ,
574
- int maxFragmentLength = 100 )
575
- {
576
- if ( string . IsNullOrEmpty ( sourceLine ) )
577
- {
578
- return string . Empty ;
579
- }
580
-
581
- int lineStartPosition = 0 ;
582
- int lineLength = sourceLine . Length ;
583
- string fragment = GetSourceFragment ( sourceLine , lineStartPosition , lineLength ,
584
- columnNumber , maxFragmentLength ) ;
585
-
586
- return fragment ;
587
- }
588
-
589
- private static string GetSourceFragment ( string source , int position , int length ,
590
- int columnNumber , int maxFragmentLength )
591
- {
592
- if ( length == 0 )
593
- {
594
- return string . Empty ;
595
- }
596
-
597
- string fragment ;
598
-
599
- if ( length > maxFragmentLength )
600
- {
601
- const string ellipsisSymbol = "…" ;
602
- string startPart = string . Empty ;
603
- string endPart = string . Empty ;
604
-
605
- var leftOffset = ( int ) Math . Floor ( ( double ) maxFragmentLength / 2 ) ;
606
- int fragmentStartPosition = columnNumber - leftOffset - 1 ;
607
- if ( fragmentStartPosition > position )
608
- {
609
- if ( length - fragmentStartPosition < maxFragmentLength )
610
- {
611
- fragmentStartPosition = length - maxFragmentLength ;
612
- }
613
- }
614
- else
615
- {
616
- fragmentStartPosition = position ;
617
- }
618
- int fragmentLength = maxFragmentLength ;
619
-
620
- if ( fragmentStartPosition > position )
621
- {
622
- startPart = ellipsisSymbol ;
623
- }
624
- if ( fragmentStartPosition + fragmentLength < length )
625
- {
626
- endPart = ellipsisSymbol ;
627
- }
628
-
629
- StringBuilder fragmentBuilder = StringBuilderPool . GetBuilder ( ) ;
630
- if ( startPart . Length > 0 )
631
- {
632
- fragmentBuilder . Append ( startPart ) ;
633
- }
634
- fragmentBuilder . Append ( source . Substring ( fragmentStartPosition , fragmentLength ) ) ;
635
- if ( endPart . Length > 0 )
636
- {
637
- fragmentBuilder . Append ( endPart ) ;
638
- }
639
-
640
- fragment = fragmentBuilder . ToString ( ) ;
641
- StringBuilderPool . ReleaseBuilder ( fragmentBuilder ) ;
642
- }
643
- else
644
- {
645
- fragment = position > 0 || length < source . Length ?
646
- source . Substring ( position , length ) : source ;
647
- }
648
-
649
- return fragment ;
650
- }
651
-
652
- private static void GetPositionOfLine ( string sourceCode , int lineNumber , out int position , out int length )
653
- {
654
- int currentLineNumber = 0 ;
655
- position = 0 ;
656
- length = 0 ;
657
-
658
- int sourceCodeLength = sourceCode . Length ;
659
- if ( sourceCodeLength > 0 )
660
- {
661
- int currentPosition ;
662
- int currentLength ;
663
- int sourceCodeEndPosition = sourceCodeLength - 1 ;
664
- int lineBreakPosition = int . MinValue ;
665
- int lineBreakLength = 0 ;
666
-
667
- do
668
- {
669
- currentLineNumber ++ ;
670
- currentPosition = lineBreakPosition == int . MinValue ? 0 : lineBreakPosition + lineBreakLength ;
671
- currentLength = sourceCodeEndPosition - currentPosition + 1 ;
672
-
673
- FindLineBreak ( sourceCode , currentPosition , currentLength ,
674
- out lineBreakPosition , out lineBreakLength ) ;
675
-
676
- if ( currentLineNumber == lineNumber )
677
- {
678
- if ( lineBreakPosition != 0 )
679
- {
680
- position = currentPosition ;
681
- int endPosition = lineBreakPosition != - 1 ?
682
- lineBreakPosition - 1 : sourceCodeEndPosition ;
683
- length = endPosition - position + 1 ;
684
- }
685
- break ;
686
- }
687
- }
688
- while ( lineBreakPosition != - 1 && lineBreakPosition <= sourceCodeEndPosition ) ;
689
- }
690
- }
691
-
692
- /// <summary>
693
- /// Finds a line break
694
- /// </summary>
695
- /// <param name="sourceCode">Source code</param>
696
- /// <param name="startPosition">Position in the input string that defines the leftmost
697
- /// position to be searched</param>
698
- /// <param name="lineBreakPosition">Position of line break</param>
699
- /// <param name="lineBreakLength">Length of line break</param>
700
- private static void FindLineBreak ( string sourceCode , int startPosition ,
701
- out int lineBreakPosition , out int lineBreakLength )
702
- {
703
- int length = sourceCode . Length - startPosition ;
704
-
705
- FindLineBreak ( sourceCode , startPosition , length ,
706
- out lineBreakPosition , out lineBreakLength ) ;
707
- }
708
-
709
- /// <summary>
710
- /// Finds a line break
711
- /// </summary>
712
- /// <param name="sourceCode">Source code</param>
713
- /// <param name="startPosition">Position in the input string that defines the leftmost
714
- /// position to be searched</param>
715
- /// <param name="length">Number of characters in the substring to include in the search</param>
716
- /// <param name="lineBreakPosition">Position of line break</param>
717
- /// <param name="lineBreakLength">Length of line break</param>
718
- private static void FindLineBreak ( string sourceCode , int startPosition , int length ,
719
- out int lineBreakPosition , out int lineBreakLength )
720
- {
721
- Match lineBreakMatch = _lineBreakRegex . Match ( sourceCode , startPosition , length ) ;
722
- if ( lineBreakMatch . Success )
723
- {
724
- lineBreakPosition = lineBreakMatch . Index ;
725
- lineBreakLength = lineBreakMatch . Length ;
726
- }
727
- else
728
- {
729
- lineBreakPosition = - 1 ;
730
- lineBreakLength = 0 ;
731
- }
732
- }
733
-
734
- #endregion
735
-
736
540
#region Obsolete methods
737
541
738
542
/// <summary>
0 commit comments