mirror of
https://github.com/danielstjules/Stringy.git
synced 2025-09-02 01:22:37 +02:00
Added indexOf and indexOfLast
This commit is contained in:
committed by
Daniel St. Jules
parent
3cf18e9e42
commit
9a5601efef
@@ -421,6 +421,34 @@ class StaticStringy
|
||||
->containsAll($needles, $caseSensitive);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the offset/index of the first occurance of $substr in the string.
|
||||
* In case $substr is not a substring of the string, returns false.
|
||||
*
|
||||
* @param string $str The haystack to search through
|
||||
* @param string $substr substring
|
||||
* @param int $offset
|
||||
* @return int|bool
|
||||
*/
|
||||
public static function indexOf($str, $substr, $offset = 0, $encoding = null)
|
||||
{
|
||||
return Stringy::create($str, $encoding)->indexOf($substr, $offset);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the offset/index of the last occurance of $substr in the string.
|
||||
* In case $substr is not a substring of the string, returns false.
|
||||
*
|
||||
* @param string $str The haystack to search through
|
||||
* @param string $substr substring
|
||||
* @param int $offset
|
||||
* @return int|bool
|
||||
*/
|
||||
public static function indexOfLast($str, $substr, $offset = 0, $encoding = null)
|
||||
{
|
||||
return Stringy::create($str, $encoding)->indexOfLast($substr, $offset);
|
||||
}
|
||||
|
||||
/**
|
||||
* Surrounds a string with the given substring.
|
||||
*
|
||||
|
@@ -520,7 +520,7 @@ class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess
|
||||
'Ἇ', 'ᾈ', 'ᾉ', 'ᾊ', 'ᾋ', 'ᾌ', 'ᾍ', 'ᾎ', 'ᾏ', 'Ᾰ',
|
||||
'Ᾱ', 'Ὰ', 'Ά', 'ᾼ', 'А'),
|
||||
'B' => array('Б', 'Β'),
|
||||
'C' => array('Ć', 'Č', 'Ĉ', 'Ċ'),
|
||||
'C' => array('Ç','Ć', 'Č', 'Ĉ', 'Ċ'),
|
||||
'D' => array('Ď', 'Ð', 'Đ', 'Ɖ', 'Ɗ', 'Ƌ', 'ᴅ', 'ᴆ', 'Д', 'Δ'),
|
||||
'E' => array('É', 'È', 'Ẻ', 'Ẽ', 'Ẹ', 'Ê', 'Ế', 'Ề', 'Ể', 'Ễ',
|
||||
'Ệ', 'Ë', 'Ē', 'Ę', 'Ě', 'Ĕ', 'Ė', 'Ε', 'Έ', 'Ἐ',
|
||||
@@ -887,6 +887,32 @@ class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the offset/index of the first occurrence of $substr in the string.
|
||||
* In case $substr is not a substring of the string, returns false.
|
||||
*
|
||||
* @param string $substr substring
|
||||
* @param int $offset
|
||||
* @return int|bool
|
||||
*/
|
||||
public function indexOf($substr, $offset = 0)
|
||||
{
|
||||
return mb_strpos($this->str, (string)$substr, (int)$offset, $this->encoding);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the offset/index of the last occurrence of $substr in the string.
|
||||
* In case $substr is not a substring of the string, returns false.
|
||||
*
|
||||
* @param string $substr substring
|
||||
* @param int $offset
|
||||
* @return int|bool
|
||||
*/
|
||||
public function indexOfLast($substr, $offset = 0)
|
||||
{
|
||||
return mb_strrpos($this->str, (string)$substr, (int)$offset, $this->encoding);
|
||||
}
|
||||
|
||||
/**
|
||||
* Surrounds $str with the given substring.
|
||||
*
|
||||
|
Reference in New Issue
Block a user