3 namespace Org\Mxchange\CoreFramework\String\Utils;
5 // Import framework stuff
6 use Org\Mxchange\CoreFramework\Configuration\FrameworkConfiguration;
7 use Org\Mxchange\CoreFramework\Generic\NullPointerException;
8 use Org\Mxchange\CoreFramework\Object\BaseFrameworkSystem;
11 use \InvalidArgumentException;
14 * A string utility class
16 * @author Roland Haeder <webmaster@ship-simu.org>
18 * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2020 Core Developer Team
19 * @license GNU GPL 3.0 or any newer version
20 * @link http://www.ship-simu.org
22 * This program is free software: you can redistribute it and/or modify
23 * it under the terms of the GNU General Public License as published by
24 * the Free Software Foundation, either version 3 of the License, or
25 * (at your option) any later version.
27 * This program is distributed in the hope that it will be useful,
28 * but WITHOUT ANY WARRANTY; without even the implied warranty of
29 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30 * GNU General Public License for more details.
32 * You should have received a copy of the GNU General Public License
33 * along with this program. If not, see <http://www.gnu.org/licenses/>.
35 final class StringUtils extends BaseFrameworkSystem {
37 * Private constructor, no instance needed
41 private function __construct () {
42 // Call parent constructor
43 parent::__construct(__CLASS__);
47 * Converts dashes to underscores, e.g. useable for configuration entries
49 * @param $str The string with maybe dashes inside
50 * @return $str The converted string with no dashed, but underscores
51 * @throws NullPointerException If $str is null
52 * @throws InvalidArgumentException If $str is empty
54 public static function convertDashesToUnderscores ($str) {
58 throw new NullPointerException($this, self::EXCEPTION_IS_NULL_POINTER);
59 } elseif (!is_string($str)) {
61 throw new InvalidArgumentException(sprintf('str[]=%s is not a string', gettype($str)), FrameworkConfiguration::EXCEPTION_CONFIG_KEY_IS_EMPTY);
62 } elseif ((is_string($str)) && (empty($str))) {
64 throw new InvalidArgumentException('str is empty', FrameworkConfiguration::EXCEPTION_CONFIG_KEY_IS_EMPTY);
68 $str = str_replace('-', '_', $str);
70 // Return converted string