How to use startsWith method of StringUtils class

Best Gherkin-php code snippet using StringUtils.startsWith

BaseArchive.php

Source:BaseArchive.php Github

copy

Full Screen

...53 $path = '';54 }55 // back out of path if filename starts with ../56 //57 while (StringUtils::startsWith($file, '../')) {58 // strip leading ../59 //60 $file = substr($file, 3);61 // strip trailing slash62 //63 $path = substr($path, 0, strlen($path) - 1);64 // back up one level in path65 //66 if (strpos($path, '/') != false) {67 // strip from end until next slash68 //69 $path = substr($path, 0, strrpos($path, '/') + 1);70 } else {71 // path is empty72 //73 $path = '';74 }75 }76 // move directory names from file to path77 //78 $slashPosition = strpos($file, '/');79 if ($slashPosition) {80 $filepath = substr($file, 0, $slashPosition + 1);81 $filename = substr($file, $slashPosition + 1);82 $path = $path.$filepath;83 $file = $filename;84 }85 }86 function concatPaths(?string $path1, ?string $path2): string {87 // check if both paths exist88 //89 if (!$path1 || $path1 == '') {90 $path = $path2;91 } else if (!$path2 || $path2 == '') {92 $path = $path1;93 } else {94 // concatenate paths95 //96 $this->normalizePaths($path1, $path2);97 $path = $this->toPath($path1) . $this->toPath($path2);98 }99 if ($path == '') {100 $path = '.';101 }102 return $path;103 }104 function toPathName(?string $path): ?string {105 // strip trailing slash106 // 107 if (StringUtils::endsWith($path, '/')) {108 $path = substr($path, 0, strlen($path) - 1);109 }110 // add quotation marks if necessary111 //112 if (StringUtils::contains($path, ' ')) {113 $path = '"' . $path . '"';114 }115 return $path;116 }117 //118 // public methods119 //120 public function getRoot(bool $trim = true, bool $pad = true): ?string {121 $list = $this->getFileInfoList(null, null, false, $trim);122 $names = $this->infoListToNames($list, $trim);123 return $this->getRootDirectoryName($names, $trim, $pad);124 }125 public function getExtension(): ?string {126 return pathinfo($this->path, PATHINFO_EXTENSION);127 }128 public function find(?string $path, string $filter = null, bool $recursive = false): ?string {129 $info = $this->getFileInfoList($path, $filter, $recursive);130 $names = $this->infoArrayToNames($info);131 if ($names) {132 $name = $names[0];133 // strip leading ./ from name134 //135 if (StringUtils::startsWith($name, './')) {136 $name = substr($name, 2);137 }138 return $name;139 }140 return null;141 }142 public function getListing(?string $path, string $filter = null, bool $recursive = false): array {143 $info = $this->getFileInfoList($path, $filter, $recursive);144 $names = $this->infoArrayToNames($info);145 // strip leading ./ from names146 //147 for ($i = 0; $i < sizeof($names); $i++) {148 if (StringUtils::startsWith($names[$i], './')) {149 $names[$i] = substr($names[$i], 2);150 }151 }152 return $names;153 }154 public function contains(?string $dirname, string $filename): bool {155 $this->normalizePaths($dirname, $filename);156 if (StringUtils::startsWith($dirname, './')) {157 $dirname = substr($names[$i], 2);158 }159 // look in top level of specified directory160 //161 if ($dirname && $dirname != '.') {162 $path = $dirname.$filename;163 } else {164 $path = $filename;165 }166 return in_array($path, $this->getListing($dirname));167 }168 public function search(?string $dirname, array $filenames, bool $recursive = true): ?string {169 foreach ($filenames as $filename) {170 $this->normalizePaths($dirname, $filename);171 }172 $info = $this->getFileInfoList($dirname, null, $recursive);173 $names = $this->infoArrayToNames($info);174 // strip leading ./ from names175 //176 for ($i = 0; $i < sizeof($names); $i++) {177 if (StringUtils::startsWith($names[$i], './')) {178 $names[$i] = substr($names[$i], 2);179 }180 }181 // sort names by nesting level, then alphabetically182 //183 usort($names, function($a, $b) {184 $aNesting = substr_count($a, '/');185 $bNesting = substr_count($b, '/');186 if ($aNesting != $bNesting) {187 return $aNesting > $bNesting;188 } else {189 return $a > $b;190 }191 });192 for ($i = 0; $i < sizeof($names); $i++) {193 $name = $names[$i];194 for ($j = 0; $j < sizeof($filenames); $j++) {195 if (basename($name) == $filenames[$j]) {196 return $name;197 }198 }199 }200 return null;201 }202 public function found(?string $dirname, ?string $filter, bool $recursive = false): bool {203 $this->normalizePaths($dirname, $filter);204 return sizeof($this->getFileInfoList($dirname, $filter, $recursive)) != 0;205 }206 public function getFileInfoTree(?string $dirname, ?string $filter): array {207 $list = $this->getFileInfoList($dirname, $filter);208 return $this->directoryInfoListToTree($list);209 }210 public function getDirectoryInfoTree(?string $dirname, ?string $filter): array {211 $list = $this->getDirectoryInfoList($dirname, $filter);212 return $this->directoryInfoListToTree($list);213 }214 //215 // protected directory utility methods216 //217 public function getRootDirectoryName(array $array, bool $trim = true, bool $pad = true): string {218 if (sizeof($array) == 0) {219 if (!$pad) {220 return '';221 } else {222 return './';223 }224 }225 // take the first item as initial prefix226 //227 $prefix = $array[0];228 $length = strlen($prefix);229 // find the common prefix230 //231 foreach ($array as $name) {232 // strip leading ./233 //234 if ($trim) {235 if (StringUtils::startsWith($name, './')) {236 $name = substr($name, 2);237 }238 }239 // check if there is a match; if not, decrease the prefix length by one240 //241 while ($length > 0 && substr($name, 0, $length) !== $prefix) {242 $length--;243 $prefix = substr($prefix, 0, $length);244 }245 }246 // find directory name of common prefix247 //248 $last = strpos($prefix, '/');249 if ($last != false) {250 $prefix = substr($prefix, 0, $last + 1);251 } else {252 $prefix = null;253 }254 if (!$prefix) {255 if (!$pad) {256 $prefix = '';257 } else {258 $prefix = './';259 }260 }261 return $prefix;262 }263 protected function isDirectoryName(?string $path): bool {264 return $path[strlen($path) - 1] == '/';265 }266 protected function addName(string $name, array &$dirnames) {267 if (!in_array($name, $dirnames)) {268 // add directory of name269 //270 $dirname = dirname($name);271 if ($dirname != '.' && $dirname != './') {272 $this->addName($dirname.'/', $dirnames);273 }274 // add name275 //276 array_push($dirnames, $name);277 }278 }279 protected function getFileAndDirectoryNames(array $names, bool $trim = true): array {280 $dirnames = [];281 for ($i = 0; $i < sizeof($names); $i++) {282 $name = $names[$i];283 // strip leading ./284 //285 if ($trim && StringUtils::startsWith($name, './')) {286 $name = substr($name, 2);287 }288 if ($name && !in_array($name, $dirnames)) {289 // add directory of name290 //291 $dirname = dirname($name);292 if ($dirname != '.') {293 $this->addName($dirname . '/', $dirnames);294 }295 // add file or directory296 //297 array_push($dirnames, $name);298 }299 }300 return $dirnames;301 }302 //303 // protected file and directory name filtering methods304 //305 protected function getDirectoryNames(array $names): array {306 $directoryNames = [];307 for ($i = 0; $i < sizeof($names); $i++) {308 $name = $names[$i];309 if ($this->isDirectoryName($name)) {310 // strip leading ./311 //312 if (StringUtils::startsWith($name, './')) {313 $name = substr($name, 2);314 }315 array_push($directoryNames, $name);316 }317 }318 return $directoryNames;319 }320 protected function getFileNames(array $names): array {321 $fileNames = [];322 for ($i = 0; $i < sizeof($names); $i++) {323 $name = $names[$i];324 if (!$this->isDirectoryName($name)) {325 // strip leading ./326 //327 if (StringUtils::startsWith($name, './')) {328 $name = substr($name, 2);329 }330 array_push($fileNames, $name);331 }332 }333 return $fileNames;334 }335 //336 // protected name / directory filtering methods337 //338 protected function getNamesInDirectory(array $names, string $dirname = null, bool $recursive = false, bool $trim = true): array {339 $dirnames = [];340 // make sure that dirname ends with a slash341 //342 if (!StringUtils::endsWith($dirname, '/')) {343 $dirname = $dirname.'/';344 }345 if (!$dirname) {346 if ($recursive) {347 // return all348 //349 for ($i = 0; $i < sizeof($names); $i++) {350 $name = $names[$i];351 // strip leading ./352 //353 if (StringUtils::startsWith($name, './')) {354 $name = substr($name, 2);355 }356 array_push($dirnames, $name);357 }358 return $dirnames;359 } else {360 // return top level items361 //362 for ($i = 0; $i < sizeof($names); $i++) {363 $name = $names[$i];364 // strip leading ./365 //366 if (StringUtils::startsWith($name, './')) {367 $name = substr($name, 2);368 }369 if (!StringUtils::contains($name, '/')) {370 array_push($dirnames, $name);371 }372 }373 return $dirnames;374 }375 }376 // get names that are part of target directory377 //378 for ($i = 0; $i < sizeof($names); $i++) {379 $name = $names[$i];380 // strip leading ./381 //382 if ($trim) {383 if (StringUtils::startsWith($name, './')) {384 $name = substr($name, 2);385 }386 }387 if ($recursive) {388 if (StringUtils::startsWith(dirname($name).'/', $dirname)) {389 array_push($dirnames, $name);390 }391 } else {392 if (dirname($name).'/' == $dirname) {393 array_push($dirnames, $name);394 }395 }396 }397 return $dirnames;398 }399 protected function getNamesNestedInDirectory(array $names, string $dirname = null): array {400 // return all if no dirname401 //402 if (!$dirname) {403 $dirnames = [];404 for ($i = 0; $i < sizeof($names); $i++) {405 $name = $names[$i];406 // strip leading ./407 //408 if (StringUtils::startsWith($name, './')) {409 $name = substr($name, 2);410 }411 array_push($dirnames, $name);412 }413 return $dirnames;414 }415 // get names that are part of target directory (nested)416 //417 $dirnames = [];418 for ($i = 0; $i < sizeof($names); $i++) {419 $name = $names[$i];420 // strip leading ./421 //422 if (StringUtils::startsWith($name, './')) {423 $name = substr($name, 2);424 }425 if (StringUtils::startsWith($name, $dirname)) {426 array_push($dirnames, $name);427 }428 }429 return $dirnames;430 }431 protected function getFilteredNames(array $names, string $filter): array {432 // return all if no filter433 //434 if (!$filter) {435 return $names;436 }437 // get names that are inside of target directory438 //439 $filteredNames = [];440 for ($i = 0; $i < sizeof($names); $i++) {441 $name = basename($names[$i]);442 if (StringUtils::startsWith($filter, '/')) {443 // use regular expression444 //445 if (preg_match($filter, $name)) {446 array_push($filteredNames, $names[$i]);447 } 448 } else {449 // use string match450 //451 if ($filter == $name || $filter == basename($name)) {452 array_push($filteredNames, $names[$i]);453 } 454 }455 }456 return $filteredNames;457 }458 //459 // protected file name / info conversion methods460 //461 protected function nameToInfo(string $name): array {462 return [463 'name' => $name464 ];465 }466 protected function namesToInfoArray(array $names): array {467 $info = [];468 foreach ($names as $name) {469 array_push($info, $this->nameToInfo($name));470 }471 return $info;472 }473 protected function infoArrayToNames(array $info): array {474 $names = [];475 foreach ($info as $item) {476 array_push($names, $item['name']);477 }478 return $names;479 }480 //481 // protected file type inspection methods482 //483 protected function getFileTypesFromNames(array $names): array {484 $fileTypes = [];485 for ($i = 0; $i < sizeof($names); $i++) {486 $name = $names[$i];487 $extension = pathinfo($name, PATHINFO_EXTENSION);488 if (array_key_exists($extension, $fileTypes)) {489 $fileTypes[$extension]++;490 } else {491 $fileTypes[$extension] = 1;492 }493 }494 return $fileTypes;495 }496 //497 // protected archive methods498 //499 protected function addPath(string $path, array &$names) {500 if ($path && $path != '.' && $path != '/' && !in_array($path, $names)) {501 // add parent dirname502 //503 $dirname = dirname($path);504 if ($dirname && $dirname != '.' && $dirname != '/') {505 $this->addPath($dirname.'/', $names);506 }507 // add path508 //509 array_push($names, $path);510 }511 }512 protected function containsDirectoryNames(string $names): bool {513 foreach ($names as $value) {514 if (StringUtils::endsWith($value, '/')) {515 return true;516 }517 }518 return false;519 }520 protected function inferDirectoryNames(array $names): array {521 foreach ($names as $value) {522 // for each file name523 //524 if (!StringUtils::endsWith($value, '/')) {525 $terms = explode('/', $value);526 if (sizeof($terms) > 1) {527 // iterate over directory names528 //529 $path = '';530 foreach (array_slice($terms, 0, -1) as $directory) {531 // compose path532 //533 $path .= $directory.'/'; 534 // add new paths to list535 //536 if (!in_array($path, $names)) {537 array_push($names, $path);538 }539 }540 }541 }542 }543 // sort names so that new paths are not at the end544 //545 sort($names);546 return $names;547 }548 //549 // protected directory list to tree conversion methods550 //551 public function infoListToNames(array $list, bool $trim = true): array {552 $names = [];553 for ($i = 0; $i < sizeof($list); $i++) {554 $name = $list[$i]['name'];555 // strip leading ./556 //557 if ($trim && StringUtils::startsWith($name, './')) {558 $name = substr($name, 2);559 }560 array_push($names, $name);561 }562 return $names;563 }564 protected function directoryInfoListToTree(array $list): array {565 $tree = [];566 function &findLeaf(&$tree, $name) {567 // strip leading ./568 //569 if (StringUtils::startsWith($name, './')) {570 $name = substr($name, 2);571 }572 for ($i = 0; $i < sizeof($tree); $i++) {573 $treeName = $tree[$i]['name'];574 // strip leading ./575 //576 if (StringUtils::startsWith($treeName, './')) {577 $treeName = substr($treeName, 2);578 }579 if ($treeName == $name) {580 return $tree[$i];581 } else if (array_key_exists('contents', $tree[$i])) {582 $leaf = &findLeaf($tree[$i]['contents'], $name);583 if ($leaf != null) {584 return $leaf;585 }586 }587 }588 $leaf = null;589 return $leaf;590 }591 for ($i = 0; $i < sizeof($list); $i++) {592 $item = $list[$i];593 $dirname = dirname($item['name']);594 // strip leading ./595 //596 if (StringUtils::startsWith($dirname, './')) {597 $dirname = substr($dirname, 2);598 }599 // search for item in tree600 //601 $leaf = &findLeaf($tree, $dirname != '/'? $dirname.'/' : $dirname);602 if ($leaf != null) {603 // create directory contents604 //605 if (!array_key_exists('contents', $leaf)) {606 $leaf['contents'] = [];607 }608 // add item to leaf609 //610 array_push($leaf['contents'], $item);...

Full Screen

Full Screen

StringUtilsTest.php

Source:StringUtilsTest.php Github

copy

Full Screen

...46 );47 }48 public function testStartsWith(): void49 {50 $this->assertTrue(StringUtils::startsWith('Строка для поиска', 'Строка'));51 $this->assertFalse(StringUtils::startsWith('Строка для поиска', 'Строка '));52 $this->assertFalse(StringUtils::startsWith('Строка для поиска', 'для'));53 $this->assertTrue(StringUtils::startsWith('Строка для поиска', ['строка', 'Строка']));54 $this->assertFalse(StringUtils::startsWith('Строка для поиска', ['строка']));55 $this->assertTrue(StringUtils::startsWith('Some string for searching', 'Some'));56 $this->assertFalse(StringUtils::startsWith('Some string for searching', 'Some '));57 $this->assertFalse(StringUtils::startsWith('Some string for searching', 'for'));58 $this->assertTrue(StringUtils::startsWith('Some string for searching', ['some', 'Some']));59 $this->assertFalse(StringUtils::startsWith('Some string for searching', ['some']));60 $this->assertFalse(StringUtils::startsWith('Some string for searching', [null, new \stdClass()]));61 $this->assertTrue(StringUtils::startsWith('Some string for searching', 'Some string for searching'));62 }63 public function testEndsWith(): void64 {65 $this->assertTrue(StringUtils::endsWith('Строка для поиска', 'поиска'));66 $this->assertFalse(StringUtils::endsWith('Строка для поиска', ' поиска'));67 $this->assertFalse(StringUtils::endsWith('Строка для поиска', 'для'));68 $this->assertTrue(StringUtils::endsWith('Строка для поиска', ['строка', 'ска']));69 $this->assertFalse(StringUtils::endsWith('Строка для поиска', ['по']));70 $this->assertTrue(StringUtils::endsWith('Some string for searching', 'ing'));71 $this->assertFalse(StringUtils::endsWith('Some string for searching', 'search'));72 $this->assertFalse(StringUtils::endsWith('Some string for searching', 'for'));73 $this->assertFalse(StringUtils::endsWith('Some string for searching', ['some']));74 $this->assertFalse(StringUtils::endsWith('Some string for searching', [null, new \stdClass()]));75 $this->assertTrue(StringUtils::endsWith('Some string for searching', 'Some string for searching'));...

Full Screen

Full Screen

StringUtilsTestCase.php

Source:StringUtilsTestCase.php Github

copy

Full Screen

...99 $this->stringUtils->urlEncodeQuotes($input)100 );101 }102 /**103 * Tests the startsWith function. This test tests a valid call104 */105 function testStartsWith1 ()106 {107 $input1 = "Barry";108 $input2 = "Barry is a programmer";109 $this->assertTrue (110 $this->stringUtils->startsWith ($input2, $input1));111 }112 /**113 * Tests the startsWith function. This test tests a call with114 * will result in failure (i.e. the function returns false)115 */116 function testStartsWith2 ()117 {118 $input1 = "Genevieve";119 $input2 = "Barry is a programmer";120 $this->assertFalse (121 $this->stringUtils->startsWith ($input2, $input1));122 }123 /**124 * Tests the startsWith function. This test tests a call with125 * null as first input parameter126 */127 function testStartsWith3 ()128 {129 $input1 = null;130 $input2 = "Barry is a programmer";131 $this->assertFalse (132 $this->stringUtils->startsWith ($input2, $input1));133 }134 /**135 * Tests the startsWith function. This test tests a call with136 * null as second input parameter137 */138 function testStartsWith4 ()139 {140 $input1 = 'Barry';141 $input2 = null;142 $this->assertFalse (143 $this->stringUtils->startsWith ($input2, $input1));144 }145 /**146 * Tests the startsWith function. This test tests a call with147 * null as both first and second input parameter148 */149 function testStartsWith5 ()150 {151 $input1 = null;152 $input2 = null;153 $this->assertFalse (154 $this->stringUtils->startsWith ($input2, $input1));155 }156 /**157 * Tests the startsWith function. This test tests a call with158 * both input strings equal (and not null).159 */160 function testStartsWith6 ()161 {162 $input1 = "Barry is a programmer";163 $input2 = "Barry is a programmer";164 $this->assertTrue (165 $this->stringUtils->startsWith ($input2, $input1));166 }167 /**168 * Test for the get property function. Basic functionality is tested169 * (getProperty ('name=value', 'name') should return 'value'170 */171 function testGetProperty1 ()172 {173 $input = "name=value";174 $property = "name";175 $expectedOutput = "value";176 $this->assertEqual (177 $this->stringUtils->getProperty ($input, $property),178 $expectedOutput179 );...

Full Screen

Full Screen

StringGherkinLine.php

Source:StringGherkinLine.php Github

copy

Full Screen

...29 }30 return StringUtils::substring($this->lineText, $indentToRemove);31 }32 /** @param non-empty-string $keyword */33 public function startsWithTitleKeyword(string $keyword): bool34 {35 $textLength = StringUtils::symbolCount($keyword);36 return StringUtils::symbolCount($this->trimmedLineText) > $textLength37 && StringUtils::startsWith($this->trimmedLineText, $keyword)38 && StringUtils::subString(39 $this->trimmedLineText,40 $textLength,41 StringUtils::symbolCount(GherkinLanguageConstants::TITLE_KEYWORD_SEPARATOR),42 ) === GherkinLanguageConstants::TITLE_KEYWORD_SEPARATOR;43 }44 public function getRestTrimmed(int $length): string45 {46 return StringUtils::trim(StringUtils::substring($this->trimmedLineText, $length));47 }48 public function isEmpty(): bool49 {50 return StringUtils::symbolCount($this->trimmedLineText) === 0;51 }52 public function startsWith(string $string): bool53 {54 return StringUtils::startsWith($this->trimmedLineText, $string);55 }56 /** @return list<GherkinLineSpan> */57 public function getTableCells(): array58 {59 /**60 * @var list<array{0:string, 1:int}> $splitCells guaranteed by PREG_SPLIT_OFFSET_CAPTURE61 */62 $splitCells = preg_split(self::CELL_PATTERN, $this->lineText, flags: PREG_SPLIT_OFFSET_CAPTURE);63 // Safely remove elements before the first and last separators64 array_shift($splitCells);65 array_pop($splitCells);66 return array_map(67 function ($match) {68 [$cell, $byteOffset] = $match;...

Full Screen

Full Screen

PhpbobAnalyzingUtils.php

Source:PhpbobAnalyzingUtils.php Github

copy

Full Screen

...24 25 public static function isInterfaceStatement(PhpStatement $phpStatement) {26 if (!($phpStatement instanceof StatementGroup)) return false;27 28 return StringUtils::startsWith(Phpbob::KEYWORD_INTERFACE,29 ltrim(strtolower($phpStatement->getCode())));30 }31 32 public static function isTraitStatement(PhpStatement $phpStatement) {33 if (!($phpStatement instanceof StatementGroup)) return false;34 35 return StringUtils::startsWith(Phpbob::KEYWORD_TRAIT,36 ltrim(strtolower($phpStatement->getCode())));37 }38 39 public static function isPropertyStatement(PhpStatement $phpStatement) {40 return $phpStatement instanceof SingleStatement41 && preg_match('/(' . preg_quote(Phpbob::CLASSIFIER_PRIVATE) .42 '|' . preg_quote(Phpbob::CLASSIFIER_PROTECTED) .43 '|' . preg_quote(Phpbob::CLASSIFIER_PUBLIC) . ')\s+('44 . preg_quote(Phpbob::KEYWORD_STATIC) . '\s+)?' .45 preg_quote(Phpbob::VARIABLE_PREFIX) . '/i', $phpStatement->getCode());46 }47 48 public static function isConstStatement(PhpStatement $phpStatement) {49 return $phpStatement instanceof SingleStatement50 && StringUtils::startsWith(Phpbob::KEYWORD_CONST, ltrim(strtolower($phpStatement->getCode())));51 }52 53 public static function isAnnotationStatement(PhpStatement $phpStatement) {54 return self::isMethodStatement($phpStatement)55 && preg_match('/private\s+static\s+function\s+_annos.*\(.*\)/i',56 $phpStatement->getCode());57 }58 59 public static function isMethodStatement(PhpStatement $phpStatement) {60 return !!preg_match('/' . preg_quote(Phpbob::KEYWORD_FUNCTION)61 . '.*\(.*\)/i', $phpStatement->getCode());62 }63 64 public static function isNamespaceStatement(PhpStatement $phpStatement) {65 return $phpStatement instanceof SingleStatement66 && preg_match('/^\s*' . preg_quote(Phpbob::KEYWORD_NAMESPACE) . '\s+/i', $phpStatement->getCode());67 }68 69 public static function isUseStatement(PhpStatement $phpStatement) {70 return $phpStatement instanceof SingleStatement71 && StringUtils::startsWith(Phpbob::KEYWORD_USE, ltrim(strtolower($phpStatement->getCode())));72 }73 74 public static function isTraitUseStatement(PhpStatement $phpStatement) {75 return StringUtils::startsWith(Phpbob::KEYWORD_USE, ltrim(strtolower($phpStatement->getCode())));76 }77 78 public static function purifyPropertyName($propertyName) {79 return str_replace(array(Phpbob::VARIABLE_PREFIX, Phpbob::VARIABLE_REFERENCE_PREFIX), '', $propertyName);80 } ...

Full Screen

Full Screen

NqlUtils.php

Source:NqlUtils.php Github

copy

Full Screen

...30 return in_array(mb_strtoupper($str), Nql::getNoticeableKeyWords());31 }32 33 public static function isPlaceholder(string $str) {34 return StringUtils::startsWith(Nql::PLACHOLDER_PREFIX, $str);35 }36 37 public static function isFunction(string $str) {38 return in_array(mb_strtoupper($str), CriteriaFunction::getNames());39 }40 41 public static function isConst(string $str) {42 return Nql::isKeywordTrue($str) || Nql::isKeywordFalse($str) || Nql::isKeywordNull($str) 43 || is_numeric($str) || Nql::isLiteral($str);44 }45 46 public static function parseConst(string $str) {47 if (Nql::isKeywordTrue($str)) {48 return true;49 }50 51 if (Nql::isKeywordFalse($str)) {52 return false;53 }54 55 if (Nql::isKeywordNull($str)) {56 return null;57 }58 59 if (is_numeric($str)) {60 return $str;61 }62 63 if (Nql::isLiteral($str)) {64 return mb_substr($str, 1, -1);65 }66 67 throw new \InvalidArgumentException($str . ' is not a Const');68 }69 70 public static function isCriteria(string $str) {71 return StringUtils::pregMatch('/^\s*' . Nql::KEYWORD_SELECT . '\s+/', $str) > 0 72 || StringUtils::pregMatch('/^\s*' . Nql::KEYWORD_FROM . '\s+/', $str) > 0;73 }74 75 public static function isQuoted(string $str) {76 return StringUtils::startsWith('"', $str) && StringUtils::endsWith('"', $str);77 }78 79 public static function isQuotationMark(string $token) {80 return $token === Nql::QUOTATION_MARK;81 }82 83 public static function removeQuotationMarks(string $expression) {84 if ((StringUtils::startsWith('"', $expression) && StringUtils::endsWith('"', $expression))85 /* || (StringUtils::startsWith('`', $entityName) && StringUtils::endsWith('`', $entityName)) */) {86 $expression = mb_substr($expression, 1, -1);87 }88 return $expression;89 }90 91 public static function removeLiteralIndicator(string $expression) {92 if (Nql::isLiteral($expression)) {93 return mb_substr($expression, 1, -1);94 }95 return $expression;96 } ...

Full Screen

Full Screen

StringUtils.php

Source:StringUtils.php Github

copy

Full Screen

...5 */6namespace common\helpers;7class StringUtils8{9 public static function startsWith($s, $prefix)10 {11 return empty($prefix) || strpos($s, $prefix) === 0;12 }13 public static function endsWith($s, $suffix)14 {15 return empty($suffix) || substr($s, -strlen($suffix)) === $suffix;16 }17 public static function contain($s, $subStr)18 {19 if (empty($subStr)) return true;20 return strpos($s, $subStr) !== false;21 }22 /**23 * @param $s124 * @param $s225 * @return bool26 */27 public static function equal($s1, $s2)28 {29 return strcmp($s1, $s2) === 0;30 }31 public static function removeTail($s, $tail)32 {33 if (empty($tail) || !StringUtils::endsWith($s, $tail)) {34 return $s;35 }36 return substr($s, 0, -strlen($tail));37 }38 public static function removeHead($s, $head)39 {40 if (empty($head) || !StringUtils::startsWith($s, $head)) {41 return $s;42 }43 return substr($s, strlen($head));44 }45 /**46 * Convert camel string (BeUser) to dash format (be-user)47 * @param $s48 * @param $head49 * @return string50 */51 public static function camel2Dash($s)52 {53// $s2 = preg_replace("%([A-Z])%se", "'-' . strtolower('\\1')",$s);54 $s2 = preg_replace_callback("%([A-Z])%s", function ($m) {55 return '-' . strtolower($m[1]);56 }, $s);57 if (!StringUtils::startsWith($s, '-')) {58 $s2 = StringUtils::removeHead($s2, '-');59 }60 return $s2;61 }62 public static function randomStr($code_length = 10)63 {64 $code = "";65 $raw_code = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";66 $raw_code_length = strlen($raw_code);67 for ($i = 0; $i < $code_length; $i++) {68 $code .= $raw_code[rand(0, $raw_code_length - 1)];69 }70 return $code;71 }...

Full Screen

Full Screen

LineTypeDetector.php

Source:LineTypeDetector.php Github

copy

Full Screen

...16 private const FILE_DELETED = '+++ /dev/null';17 private const FILE_ADDED = '--- /dev/null';18 public static function isStartOfFileDiff(string $line): bool19 {20 return StringUtils::startsWith(self::FILE_DIFF_START, $line);21 }22 public static function isDeletedFile(string $line): bool23 {24 return StringUtils::startsWith(self::FILE_DELETED, $line);25 }26 public static function isFileAdded(string $line): bool27 {28 return StringUtils::startsWith(self::FILE_ADDED, $line);29 }30 public static function isStartOfChangeHunk(string $line): bool31 {32 return StringUtils::startsWith(self::CHANGE_HUNK_START, $line);33 }34}...

Full Screen

Full Screen

startsWith

Using AI Code Generation

copy

Full Screen

1require_once 'StringUtils.php';2echo StringUtils::startsWith('hello world', 'hello');3require_once 'StringUtils.php';4echo StringUtils::endsWith('hello world', 'world');5require_once 'StringUtils.php';6echo StringUtils::contains('hello world', 'world');7require_once 'StringUtils.php';8echo StringUtils::reverse('hello world');9require_once 'StringUtils.php';10echo StringUtils::capitalize('hello world');11require_once 'StringUtils.php';12echo StringUtils::lowerCase('HELLO WORLD');13require_once 'StringUtils.php';14echo StringUtils::upperCase('hello world');15require_once 'StringUtils.php';16echo StringUtils::length('hello world');17require_once 'StringUtils.php';18echo StringUtils::trim(' hello world ');19require_once 'StringUtils.php';20echo StringUtils::ltrim(' hello world ');21require_once 'StringUtils.php';22echo StringUtils::rtrim(' hello world ');23require_once 'StringUtils.php';24print_r(StringUtils::toCharArray('hello world'));25require_once 'StringUtils.php';26echo StringUtils::replace('hello world', 'world', 'php');27require_once 'StringUtils.php';28echo StringUtils::replaceAll('hello world', 'o', '0');29require_once 'StringUtils.php';30print_r(StringUtils::split('hello world', ' '));

Full Screen

Full Screen

startsWith

Using AI Code Generation

copy

Full Screen

1require_once 'StringUtils.php';2$testString = "This is a test string";3if(StringUtils::startsWith($testString, "This")){4 echo "String starts with 'This'";5}6require_once 'StringUtils.php';7$testString = "This is a test string";8if(StringUtils::endsWith($testString, "string")){9 echo "String ends with 'string'";10}

Full Screen

Full Screen

startsWith

Using AI Code Generation

copy

Full Screen

1require_once 'StringUtils.php';2$myString = 'Hello World';3$myString2 = 'Hello';4if(StringUtils::startsWith($myString, $myString2)) {5 echo 'String '.$myString.' starts with '.$myString2;6} else {7 echo 'String '.$myString.' does not start with '.$myString2;8}

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Gherkin-php automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Trigger startsWith code on LambdaTest Cloud Grid

Execute automation tests with startsWith on a cloud-based Grid of 3000+ real browsers and operating systems for both web and mobile applications.

Test now for Free

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful