diff -r 7b1b88e27a20 -r 48c4eec2b7e6 wp/wp-includes/pomo/po.php --- a/wp/wp-includes/pomo/po.php Thu Sep 29 08:06:27 2022 +0200 +++ b/wp/wp-includes/pomo/po.php Fri Sep 05 18:40:08 2025 +0200 @@ -53,7 +53,7 @@ /** * Exports all entries to PO format * - * @return string sequence of mgsgid/msgstr PO strings, doesn't containt newline at the end + * @return string sequence of msgid/msgstr PO strings, doesn't contain a newline at the end */ public function export_entries() { // TODO: Sorting. @@ -64,7 +64,7 @@ * Exports the whole PO file as a string * * @param bool $include_headers whether to include the headers in the export - * @return string ready for inclusion in PO file string for headers and all the enrtries + * @return string ready for inclusion in PO file string for headers and all the entries */ public function export( $include_headers = true ) { $res = ''; @@ -110,10 +110,10 @@ /** * Formats a string in PO-style * - * @param string $string the string to format + * @param string $input_string the string to format * @return string the poified string */ - public static function poify( $string ) { + public static function poify( $input_string ) { $quote = '"'; $slash = '\\'; $newline = "\n"; @@ -124,12 +124,12 @@ "\t" => '\t', ); - $string = str_replace( array_keys( $replaces ), array_values( $replaces ), $string ); + $input_string = str_replace( array_keys( $replaces ), array_values( $replaces ), $input_string ); - $po = $quote . implode( "${slash}n$quote$newline$quote", explode( $newline, $string ) ) . $quote; - // Add empty string on first line for readbility. - if ( false !== strpos( $string, $newline ) && - ( substr_count( $string, $newline ) > 1 || substr( $string, -strlen( $newline ) ) !== $newline ) ) { + $po = $quote . implode( "{$slash}n{$quote}{$newline}{$quote}", explode( $newline, $input_string ) ) . $quote; + // Add empty string on first line for readability. + if ( str_contains( $input_string, $newline ) && + ( substr_count( $input_string, $newline ) > 1 || substr( $input_string, -strlen( $newline ) ) !== $newline ) ) { $po = "$quote$quote$newline$po"; } // Remove empty strings. @@ -140,17 +140,17 @@ /** * Gives back the original string from a PO-formatted string * - * @param string $string PO-formatted string - * @return string enascaped string + * @param string $input_string PO-formatted string + * @return string unescaped string */ - public static function unpoify( $string ) { + public static function unpoify( $input_string ) { $escapes = array( 't' => "\t", 'n' => "\n", 'r' => "\r", '\\' => '\\', ); - $lines = array_map( 'trim', explode( "\n", $string ) ); + $lines = array_map( 'trim', explode( "\n", $input_string ) ); $lines = array_map( array( 'PO', 'trim_quotes' ), $lines ); $unpoified = ''; $previous_is_backslash = false; @@ -178,18 +178,18 @@ } /** - * Inserts $with in the beginning of every new line of $string and + * Inserts $with in the beginning of every new line of $input_string and * returns the modified string * - * @param string $string prepend lines in this string - * @param string $with prepend lines with this string + * @param string $input_string prepend lines in this string + * @param string $with prepend lines with this string */ - public static function prepend_each_line( $string, $with ) { - $lines = explode( "\n", $string ); + public static function prepend_each_line( $input_string, $with ) { + $lines = explode( "\n", $input_string ); $append = ''; - if ( "\n" === substr( $string, -1 ) && '' === end( $lines ) ) { + if ( "\n" === substr( $input_string, -1 ) && '' === end( $lines ) ) { /* - * Last line might be empty because $string was terminated + * Last line might be empty because $input_string was terminated * with a newline, remove it from the $lines array, * we'll restore state by re-terminating the string at the end. */ @@ -342,7 +342,7 @@ $context = ''; $msgstr_index = 0; while ( true ) { - $lineno++; + ++$lineno; $line = PO::read_line( $f ); if ( ! $line ) { if ( feof( $f ) ) { @@ -365,7 +365,7 @@ // The comment is the start of a new entry. if ( self::is_final( $context ) ) { PO::read_line( $f, 'put-back' ); - $lineno--; + --$lineno; break; } // Comments have to be at the beginning. @@ -377,7 +377,7 @@ } elseif ( preg_match( '/^msgctxt\s+(".*")/', $line, $m ) ) { if ( self::is_final( $context ) ) { PO::read_line( $f, 'put-back' ); - $lineno--; + --$lineno; break; } if ( $context && 'comment' !== $context ) { @@ -388,7 +388,7 @@ } elseif ( preg_match( '/^msgid\s+(".*")/', $line, $m ) ) { if ( self::is_final( $context ) ) { PO::read_line( $f, 'put-back' ); - $lineno--; + --$lineno; break; } if ( $context && 'msgctxt' !== $context && 'comment' !== $context ) { @@ -505,10 +505,10 @@ * @return string */ public static function trim_quotes( $s ) { - if ( '"' === substr( $s, 0, 1 ) ) { + if ( str_starts_with( $s, '"' ) ) { $s = substr( $s, 1 ); } - if ( '"' === substr( $s, -1, 1 ) ) { + if ( str_ends_with( $s, '"' ) ) { $s = substr( $s, 0, -1 ); } return $s;