Skip to content

Commit

Permalink
Update from Chris
Browse files Browse the repository at this point in the history
  • Loading branch information
csev committed Mar 14, 2024
1 parent 7bdf073 commit aeb0dfe
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/Util/U.php
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,7 @@ public static function success_out($output) {
// http://stackoverflow.com/questions/834303/startswith-and-endswith-public static functions-in-php
public static function startsWith($haystack, $needle) {
// search backwards starting from haystack length characters from the end
if ( !is_string($haystack) || !is_string($needle) ) return false;
return $needle === "" || strrpos($haystack, $needle, -strlen($haystack)) !== FALSE;
}

Expand Down
11 changes: 11 additions & 0 deletions tests/Util/UTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,17 @@ public function testSha256() {
$this->assertEquals($out, null);
}

public function testStartsWith() {
$this->assertTrue(U::startsWith("csev@umich.edu", "csev"));
$this->assertTrue(U::startsWith("csev@umich.edu", ""));
$this->assertFalse(U::startsWith("csev@umich.edu", "cxev"));
$this->assertFalse(U::startsWith("edu", "@umich.edu"));
$this->assertFalse(U::startsWith(null, "@umich.edu"));
$this->assertFalse(U::startsWith(null, null));
$this->assertFalse(U::startsWith("edu", null));
}


public function testEndsWith() {
$this->assertTrue(U::endsWith("csev@umich.edu", "@umich.edu"));
$this->assertTrue(U::endsWith("csev@umich.edu", ""));
Expand Down

0 comments on commit aeb0dfe

Please sign in to comment.