Pchp.Library.Streams.TextElement.AsText C# (CSharp) Method

AsText() public method

public AsText ( Encoding enc ) : string
enc System.Text.Encoding
return string
        public string AsText(Encoding enc) => IsNull ? string.Empty : IsText ? GetText() : enc.GetString(GetBytes());

Usage Example

Ejemplo n.º 1
0
        /// <summary>
        /// Processes the <paramref name="input"/> (either of type <see cref="string"/> or <see cref="byte"/>[])
        /// data and returns the filtered data in one of the formats above or <c>null</c>.
        /// </summary>
        public TextElement Filter(IEncodingProvider enc, TextElement input, bool closing)
        {
            string str = input.AsText(enc.StringEncoding);

            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)
            {
                // 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(new TextElement(str));
        }
All Usage Examples Of Pchp.Library.Streams.TextElement::AsText