escaped-control-characters.js (1064B)
1 // Copyright (C) 2024 Leo Balter. All rights reserved. 2 // This code is governed by the BSD license found in the LICENSE file. 3 4 /*--- 5 esid: sec-encodeforregexescape 6 description: Encodes control characters with their ControlEscape sequences 7 info: | 8 EncodeForRegExpEscape ( c ) 9 10 2. If c is the code point listed in some cell of the “Code Point” column of Table 64, then 11 a. Return the string-concatenation of 0x005C (REVERSE SOLIDUS) and the string in the “ControlEscape” column of the row whose “Code Point” column contains c. 12 13 ControlEscape, Numeric Value, Code Point, Unicode Name, Symbol 14 t 9 U+0009 CHARACTER TABULATION <HT> 15 n 10 U+000A LINE FEED (LF) <LF> 16 v 11 U+000B LINE TABULATION <VT> 17 f 12 U+000C FORM FEED (FF) <FF> 18 r 13 U+000D CARRIAGE RETURN (CR) <CR> 19 features: [RegExp.escape] 20 ---*/ 21 22 const controlCharacters = '\t\n\v\f\r'; 23 const expectedEscapedCharacters = '\\t\\n\\v\\f\\r'; 24 25 assert.sameValue(RegExp.escape(controlCharacters), expectedEscapedCharacters, 'Control characters are correctly escaped'); 26 27 reportCompare(0, 0);