PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 6.8.1
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v6.8.1
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 +45 -29 6.266.8.1 View file →
@@ -45,17 +45,24 @@
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 - *
49 + * @param bool $discard_char
50 50 * @return string
51 51 */
52 - public function read_until( $char ) {
52 + public function read_until( $char, $discard_char = true ) {
53 53 $value = '';
54 54
55 - while ( $this->pos <= $this->max && ( $one = $this->string[ $this->pos++ ] ) !== $char ) {
56 - $value .= $one;
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 + }
57 63 }
64 +
58 65 return $value;
59 66 }
60 67
61 68 /**
@@ -63,45 +70,54 @@
63 70 * whichever comes first.
64 71 * By default, remove enclosing double-quotes from the result.
65 72 *
66 73 * @param int $count
67 - *
68 74 * @return string
69 75 */
70 76 public function read( $count ) {
71 77 $value = '';
72 78
73 - while ( $count > 0 && $this->pos <= $this->max && ( ( $one = $this->string[ $this->pos ] ) || '0' === $one ) ) {
74 - $value .= $one;
75 - $this->pos += 1;
79 + while ( $count > 0 && ! is_null( $one = $this->read_one() ) ) {
80 + $value .= $one;
76 81 --$count;
77 82 }
78 83
79 - /**
80 - * Remove a single set of double-quotes from around a string.
81 - *
82 - * Examples:
83 - * abc => abc
84 - * "abc" => abc
85 - * ""abc"" => "abc"
86 - */
87 - if ( strlen( $value ) < 2 || substr( $value, 0, 1 ) !== '"' || substr( $value, -1, 1 ) !== '"' ) {
88 - // Only remove exactly one quote from the start and the end and then only if there is one at each end.
89 - // Too short, or does not start or end with a quote.
90 - return $value;
84 + return $this->strip_quotes( $value );
85 + }
86 +
87 + /**
88 + * Read the next character from the supplied string.
89 + * Return null when we have run out of characters.
90 + *
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;
91 99 }
92 -
93 - // Return the middle of the string, from the second character to the second-but-last.
94 - return substr( $value, 1, -1 );
100 + return $value;
95 101 }
96 102
97 103 /**
98 - * Shift the position. This is used to skip a character that we don't need to read.
104 + * Remove a single set of double-quotes from around a string.
105 + * abc => abc
106 + * "abc" => abc
107 + * ""abc"" => "abc"
99 108 *
100 - * @since 6.9.1 This was added as an optimization.
101 - *
102 - * @return void
109 + * @param string $string
110 + * @return string
103 111 */
104 - public function skip_next_character() {
105 - $this->pos += 1;
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 );
106 122 }
107 123 }