/// <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)); }
/// <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) { var text = input.AsText(enc.StringEncoding); // return new TextElement(text.Replace("\n", "\r\n")); StringBuilder sb = null; // lazily constructed string builder int idx = 0; int pos; while (idx < text.Length && (pos = IndexOfStandaloneLF(text, idx)) >= 0) { sb ??= StringBuilderUtilities.Pool.Get(); sb.Append(text, idx, pos - idx); sb.Append("\r\n"); // idx = pos + 1; } if (sb != null) { sb.Append(text, idx, text.Length - idx); text = StringBuilderUtilities.GetStringAndReturn(sb); } return(new TextElement(text)); }
/// <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) { return(new TextElement(input.AsText(enc.StringEncoding).Replace("\n", "\r\n"))); }
/// <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(Context ctx, TextElement input, bool closing) { return new TextElement(input.AsText(ctx.StringEncoding).Replace("\n", "\r\n")); }
/// <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(Context ctx, TextElement input, bool closing) { string str = input.AsText(ctx.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); }
/// <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(Context ctx, TextElement input, bool closing) { return(new TextElement(input.AsText(ctx.StringEncoding).Replace("\n", "\r\n"))); }