<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/css/bootstrap.min.css" rel="stylesheet"
        integrity="sha384-GLhlTQ8iRABdZLl6O3oVMWSktQOp6b7In1Zl3/Jr59b6EGGoI1aFkw7cmDA6j6gD" crossorigin="anonymous">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.3.0/css/all.min.css"
        integrity="sha512-SzlrxWUlpfuzQ+pcUCosxcglQRNAq/DZjVsC0lE40xsADsfeQoEypE+enwcOiGjk/bSuGGKHEyjSoQ1zVisanQ=="
        crossorigin="anonymous" referrerpolicy="no-referrer" />
</head>
</html>
<?php
/**
 *  String Helper class.
 *
 * @package Automattic\WooCommerce\Internal\ProductFeed
 */

declare(strict_types=1);

namespace Automattic\WooCommerce\Internal\ProductFeed\Utils;

if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

/**
 * String utility helper functions
 *
 * @since 10.5.0
 */
class StringHelper {
	/**
	 * Convert value to boolean string ('true' or 'false')
	 *
	 * @since 10.5.0
	 *
	 * @param mixed $value Value to convert.
	 * @return string 'true' or 'false'.
	 */
	public static function bool_string( $value ): string {
		if ( is_bool( $value ) ) {
			return $value ? 'true' : 'false';
		}
		if ( is_scalar( $value ) || null === $value ) {
			$value = strtolower( (string) $value );
		} else {
			$value = '';
		}
		return ( 'true' === $value || '1' === $value || 'yes' === $value ) ? 'true' : 'false';
	}

	/**
	 * Truncate text to specified length
	 *
	 * @since 10.5.0
	 *
	 * @param string $text Text to truncate.
	 * @param int    $max_length Maximum length.
	 * @return string Truncated text.
	 */
	public static function truncate( string $text, int $max_length ): string {
		if ( mb_strlen( $text ) > $max_length ) {
			return mb_substr( $text, 0, $max_length );
		}
		return $text;
	}
}
