public static void Append_Entry_To_List(ref List <Tuple <string, FormDataEntryValue> > entryList, string name, dynamic value, bool prevent_line_break_normalization_flag = false) {/* Docs: https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#append-an-entry */ /* 1) For name, replace every occurrence of U+000D (CR) not followed by U+000A (LF), and every occurrence of U+000A (LF) not preceded by U+000D (CR), by a string consisting of a U+000D (CR) and U+000A (LF). */ var normalizedName = StringCommon.Replace(name.AsMemory(), FilterCRLF.Instance, strNewline.AsSpan()); /* 2) Replace name with the result of converting to a sequence of Unicode scalar values. */ name = UnicodeCommon.Convert_To_Scalar_Values(normalizedName.AsMemory()); /* 3) If value is not a File object, then: */ if (!(value is FileBlob valueFile)) { if (!(value is string)) { throw new ArgumentException($"Expected value to be string, not: {value.GetType().Name}"); } if (!prevent_line_break_normalization_flag) { string normalizedValue = StringCommon.Replace(((string)value).AsMemory(), FilterCRLF.Instance, strNewline.AsSpan()); value = UnicodeCommon.Convert_To_Scalar_Values(normalizedValue.AsMemory()); } var entryValue = new FormDataEntryValue(EFormDataValueType.String, name, value); entryList.Add(new Tuple <string, FormDataEntryValue>(name, entryValue)); }
public void ReplaceCharTest() { Assert.Equal("A,B,C", StringCommon.Replace("A, B, C ", false, true, (' ', ""))); Assert.Equal("A, B, C ", StringCommon.Replace("A, B, C ", false, true, (' ', " "))); Assert.Equal("A, B, C", StringCommon.Replace("A, B, C ", true, true, (' ', " "))); Assert.Equal("A,B,C", StringCommon.Replace(" A, B, C", false, true, (' ', ""))); Assert.Equal(" A, B, C", StringCommon.Replace(" A, B, C", false, true, (' ', " "))); Assert.Equal("A, B, C", StringCommon.Replace(" A, B, C", true, true, (' ', " "))); Assert.Equal("ABC", StringCommon.Replace(" A B C ", false, true, (' ', ""))); Assert.Equal(" A B C ", StringCommon.Replace(" A B C ", false, true, (' ', " "))); Assert.Equal("A B C", StringCommon.Replace(" A B C ", true, true, (' ', " "))); Assert.Equal("A,B,C", StringCommon.Replace("A,0B,C0", true, true, ('0', ""))); Assert.Equal("A,11B,C", StringCommon.Replace("A,0B,C0", true, true, ('0', "11"))); Assert.Equal("A,11B11,C", StringCommon.Replace("0A,0B0,C0", true, true, ('0', "11"))); }
private static byte[] process_blob_parts(IReadOnlyCollection <BlobPart> blobParts, BlobPropertyBag options) {/* Docs: https://w3c.github.io/FileAPI/#process-blob-parts */ using (MemoryStream Stream = new MemoryStream()) { foreach (var element in blobParts) { if (element.data is string) { string s = element.data; if (options.endings == EBlobEnding.Native) { string CorrectEnding = FilterCRLF.CRLF; if (!Environment.NewLine.Equals(FilterCRLF.CRLF, StringComparison.Ordinal)) { CorrectEnding = FilterCRLF.LF; } string native_line_ending = StringCommon.Replace(s, false, false, (UnicodeCommon.CHAR_CARRIAGE_RETURN, CorrectEnding), (UnicodeCommon.CHAR_LINE_FEED, CorrectEnding)); var encodedBytes = System.Text.Encoding.UTF8.GetBytes(native_line_ending); Stream.Write(encodedBytes, (int)Stream.Position, encodedBytes.Length); } } else if (element.data is ReadOnlyMemory <byte> bytes) { Stream.Write(bytes.ToArray(), (int)Stream.Position, bytes.Length); } else if (element.data is Blob blob) { Stream.Write(blob.data, (int)Stream.Position, (int)blob.size); } } return(Stream.ToArray()); } }
public void ReplaceDataFilterTest(string Expected, string Input, bool Trim, bool Collapse, string Replacement) { string Actual = StringCommon.Replace(Input, Trim, Collapse, (FilterWhitespace.Instance, Replacement)); Assert.Equal(Expected, Actual); }
public void ReplacePredicateTest(string Expected, string Input, bool Trim, bool Collapse, string Replacement) { string Actual = StringCommon.Replace(Input, Trim, Collapse, (UnicodeCommon.Is_Ascii_Whitespace, Replacement)); Assert.Equal(Expected, Actual); }