Esempio 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();
            }
        }
Esempio n. 2
0
 void ChangeLength(TreeNode line, int newLength, UnicodeNewline newLine)
 {
     line.LengthIncludingDelimiter = newLength;
     line.UnicodeNewline           = newLine;
     OnLineChanged(new LineEventArgs(line));
     line.UpdateAugmentedData();
 }
 public SimpleLineSegment(SimpleReadonlyDocument splitter, int lineNumber, int offset, int length, UnicodeNewline newLine)
 {
     this.splitter            = splitter;
     LineNumber               = lineNumber;
     LengthIncludingDelimiter = length;
     UnicodeNewline           = newLine;
     Offset = offset;
 }
Esempio 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);
        }
Esempio 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);
        }
Esempio 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;
        }
Esempio n. 9
0
			public Delimiter (int offset, UnicodeNewline unicodeNewline)
			{
				Offset = offset;
				UnicodeNewline = unicodeNewline;
			}
Esempio n. 10
0
 public TreeNode(int length, UnicodeNewline newLine) : base(length, newLine)
 {
 }
Esempio 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;
			}
Esempio 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;
			}
Esempio 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;
 }
		void ChangeLength (TreeNode line, int newLength, UnicodeNewline newLine)
		{
			line.LengthIncludingDelimiter = newLength;
			line.UnicodeNewline = newLine;
			OnLineChanged (new LineEventArgs (line));
			line.UpdateAugmentedData ();
		}
		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;
		}
			public TreeNode (int length, UnicodeNewline newLine) : base(length, newLine)
			{
			}
Esempio 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);
        }
Esempio n. 19
0
 protected DocumentLine(int length, UnicodeNewline unicodeNewline)
 {
     LengthIncludingDelimiter = length;
     UnicodeNewline           = unicodeNewline;
 }
		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;
		}
		protected DocumentLine (int length, UnicodeNewline unicodeNewline)
		{
			LengthIncludingDelimiter = length;
			UnicodeNewline = unicodeNewline;
		}