@@ 2807-2831 (lines=25) @@ | ||
2804 | * |
|
2805 | * @return static |
|
2806 | */ |
|
2807 | public function beforeFirst(string $separator): self |
|
2808 | { |
|
2809 | if ($separator === '') { |
|
2810 | return static::create(); |
|
2811 | } |
|
2812 | ||
2813 | if ($this->str === '') { |
|
2814 | return static::create(); |
|
2815 | } |
|
2816 | ||
2817 | $offset = $this->indexOf($separator); |
|
2818 | if ($offset === false) { |
|
2819 | return static::create('', $this->encoding); |
|
2820 | } |
|
2821 | ||
2822 | return static::create( |
|
2823 | UTF8::substr( |
|
2824 | $this->str, |
|
2825 | 0, |
|
2826 | $offset, |
|
2827 | $this->encoding |
|
2828 | ), |
|
2829 | $this->encoding |
|
2830 | ); |
|
2831 | } |
|
2832 | ||
2833 | /** |
|
2834 | * Gets the substring before the first occurrence of a separator. |
|
@@ 2841-2865 (lines=25) @@ | ||
2838 | * |
|
2839 | * @return static |
|
2840 | */ |
|
2841 | public function beforeFirstIgnoreCase(string $separator): self |
|
2842 | { |
|
2843 | if ($separator === '') { |
|
2844 | return static::create(); |
|
2845 | } |
|
2846 | ||
2847 | if ($this->str === '') { |
|
2848 | return static::create(); |
|
2849 | } |
|
2850 | ||
2851 | $offset = $this->indexOfIgnoreCase($separator); |
|
2852 | if ($offset === false) { |
|
2853 | return static::create('', $this->encoding); |
|
2854 | } |
|
2855 | ||
2856 | return static::create( |
|
2857 | UTF8::substr( |
|
2858 | $this->str, |
|
2859 | 0, |
|
2860 | $offset, |
|
2861 | $this->encoding |
|
2862 | ), |
|
2863 | $this->encoding |
|
2864 | ); |
|
2865 | } |
|
2866 | ||
2867 | /** |
|
2868 | * Gets the substring before the last occurrence of a separator. |
|
@@ 2875-2899 (lines=25) @@ | ||
2872 | * |
|
2873 | * @return static |
|
2874 | */ |
|
2875 | public function beforeLast(string $separator): self |
|
2876 | { |
|
2877 | if ($separator === '') { |
|
2878 | return static::create(); |
|
2879 | } |
|
2880 | ||
2881 | if ($this->str === '') { |
|
2882 | return static::create(); |
|
2883 | } |
|
2884 | ||
2885 | $offset = $this->indexOfLast($separator); |
|
2886 | if ($offset === false) { |
|
2887 | return static::create('', $this->encoding); |
|
2888 | } |
|
2889 | ||
2890 | return static::create( |
|
2891 | UTF8::substr( |
|
2892 | $this->str, |
|
2893 | 0, |
|
2894 | $offset, |
|
2895 | $this->encoding |
|
2896 | ), |
|
2897 | $this->encoding |
|
2898 | ); |
|
2899 | } |
|
2900 | ||
2901 | /** |
|
2902 | * Gets the substring before the last occurrence of a separator. |
|
@@ 2909-2933 (lines=25) @@ | ||
2906 | * |
|
2907 | * @return static |
|
2908 | */ |
|
2909 | public function beforeLastIgnoreCase(string $separator): self |
|
2910 | { |
|
2911 | if ($separator === '') { |
|
2912 | return static::create(); |
|
2913 | } |
|
2914 | ||
2915 | if ($this->str === '') { |
|
2916 | return static::create(); |
|
2917 | } |
|
2918 | ||
2919 | $offset = $this->indexOfLastIgnoreCase($separator); |
|
2920 | if ($offset === false) { |
|
2921 | return static::create('', $this->encoding); |
|
2922 | } |
|
2923 | ||
2924 | return static::create( |
|
2925 | UTF8::substr( |
|
2926 | $this->str, |
|
2927 | 0, |
|
2928 | $offset, |
|
2929 | $this->encoding |
|
2930 | ), |
|
2931 | $this->encoding |
|
2932 | ); |
|
2933 | } |
|
2934 | ||
2935 | /** |
|
2936 | * Returns the string with the first letter of each word capitalized, |