Detect is character at specified position is inside of a comment

@param $haystack
@param $charPosition

@return bool
503753
protected function isCharInComment($haystack, $charPosition)
    {
        // check for line comment
        for ($c = $charPosition; $c > 0; --$c) {
            if ($haystack[$c] === PHP_EOL) {
                break;
            } elseif ($haystack[$c] === '#' or ($haystack[$c] === '/'
                    and ($haystack[$c + 1] === '/' or $haystack[$c - 1] === '/'))
            ) {
                return true;
            }
        }
        // check for block comment
        $openingsCount = 0;
        $closingsCount = 0;
        for ($c = $charPosition; $c > 0; --$c) {
            if ($haystack[$c] === '*' and $haystack[$c - 1] === '/') {
                ++$openingsCount;
            }
            if ($haystack[$c] === '/' and $haystack[$c - 1] === '*') {
                ++$closingsCount;
            }
        }
        if ($openingsCount !== $closingsCount) {
            return true;
        }
        return false;
    }
111756
public static function startsWith($haystack, $needle)
    {
        return $needle === '' or mb_strrpos($haystack, $needle, -mb_strlen($haystack)) !== false;
    }
182711
public static function strpos(string $haystack, string $needle, int $offset=0) {
		if (\function_exists('mb_strpos')) {
			return \mb_strpos($haystack, $needle, $offset, 'UTF-8');
		}

		return \strpos($haystack, $needle, $offset);
	}
187255
protected function string_contains( $haystack, $needles ) {
		foreach ( (array) $needles as $needle ) {
			if ( '' !== $needle && mb_strpos( $haystack, $needle ) !== false ) {
				return true;
			}
		}

		return false;
	}
417654
public static function stringEndsWith($haystack, $needle)
    {
        if (substr($haystack, - strlen($needle)) === $needle) {
            return true;
        }

        return false;
    }
169729
public static function strrpos(string $haystack, string $needle, int $offset=0) {
		if (\function_exists('mb_strrpos')) {
			return \mb_strrpos($haystack, $needle, $offset, 'UTF-8');
		}
		else {
			return \strrpos($haystack, $needle, $offset);
		}
	}
324604
public static function contains($haystack, $needle, $ignoreCase = false)
    {
        if ($ignoreCase) {
            $needle = strtolower($needle);
            $haystack = strtolower($haystack);
        }
        $pos = strpos($haystack, $needle);

        return !($pos === false);
    }
1291942
public static function words_match($haystack, $needle)
    {
        $a_needle  = self::tokenize_string($needle, 1);
        $_haystack = join(" ", self::tokenize_string($haystack, 1));
        $valid     = strlen($_haystack) > 0;
        $hits      = 0;

        foreach ($a_needle as $w) {
            if ($valid) {
                if (stripos($_haystack, $w) !== false) {
                    $hits++;
                }
            }
            else if (stripos($haystack, $w) !== false) {
                $hits++;
            }
        }

        return $hits >= count($a_needle);
    }
620040
public static function stringEndsWith($haystack, $needle)
    {
        if (!is_string($haystack) || !is_string($needle)) {
            throw new \InvalidArgumentException('Not a string');
        }

        return (strrpos($haystack, $needle) + strlen($needle)) === strlen($haystack);
    }
374853
public static function checkIfContainsAnyOf($haystack, $needles) {
		foreach ($needles as $needle) {
			if (self::checkIfContains($haystack, $needle)) return true;
		}
		return false;
	}
1013213
protected function stringHasStatement( $haystack, $needle ) {
		$pattern = '~^\s*(' . preg_quote( $needle, '~' ) . ')\s*$~m';
		return (bool) preg_match( $pattern, $haystack );
	}
991230
public function match($needle, $haystack)
    {
        $len = strlen($needle);

        /** @noinspection SubStrUsedAsStrPosInspection */
        return $len === 0 || substr($haystack, 0, $len) === $needle;
    }
691247
public static function hasKeys(array $haystack)
    {
        $fails = false;
        $keys = func_get_args();
        array_shift($keys);

        foreach ($keys as $key) {
            if (!array_key_exists($key, $haystack)) {
                $fails = true;
                break;
            }
        }

        return !$fails;
    }
64696
public function strpos($haystack, $needle, $offset = 0)
    {
        return iconv_strpos($haystack, $needle, $offset, $this->getEncoding());
    }
564123
public function strpos($haystack, $needle)
    {
        $hstck = '' . $haystack;
        $ndl = '' . $needle;
        if ($hstck === '' || $ndl === '') {
            return false;
        }
        if (static::$nativeSupport['mbstring']) {
            return mb_strpos($hstck, $ndl);
        }

        $pos = strpos($hstck, $ndl);
        if (!$pos) {
            return $pos;
        }
        return count(
            preg_split('//u', substr($hstck, 0, $pos), null, PREG_SPLIT_NO_EMPTY)
        );
    }
799191
public static function InString ($haystack, $needle, $part = FALSE, $encoding = Encoding::DEFAULT_ENCODING) {
		return mb_strstr($haystack, $needle, $part, $encoding) !== false;
	}
583910
public static function pos($haystack, $needle, $offset = 0)
    {
        if (self::isMBString()) {
            return mb_strpos($haystack, $needle, $offset, self::$encoding);
        }

        return strpos($haystack, $needle, $offset); // @codeCoverageIgnore
    }