File: legacy-octal-escape.js

package info (click to toggle)
qtdeclarative-opensource-src 5.15.2%2Bdfsg-6
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 259,220 kB
  • sloc: javascript: 512,396; cpp: 493,894; xml: 8,892; python: 3,304; ansic: 2,764; sh: 206; makefile: 59; php: 27
file content (61 lines) | stat: -rw-r--r-- 2,354 bytes parent folder | download | duplicates (11)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-regular-expressions-patterns
es6id: B.1.4
description: Legacy Octal Escape Sequence
info: |
    CharacterEscape[U]::
        ControlEscape
        c ControlLetter
        0 [lookahead ∉ DecimalDigit]
        HexEscapeSequence
        RegExpUnicodeEscapeSequence[?U]
        [~U] LegacyOctalEscapeSequence
        IdentityEscape[?U]

    The production CharacterEscape::LegacyOctalEscapeSequence evaluates by
    evaluating the SV of the LegacyOctalEscapeSequence (see B.1.2) and
    returning its character result.
---*/

var match;

assert.sameValue(/\1/.exec('\x01')[0], '\x01', '\\1');
assert.sameValue(/\2/.exec('\x02')[0], '\x02', '\\2');
assert.sameValue(/\3/.exec('\x03')[0], '\x03', '\\3');
assert.sameValue(/\4/.exec('\x04')[0], '\x04', '\\4');
assert.sameValue(/\5/.exec('\x05')[0], '\x05', '\\5');
assert.sameValue(/\6/.exec('\x06')[0], '\x06', '\\6');
assert.sameValue(/\7/.exec('\x07')[0], '\x07', '\\7');

assert.sameValue(/\00/.exec('\x00')[0], '\x00', '\\00');
assert.sameValue(/\07/.exec('\x07')[0], '\x07', '\\07');

assert.sameValue(/\30/.exec('\x18')[0], '\x18', '\\30');
assert.sameValue(/\37/.exec('\x1f')[0], '\x1f', '\\37');

assert.sameValue(/\40/.exec('\x20')[0], '\x20', '\\40');
assert.sameValue(/\47/.exec('\x27')[0], '\x27', '\\47');

assert.sameValue(/\70/.exec('\x38')[0], '\x38', '\\70');
assert.sameValue(/\77/.exec('\x3f')[0], '\x3f', '\\77');

// Sequence is bounded according to the String Value (not number of characters)
assert.sameValue(/\400/.exec('\x200')[0], '\x200', '\\400');
assert.sameValue(/\470/.exec('\x270')[0], '\x270', '\\470');
assert.sameValue(/\700/.exec('\x380')[0], '\x380', '\\700');
assert.sameValue(/\770/.exec('\x3f0')[0], '\x3f0', '\\770');

assert.sameValue(/\000/.exec('\x00')[0], '\x00', '\\000');
assert.sameValue(/\007/.exec('\x07')[0], '\x07', '\\007');
assert.sameValue(/\070/.exec('\x38')[0], '\x38', '\\070');

assert.sameValue(/\300/.exec('\xc0')[0], '\xc0', '\\300');
assert.sameValue(/\307/.exec('\xc7')[0], '\xc7', '\\307');
assert.sameValue(/\370/.exec('\xf8')[0], '\xf8', '\\370');

match = /(.)\1/.exec('a\x01 aa');
assert.sameValue(
  match[0], 'aa', 'DecimalEscape takes precedence over LegacyOctalEscapeSequence'
);