Beispiel #1
0
 public function testNullOrEmpty()
 {
     $str = new MString('一二三四五');
     $this->assertFalse($str->isNullOrEmpty());
     $str = new MString('');
     $this->assertTrue($str->isNullOrEmpty());
     $str = new MString('     ');
     $this->assertFalse($str->isNullOrEmpty());
 }
Beispiel #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;
     }
 }