* @version 0.0.0 * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2019 Core Developer Team * @license GNU GPL 3.0 or any newer version * @link http://www.ship-simu.org * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ final class StringUtils extends BaseFrameworkSystem { /** * Private constructor, no instance needed * * @return void */ private function __construct () { // Call parent constructor parent::__construct(__CLASS__); } /** * Converts dashes to underscores, e.g. useable for configuration entries * * @param $str The string with maybe dashes inside * @return $str The converted string with no dashed, but underscores * @throws NullPointerException If $str is null * @throws InvalidArgumentException If $str is empty */ public static function convertDashesToUnderscores ($str) { // Is it null? if (is_null($str)) { // Throw NPE throw new NullPointerException($this, self::EXCEPTION_IS_NULL_POINTER); } elseif (!is_string($str)) { // Entry is empty throw new InvalidArgumentException(sprintf('str[]=%s is not a string', gettype($str)), FrameworkConfiguration::EXCEPTION_CONFIG_KEY_IS_EMPTY); } elseif ((is_string($str)) && (empty($str))) { // Entry is empty throw new InvalidArgumentException('str is empty', FrameworkConfiguration::EXCEPTION_CONFIG_KEY_IS_EMPTY); } // Convert them all $str = str_replace('-', '_', $str); // Return converted string return $str; } }