Fixes slashes in path

@param string $str
@param bool|false $removeInitial
@param bool|false $removeTrailing

@return mixed|string
193035
public static function fixSlashes($str, $removeInitial = false, $removeTrailing = false)
    {
        $r = str_replace('//', '/', $str);

        if (\strlen($r) > 0) {
            if ($removeInitial && ($r[0] === '/')) {
                $r = substr($r, 1);
            }

            if ($removeTrailing && ($r[\strlen($r) - 1] === '/')) {
                $r = substr($r, 0, \strlen($r) - 1);
            }
        }

        return $r;
    }
1073068
private static function UnescapeReplacementString( $str )
	{
		$result = "";
		$charArr = str_split ( $str );

		for ( $k = 0; $k < count( $charArr ); $k++ )
		{
			if ( $charArr[ $k ] == '\\' )
			{
				if ( $k == count( $charArr ) - 1 )
					throw XPath2Exception::withErrorCodeAndParam( "FORX0004", Resources::FORX0004, $str );

					switch ( $charArr[ $k + 1 ] )
					{
						case 'n':
							$result .= "\n";
							break;

						case 'r':
							$result .="\r";
							break;

						case 't':
							$result .= "\t";
							break;

						case 'a':
							$result .= "\a";
							break;

						case '\\':
							$result .= "\\";
							break;

						default:
							throw XPath2Exception::withErrorCodeAndParam( "FORX0004", Resources::FORX0004, $str );
					}
					$k++;
			}
			else
				$result .= $charArr[ $k ];
		}
		return $result;
	}
846476
function _set_uri_string($str){
		// Filter out control characters
		$str = _removeInvisibleCharacters($str, FALSE);

		// If the URI contains only a slash we'll kill it
		$this->uri_string = ($str == '/') ? '' : $str;
		
	}
862484
public static function preBackSlash($str, $unify = false)
    {
        return self::_slash($str, '\\', true, true, $unify);
    }
568000
public static function cleanForOrder(string $str): string
  {
    $str = self::removeAccents($str);
    $str = preg_replace("/^[^a-z0-9 ]/i", "", $str);
    $str = trim($str);
    return $str;
  }
1047749
public function sanitize_filename($str, $relative_path = FALSE) {
		$bad = array("../", "<!--", "-->", "<", ">", "'", '"', '&', '$', '#', '{', '}', '[', ']', '=', ';', '?', "%20", "%22", "%3c", 		// <
		"%253c", 		// <
		"%3e", 		// >
		"%0e", 		// >
		"%28", 		// (
		"%29", 		// )
		"%2528", 		// (
		"%26", 		// &
		"%24", 		// $
		"%3f", 		// ?
		"%3b", 		// ;
		"%3d")		// =
		;
		
		if (!$relative_path) {
			$bad[] = './';
			$bad[] = '/';
		}
		
		$str = $this->remove_invisible_characters($str, FALSE);
		return stripslashes(str_replace($bad, '', $str));
	}
135272
function fix_eol($str) {
      $str = str_replace("\r\n", "\n", $str);
      $str = str_replace("\r", "\n", $str);
      $str = str_replace("\n", "\r\n", $str);
      return $str;
   }
1063891
public static function preDS($str, $unify = false)
    {
        return self::_slash($str, DIRECTORY_SEPARATOR, true, true, $unify);
    }
419353
public function filterTrace($str)
    {

        if (empty($this->options['backtrace_filters']) || !is_array($this->options['backtrace_filters'])) {
            return $str;
        }

        foreach ($this->options['backtrace_filters'] as $pattern => $replacement) {
            $str = preg_replace($pattern, $replacement, $str);
        }

        return $str;
    }
1195635
public static function trimSpaceInStr($str)
    {
        $pat = array(" ", "　", "\t", "\n", "\r");
        $string = array("", "", "", "", "", );
        return str_replace($pat, $string, $str);
    }
87481
public static function isArabic($str)
    {
        $isArabic = false;
        $arr      = self::identify($str);
        
        if (count($arr) == 1 && $arr[0] == 0) {
            $isArabic = true;
        }
        
        return $isArabic;
    }
854881
public static String removeLeadingAndTrailingDelimiter(String str, String delimiter) {
        final int strLength = str.length();
        final int delimiterLength = delimiter.length();

        final boolean leadingDelimiter = str.startsWith(delimiter);
        final boolean trailingDelimiter = strLength > delimiterLength && str.endsWith(delimiter);
        if (!leadingDelimiter && !trailingDelimiter) {
            return str;
        } else {
            final int startingDelimiterIndex = leadingDelimiter ? delimiterLength : 0;
            final int endingDelimiterIndex = trailingDelimiter ? Math.max(strLength - delimiterLength, startingDelimiterIndex) : strLength;
            return str.substring(startingDelimiterIndex, endingDelimiterIndex);
        }
    }
749435
public void removeString(String str)
    {
        if (sourceNode != null)
        {
            //Split the _transition path corresponding to str to ensure that
            //any other _transition paths sharing nodes with it are not affected
            splitTransitionPath(sourceNode, str);

            //Remove from equivalenceClassMDAGNodeHashMap, the entries of all the nodes in the _transition path corresponding to str.
            removeTransitionPathRegisterEntries(str);

            //Get the last node in the _transition path corresponding to str
            MDAGNode strEndNode = sourceNode.transition(str);
            if (strEndNode == null) return;

            if (!strEndNode.hasTransitions())
            {
                int soleInternalTransitionPathLength = calculateSoleTransitionPathLength(str);
                int internalTransitionPathLength = str.length() - 1;

                if (soleInternalTransitionPathLength == internalTransitionPathLength)
                {
                    sourceNode.removeOutgoingTransition(str.charAt(0));
                    transitionCount -= str.length();
                }
                else
                {
                    //Remove the sub-path in str's _transition path that is only used by str
                    int toBeRemovedTransitionLabelCharIndex = (internalTransitionPathLength - soleInternalTransitionPathLength);
                    MDAGNode latestNonSoloTransitionPathNode = sourceNode.transition(str.substring(0, toBeRemovedTransitionLabelCharIndex));
                    latestNonSoloTransitionPathNode.removeOutgoingTransition(str.charAt(toBeRemovedTransitionLabelCharIndex));
                    transitionCount -= str.substring(toBeRemovedTransitionLabelCharIndex).length();
                    /////

                    replaceOrRegister(sourceNode, str.substring(0, toBeRemovedTransitionLabelCharIndex));
                }

            }
            else
            {
                strEndNode.setAcceptStateStatus(false);
                replaceOrRegister(sourceNode, str);
            }
        }
        else
        {
            unSimplify();
        }
    }
1193570
public static function removeAccents($str)
	{
		// $from_chars = explode(',', 'À,Á,Â,Ã,Ä,Å,Ç,È,É,Ê,Ë,Ì,Í,Î,Ï,Ð,Ñ,Ò,Ó,Ô,Õ,Ö,Ø,Ǿ,Ù,Ú,Û,Ü,Ý,ß,à,á,â,ã,ä,å,ç,è,é,ê,ë,ì,í,î,ï,ð,ñ,ò,ó,ô,õ,ö,ø,ǿ,ù,ú,û,ü,ý,ÿ');
		// $to_chars	= str_split('AAAAAACEEEEIIIIDNOOOOOOOUUUUYBaaaaaaceeeeiiiionooooooouuuuyy');
		// $str = str_replace($from_chars, $to_chars, $str);
        $map = array(
			// single letters
            'à' => 'a', 'á' => 'a', 'â' => 'a', 'ã' => 'a', 'ä' => 'a', 'ą' => 'a', 'å' => 'a', 'ā' => 'a', 'ă' => 'a', 'ǎ' => 'a', 'ǻ' => 'a',
            'À' => 'A', 'Á' => 'A', 'Â' => 'A', 'Ã' => 'A', 'Ä' => 'A', 'Ą' => 'A', 'Å' => 'A', 'Ā' => 'A', 'Ă' => 'A', 'Ǎ' => 'A', 'Ǻ' => 'A',
			'ß' => 'B',
			'ç' => 'c', 'ć' => 'c', 'ĉ' => 'c', 'ċ' => 'c', 'č' => 'c',
			'Ç' => 'C', 'Ć' => 'C', 'Ĉ' => 'C', 'Ċ' => 'C', 'Č' => 'C',
			'ď' => 'd', 'đ' => 'd',
			'Ð' => 'D', 'Ď' => 'D', 'Đ' => 'D',
			'è' => 'e', 'é' => 'e', 'ê' => 'e', 'ë' => 'e', 'ę' => 'e', 'ē' => 'e', 'ĕ' => 'e', 'ė' => 'e', 'ě' => 'e',
			'È' => 'E', 'É' => 'E', 'Ê' => 'E', 'Ë' => 'E', 'Ę' => 'E', 'Ē' => 'E', 'Ĕ' => 'E', 'Ė' => 'E', 'Ě' => 'E',
			'ƒ' => 'f',
			'ĝ' => 'g', 'ğ' => 'g', 'ġ' => 'g', 'ģ' => 'g',
			'Ĝ' => 'G', 'Ğ' => 'G', 'Ġ' => 'G', 'Ģ' => 'G',
			'ĥ' => 'h', 'ħ' => 'h', 'Ĥ' => 'H', 'Ħ' => 'H',
			'ì' => 'i', 'í' => 'i', 'î' => 'i', 'ï' => 'i',
			'ĩ' => 'i', 'ī' => 'i', 'ĭ' => 'i', 'į' => 'i', 'ſ' => 'i', 'ǐ' => 'i', 'Ì' => 'I', 'Í' => 'I', 'Î' => 'I', 'Ï' => 'I', 'Ĩ' => 'I', 'Ī' => 'I', 'Ĭ' => 'I', 'Į' => 'I', 'İ' => 'I', 'Ǐ' => 'I',
			'ĵ' => 'j', 'Ĵ' => 'J',
			'ķ' => 'k', 'Ķ' => 'K',
			'ł' => 'l', 'ĺ' => 'l', 'ļ' => 'l', 'ľ' => 'l', 'ŀ' => 'l',
			'Ł' => 'L', 'Ĺ' => 'L', 'Ļ' => 'L', 'Ľ' => 'L', 'Ŀ' => 'L',
			'ñ' => 'n', 'ń' => 'n', 'ņ' => 'n', 'ň' => 'n', 'ŉ' => 'n',
			'Ñ' => 'N', 'Ń' => 'N', 'Ņ' => 'N', 'Ň' => 'N',
			'ò' => 'o', 'ó' => 'o', 'ô' => 'o', 'õ' => 'o', 'ö' => 'o', 'ð' => 'o', 'ø' => 'o', 'ō' => 'o', 'ŏ' => 'o', 'ő' => 'o', 'ơ' => 'o', 'ǒ' => 'o', 'ǿ' => 'o',
			'Ò' => 'O', 'Ó' => 'O', 'Ô' => 'O', 'Õ' => 'O', 'Ö' => 'O', 'Ø' => 'O', 'Ō' => 'O', 'Ŏ' => 'O', 'Ő' => 'O', 'Ơ' => 'O', 'Ǒ' => 'O', 'Ǿ' => 'O',
			'ŕ' => 'r', 'ŗ' => 'r', 'ř' => 'r',
			'Ŕ' => 'R', 'Ŗ' => 'R', 'Ř' => 'R',
			'ś' => 's', 'š' => 's', 'ŝ' => 's', 'ş' => 's',
			'Ś' => 'S', 'Š' => 'S', 'Ŝ' => 'S', 'Ş' => 'S',
			'ţ' => 't', 'ť' => 't', 'ŧ' => 't',
			'Ţ' => 'T', 'Ť' => 'T', 'Ŧ' => 'T',
			'ù' => 'u', 'ú' => 'u', 'û' => 'u', 'ü' => 'u', 'ũ' => 'u', 'ū' => 'u', 'ŭ' => 'u', 'ů' => 'u', 'ű' => 'u', 'ų' => 'u', 'ư' => 'u', 'ǔ' => 'u', 'ǖ' => 'u', 'ǘ' => 'u', 'ǚ' => 'u', 'ǜ' => 'u',
			'Ù' => 'U', 'Ú' => 'U', 'Û' => 'U', 'Ü' => 'U', 'Ũ' => 'U', 'Ū' => 'U', 'Ŭ' => 'U', 'Ů' => 'U', 'Ű' => 'U', 'Ų' => 'U', 'Ư' => 'U', 'Ǔ' => 'U', 'Ǖ' => 'U', 'Ǘ' => 'U', 'Ǚ' => 'U', 'Ǜ' => 'U',
			'ŵ' => 'w',
			'Ŵ' => 'W',
			'ý' => 'y', 'ÿ' => 'y', 'ŷ' => 'y',
			'Ý' => 'Y', 'Ÿ' => 'Y', 'Ŷ' => 'Y',
			'ż' => 'z', 'ź' => 'z', 'ž' => 'z',
			'Ż' => 'Z', 'Ź' => 'Z', 'Ž' => 'Z',
			// accentuated ligatures
			'Ǽ' => 'A',
			'ǽ' => 'a',
        );
		$str = self::toUtf8($str);
        $str = \strtr($str, $map);
		return $str;
	}
263227
function normalizeSlashes($str, $sep='/')
    {
        $result = preg_replace('/[\\/\\\]+/', $sep, $str);
        return $result === null ? '' : $result;
    }
750710
public static function unDS($str, $unify = false)
    {
        return self::_slash($str, DIRECTORY_SEPARATOR, false, false, $unify);
    }
149822
public static function cutStart(
        string $str,
        string $subString = ' ',
        bool $repeat = false,
        bool $caseSensitive = true
    ) : string {
        $prepared = RegEx::prepare($subString, '/');
        $regex = sprintf(
            '/^%s/%s',
            ($subString
                ? ($repeat ? RegexHelper::quantifyGroup($prepared, 0) : $prepared)
                : ''
            ),
            (!$caseSensitive ? 'i' : '')
        );

        return preg_replace($regex, '', $str);
    }