Beispiel #1
0
        /// <summary>
        /// Processes the <paramref name="input"/> (either of type <see cref="string"/> or <see cref="PhpBytes"/>)
        /// data and returns the filtered data in one of the formats above or <c>null</c>.
        /// </summary>
        public object Filter(object input, bool closing)
        {
            string str = PhpStream.AsText(input);

            if (pending)
            {
                // Both \r\n together make a pair which would consume a pending \r.
                if (str.Length == 0)
                {
                    str = "\r";
                }
                else if (str[0] != '\n')
                {
                    str.Insert(0, "\r");
                }
            }

            // Replace the pair.
            str = str.Replace("\r\n", "\n");
            if (str.Length == 0)
            {
                return(string.Empty);
            }

            // Check for pending \r at the end.
            pending = str[str.Length - 1] == '\r';

            // Postpone the resolution of \r\n vs. \r to the next filtering if this is not the last one.
            if (!closing && pending)
            {
                str.Remove(str.Length - 1, 1);
            }

            return(str);
        }
Beispiel #2
0
        /// <summary>
        /// Processes the <paramref name="input"/> (either of type <see cref="string"/> or <see cref="PhpBytes"/>)
        /// data and returns the filtered data in one of the formats above or <c>null</c>.
        /// </summary>
        public object Filter(object input, bool closing)
        {
            string str = PhpStream.AsText(input);

            str = str.Replace("\n", "\r\n");
            return(str);
        }