Exemple #1
0
 public function testToLower()
 {
     $str = new MString('ABCDEFG');
     $this->assertEquals('abcdefg', \strval($str->toLower()));
 }
Exemple #2
0
 /**
  * Whether this string starts with a given string
  * @link http://stackoverflow.com/a/3282864/570787
  * @param self $str
  * @param MStringComparison $cmp optional comparision option, default is null (case sensitive)
  * @return bool
  */
 public function startsWith(self $str, MStringComparison $cmp = null)
 {
     if ($str->isNullOrEmpty()) {
         throw new \InvalidArgumentException('$str is empty');
     }
     if ($str->count() > $this->count()) {
         throw new \InvalidArgumentException('$str is longer than $this');
     }
     if ($cmp === null || $cmp->getValue() === MStringComparison::CASE_SENSITIVE) {
         return $this->substring(0, $str->count())->_Value === $str->_Value;
     } else {
         return $this->substring(0, $str->count())->toLower()->_Value === $str->toLower()->_Value;
     }
 }