PluginProbe
Elementor Website Builder – more than just a page builder / 4.3.1
Elementor Website Builder – more than just a page builder v4.3.1
4.3.2 4.3.1 4.3.0 4.3.0-beta3 4.3.0-beta2 4.3.0-beta1 4.2.4 4.2.3 4.2.2 4.2.1 4.2.0 4.1.5 4.2.0-beta2 4.2.0-dev2 4.2.0-beta1 4.1.4 4.1.3 4.1.2 4.1.1 4.1.0 4.1.0-beta3 4.1.0-dev3 4.0.9 4.1.0-beta2 4.1.0-dev2 All 455 releases
elementor / modules / atomic-widgets / css-converter / css-block-scanner-trait.php

css-block-scanner-trait.php in Elementor Website Builder – more than just a page builder 4.3.1, at modules/atomic-widgets/css-converter/css-block-scanner-trait.php

60 lines 1.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Elementor\Modules\AtomicWidgets\CssConverter;
4
5 if ( ! defined( 'ABSPATH' ) ) {
6 exit;
7 }
8
9 trait Css_Block_Scanner_Trait {
10
11 /**
12 * Returns true when the quote/character at $pos is preceded by an odd number of backslashes,
13 * meaning it is escaped. Counting consecutive backslashes handles `"\\"` correctly
14 * (even count → backslash itself escaped → the following char is NOT escaped).
15 */
16 private function is_escaped( string $css, int $pos ): bool {
17 $count = 0;
18 $j = $pos - 1;
19 while ( $j >= 0 && '\\' === $css[ $j ] ) {
20 ++$count;
21 --$j;
22 }
23 return 1 === $count % 2;
24 }
25
26 private function find_block_end( string $css, int $start, int $len ): ?int {
27 $depth = 1;
28 $in_string = false;
29 $str_char = '';
30
31 for ( $i = $start; $i < $len; $i++ ) {
32 $c = $css[ $i ];
33
34 if ( $in_string ) {
35 if ( $str_char === $c && ! $this->is_escaped( $css, $i ) ) {
36 $in_string = false;
37 }
38 continue;
39 }
40
41 if ( '"' === $c || "'" === $c ) {
42 $in_string = true;
43 $str_char = $c;
44 continue;
45 }
46
47 if ( '{' === $c ) {
48 ++$depth;
49 } elseif ( '}' === $c ) {
50 --$depth;
51 if ( 0 === $depth ) {
52 return $i + 1;
53 }
54 }
55 }
56
57 return null;
58 }
59 }
60