PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 6.15
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v6.15
6.35 6.34 6.33.1 6.33 6.32.1 6.32 6.31 6.25 6.25.1 6.26 6.26.1 6.27 6.28 6.29 6.3 6.3.1 6.3.2 6.30 6.4 6.4.1 6.4.2 6.5 6.5.1 6.5.2 6.5.3 All 141 releases
← All changes | classes/helpers/FrmStringReaderHelper.php +27 -46 6.56.15 View file →
@@ -45,24 +45,15 @@
45 45 * Read characters until we reach the given character $char.
46 46 * By default, discard that final matching character and return the rest.
47 47 *
48 48 * @param string $char
49 - * @param bool $discard_char
50 49 * @return string
51 50 */
52 - public function read_until( $char, $discard_char = true ) {
51 + public function read_until( $char ) {
53 52 $value = '';
54 -
55 - while ( null !== ( $one = $this->read_one() ) ) {
56 - if ( $one !== $char || ! $discard_char ) {
57 - $value .= $one;
58 - }
59 -
60 - if ( $one === $char ) {
61 - break;
62 - }
53 + while ( $this->pos <= $this->max && ( $one = $this->string[ $this->pos++ ] ) !== $char ) {
54 + $value .= $one;
63 55 }
64 -
65 56 return $value;
66 57 }
67 58
68 59 /**
@@ -75,49 +66,39 @@
75 66 */
76 67 public function read( $count ) {
77 68 $value = '';
78 69
79 - while ( $count > 0 && ! is_null( $one = $this->read_one() ) ) {
80 - $value .= $one;
70 + while ( $count > 0 && $this->pos <= $this->max && ( ( $one = $this->string[ $this->pos ] ) || '0' === $one ) ) {
71 + $value .= $one;
72 + $this->pos += 1;
81 73 --$count;
82 74 }
83 75
84 - return $this->strip_quotes( $value );
76 + /**
77 + * Remove a single set of double-quotes from around a string.
78 + *
79 + * Examples:
80 + * abc => abc
81 + * "abc" => abc
82 + * ""abc"" => "abc"
83 + */
84 + if ( strlen( $value ) < 2 || substr( $value, 0, 1 ) !== '"' || substr( $value, -1, 1 ) !== '"' ) {
85 + // Only remove exactly one quote from the start and the end and then only if there is one at each end.
86 + // Too short, or does not start or end with a quote.
87 + return $value;
88 + }
89 +
90 + // Return the middle of the string, from the second character to the second-but-last.
91 + return substr( $value, 1, -1 );
85 92 }
86 93
87 94 /**
88 - * Read the next character from the supplied string.
89 - * Return null when we have run out of characters.
95 + * Shift the position. This is used to skip a character that we don't need to read.
90 96 *
91 - * @return string|null
92 - */
93 - private function read_one() {
94 - if ( $this->pos <= $this->max ) {
95 - $value = $this->string[ $this->pos ];
96 - $this->pos += 1;
97 - } else {
98 - $value = null;
99 - }
100 - return $value;
101 - }
102 -
103 - /**
104 - * Remove a single set of double-quotes from around a string.
105 - * abc => abc
106 - * "abc" => abc
107 - * ""abc"" => "abc"
97 + * @since 6.9.1 This was added as an optimization.
108 98 *
109 - * @param string string
110 - * @return string
99 + * @return void
111 100 */
112 - private function strip_quotes( $string ) {
113 - // Only remove exactly one quote from the start and the end and then only if there is one at each end.
114 -
115 - if ( strlen( $string ) < 2 || substr( $string, 0, 1 ) !== '"' || substr( $string, -1, 1 ) !== '"' ) {
116 - // Too short, or does not start or end with a quote.
117 - return $string;
118 - }
119 -
120 - // Return the middle of the string, from the second character to the second-but-last.
121 - return substr( $string, 1, -1 );
101 + public function skip_next_character() {
102 + $this->pos += 1;
122 103 }
123 104 }