public void Ctor_EmptyByDefault() { // Act var byteMap = new AsciiByteMap(); // Assert for (int i = 0; i < 128; i++) { Assert.False(byteMap.TryLookup(new Rune(i), out _)); } }
// Writes a scalar value as a JavaScript-escaped character (or sequence of characters). // See ECMA-262, Sec. 7.8.4, and ECMA-404, Sec. 9 // https://www.ecma-international.org/ecma-262/5.1/#sec-7.8.4 // https://www.ecma-international.org/publications/files/ECMA-ST/ECMA-404.pdf // // ECMA-262 allows encoding U+000B as "\v", but ECMA-404 does not. // Both ECMA-262 and ECMA-404 allow encoding U+002F SOLIDUS as "\/" // (in ECMA-262 this character is a NonEscape character); however, we // don't encode SOLIDUS by default unless the caller has provided an // explicit bitmap which does not contain it. In this case we'll assume // that the caller didn't want a SOLIDUS written to the output at all, // so it should be written using "\u002F" encoding. // HTML-specific characters (including apostrophe and quotes) will // be written out as numeric entities for defense-in-depth. internal override int EncodeUtf8(Rune value, Span <byte> destination) { if (_preescapedMap.TryLookup(value, out byte preescapedForm)) { if (!SpanUtility.IsValidIndex(destination, 1)) { goto OutOfSpace; } destination[0] = (byte)'\\'; destination[1] = preescapedForm; return(2); OutOfSpace: return(-1); } return(TryEncodeScalarAsHex(this, value, destination));