Completed
Push — v2.0.x ( 94c950...c40792 )
by Florent
02:29
created

StringUtil::mb_pad_str()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 1
Metric Value
c 1
b 1
f 1
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 4
1
<?php
2
3
/*
4
 * The MIT License (MIT)
5
 *
6
 * Copyright (c) 2014-2016 Spomky-Labs
7
 *
8
 * This software may be modified and distributed under the terms
9
 * of the MIT license.  See the LICENSE file for details.
10
 */
11
12
namespace Jose\Util;
13
14
/**
15
 * Class String.
16
 */
17
final class StringUtil
18
{
19
    public static function strlen($string)
20
    {
21
        return function_exists('mb_strlen') ? mb_strlen($string, '8bit') : strlen($string);
22
    }
23
24
    public static function substr($string, $start, $length = null)
25
    {
26
        return function_exists('mb_substr') ? mb_substr($string, $start, $length, '8bit') : substr($string, $start, $length);
27
    }
28
29
    public static function str_pad($input, $pad_length, $pad_string = null, $pad_style = null)
30
    {
31
        return function_exists('mb_strlen') ? self::mb_pad_str($input, $pad_length, $pad_string, $pad_style) : str_pad($input, $pad_length, $pad_string, $pad_style);
32
    }
33
34
    private static function mb_pad_str($input, $pad_length, $pad_string = null, $pad_style = null)
35
    {
36
        return str_pad($input, strlen($input)-mb_strlen($input, '8bit')+$pad_length, $pad_string, $pad_style);
37
    }
38
}
39