Ejemplo n.º 1
0
        /// <summary>
        /// Gets the new line as a string.
        /// </summary>
        public static string GetString(UnicodeNewline newLine)
        {
            switch (newLine)
            {
            case UnicodeNewline.Unknown:
                return("");

            case UnicodeNewline.LF:
                return("\n");

            case UnicodeNewline.CRLF:
                return("\r\n");

            case UnicodeNewline.CR:
                return("\r");

            case UnicodeNewline.NEL:
                return("\u0085");

            case UnicodeNewline.VT:
                return("\u000B");

            case UnicodeNewline.FF:
                return("\u000C");

            case UnicodeNewline.LS:
                return("\u2028");

            case UnicodeNewline.PS:
                return("\u2029");

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
Ejemplo n.º 2
0
 void ChangeLength(TreeNode line, int newLength, UnicodeNewline newLine)
 {
     line.LengthIncludingDelimiter = newLength;
     line.UnicodeNewline           = newLine;
     OnLineChanged(new LineEventArgs(line));
     line.UpdateAugmentedData();
 }
Ejemplo n.º 3
0
 public SimpleLineSegment(SimpleReadonlyDocument splitter, int lineNumber, int offset, int length, UnicodeNewline newLine)
 {
     this.splitter            = splitter;
     LineNumber               = lineNumber;
     LengthIncludingDelimiter = length;
     UnicodeNewline           = newLine;
     Offset = offset;
 }
Ejemplo n.º 4
0
        public static string NormilizeEols(string text, UnicodeNewline newLine)
        {
            if (string.IsNullOrEmpty(text))
            {
                return(text);
            }

            var eol = GetString(newLine);

            text = Regex.Replace(text, @"\r\n|\n\r|\n|\r", eol);

            return(text);
        }
Ejemplo n.º 5
0
        TreeNode InsertAfter(TreeNode segment, int length, UnicodeNewline newLine)
        {
            var result = new TreeNode(length, newLine);

            if (segment == null)
            {
                tree.Root  = result;
                tree.Count = 1;
                return(result);
            }

            tree.InsertAfter(segment, result);
            result.UpdateAugmentedData();
            OnLineInserted(new LineEventArgs(result));
            return(result);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Replace Unicode NewLines with ControlChars.NullChar or Specified Character
        /// </summary>
        /// <param name="text">Source Test</param>
        /// <param name="SubstituteChar">Default is vbNullChar</param>
        /// <returns>String with Unicode NewLines replaced with SubstituteChar</returns>
        public static string WithoutNewLines(this string text, char SubstituteChar = default)
        {
            System.Diagnostics.Contracts.Contract.Requires(text != null);
            var            sb     = new StringBuilder();
            int            length = default(int);
            UnicodeNewline type   = default(UnicodeNewline);

            for (int i = 0, loopTo = text.Length - 1; i <= loopTo; i++)
            {
                char ch = text[i];
                // Do not delete the next line
                int j = i;
                if (TryGetDelimiterLengthAndType(ch, out length, out type, () => j < text.Length - 1 ? text[j + 1] : SubstituteChar))
                {
                    i += length - 1;
                    continue;
                }
                sb.Append(ch);
            }
            return(sb.ToString());
        }
 /// <summary>
 /// Gets the new line as a string.
 /// </summary>
 public static string GetString(UnicodeNewline newLine)
 {
     switch (newLine)
     {
         case UnicodeNewline.Unknown:
             return "";
         case UnicodeNewline.LF:
             return "\n";
         case UnicodeNewline.CRLF:
             return "\r\n";
         case UnicodeNewline.CR:
             return "\r";
         case UnicodeNewline.NEL:
             return "\u0085";
         case UnicodeNewline.VT:
             return "\u000B";
         case UnicodeNewline.FF:
             return "\u000C";
         case UnicodeNewline.LS:
             return "\u2028";
         case UnicodeNewline.PS:
             return "\u2029";
         default:
             throw new ArgumentOutOfRangeException();
     }
 }
        /// <summary>
        /// Determines if a char is a new line delimiter.
        /// </summary>
        /// <returns>0 == no new line, otherwise it returns either 1 or 2 depending of the length of the delimiter.</returns>
        /// <param name="curChar">The current character.</param>
        /// <param name = "length">The length of the delimiter</param>
        /// <param name = "type">The type of the delimiter</param>
        /// <param name="nextChar">The next character (if != LF then length will always be 0 or 1).</param>
        public static bool TryGetDelimiterLengthAndType(char curChar, out int length, out UnicodeNewline type, char nextChar)
        {
            if (curChar == CR)
            {
                if (nextChar == LF)
                {
                    length = 2;
                    type = UnicodeNewline.CRLF;
                }
                else
                {
                    length = 1;
                    type = UnicodeNewline.CR;

                }
                return true;
            }

            switch (curChar)
            {
                case LF:
                    type = UnicodeNewline.LF;
                    length = 1;
                    return true;
                case NEL:
                    type = UnicodeNewline.NEL;
                    length = 1;
                    return true;
                case VT:
                    type = UnicodeNewline.VT;
                    length = 1;
                    return true;
                case FF:
                    type = UnicodeNewline.FF;
                    length = 1;
                    return true;
                case LS:
                    type = UnicodeNewline.LS;
                    length = 1;
                    return true;
                case PS:
                    type = UnicodeNewline.PS;
                    length = 1;
                    return true;
            }
            length = -1;
            type = UnicodeNewline.Unknown;
            return false;
        }
Ejemplo n.º 9
0
			public Delimiter (int offset, UnicodeNewline unicodeNewline)
			{
				Offset = offset;
				UnicodeNewline = unicodeNewline;
			}
Ejemplo n.º 10
0
 public TreeNode(int length, UnicodeNewline newLine) : base(length, newLine)
 {
 }
Ejemplo n.º 11
0
			public PrimitiveLineSegment (PrimitiveLineSplitter splitter, int lineNumber, int offset, int length, UnicodeNewline newLine) : base(length, newLine)
			{
				this.splitter = splitter;
				this.lineNumber = lineNumber;
				Offset = offset;
			}
Ejemplo n.º 12
0
 public Delimiter(int offset, UnicodeNewline unicodeNewline)
 {
     Offset         = offset;
     UnicodeNewline = unicodeNewline;
 }
			public SimpleLineSegment (SimpleReadonlyDocument splitter, int lineNumber, int offset, int length, UnicodeNewline newLine)
			{
				this.splitter = splitter;
				LineNumber = lineNumber;
				LengthIncludingDelimiter = length;
				UnicodeNewline = newLine;
				Offset = offset;
			}
Ejemplo n.º 14
0
 public PrimitiveLineSegment(PrimitiveLineSplitter splitter, int lineNumber, int offset, int length, UnicodeNewline newLine) : base(length, newLine)
 {
     this.splitter   = splitter;
     this.lineNumber = lineNumber;
     Offset          = offset;
 }
Ejemplo n.º 15
0
		void ChangeLength (TreeNode line, int newLength, UnicodeNewline newLine)
		{
			line.LengthIncludingDelimiter = newLength;
			line.UnicodeNewline = newLine;
			OnLineChanged (new LineEventArgs (line));
			line.UpdateAugmentedData ();
		}
Ejemplo n.º 16
0
		TreeNode InsertAfter (TreeNode segment, int length, UnicodeNewline newLine)
		{
			var result = new TreeNode (length, newLine) { StartSpan = segment.StartSpan };
			if (segment == null) {
				tree.Root = result;
				tree.Count = 1;
				return result;
			}
			
			tree.InsertAfter (segment, result);
			result.UpdateAugmentedData ();
			OnLineInserted (new LineEventArgs (result));
			return result;
		}
Ejemplo n.º 17
0
			public TreeNode (int length, UnicodeNewline newLine) : base(length, newLine)
			{
			}
Ejemplo n.º 18
0
        /// <summary>
        /// Determines if a char is a new line delimiter.
        /// </summary>
        /// <returns>0 == no new line, otherwise it returns either 1 or 2 depending of the length of the delimiter.</returns>
        /// <param name="curChar">The current character.</param>
        /// <param name = "length">The length of the delimiter</param>
        /// <param name = "type">The type of the delimiter</param>
        /// <param name="nextChar">The next character (if != LF then length will always be 0 or 1).</param>
        public static bool TryGetDelimiterLengthAndType(char curChar, out int length, out UnicodeNewline type, char nextChar)
        {
            if (curChar == CR)
            {
                if (nextChar == LF)
                {
                    length = 2;
                    type   = UnicodeNewline.CRLF;
                }
                else
                {
                    length = 1;
                    type   = UnicodeNewline.CR;
                }
                return(true);
            }

            switch (curChar)
            {
            case LF:
                type   = UnicodeNewline.LF;
                length = 1;
                return(true);

            case NEL:
                type   = UnicodeNewline.NEL;
                length = 1;
                return(true);

            case VT:
                type   = UnicodeNewline.VT;
                length = 1;
                return(true);

            case FF:
                type   = UnicodeNewline.FF;
                length = 1;
                return(true);

            case LS:
                type   = UnicodeNewline.LS;
                length = 1;
                return(true);

            case PS:
                type   = UnicodeNewline.PS;
                length = 1;
                return(true);
            }
            length = -1;
            type   = UnicodeNewline.Unknown;
            return(false);
        }
Ejemplo n.º 19
0
 protected DocumentLine(int length, UnicodeNewline unicodeNewline)
 {
     LengthIncludingDelimiter = length;
     UnicodeNewline           = unicodeNewline;
 }
Ejemplo n.º 20
0
		static int GetEolMarkerIndex (UnicodeNewline ch)
		{
			switch (ch) {
			case UnicodeNewline.Unknown:
				return 0;
			case UnicodeNewline.LF:
				return 1;
			case UnicodeNewline.CRLF:
				return 2;
			case UnicodeNewline.CR:
				return 3;
			case UnicodeNewline.NEL:
				return 4;
			case UnicodeNewline.VT:
				return 5;
			case UnicodeNewline.FF:
				return 6;
			case UnicodeNewline.LS:
				return 7;
			case UnicodeNewline.PS:
				return 8;
			}
			return 0;
		}
Ejemplo n.º 21
0
		protected DocumentLine (int length, UnicodeNewline unicodeNewline)
		{
			LengthIncludingDelimiter = length;
			UnicodeNewline = unicodeNewline;
		}