Replace char with null bytes inside (optionally specified) enclosure

@param string $str
@param string $search_char
@param string $enclosure_open
@param string $enclosure_close

@return string $str
195480
private static function replaceCharInsideEnclosure($str, $search_char, $enclosure_open='(', $enclosure_close=')')
    {
        if ($str === '' || strpos($str, $search_char) === false || strpos($str, $enclosure_open) === false) {
            return $str;
        }

        for ($i = 0, $str_length = \strlen($str); $i < $str_length; $i++) {
            if ($i > 0 && $str[$i] === $search_char) {
                // check if enclosure is open by counting char before position
                $enclosure_is_open = substr_count($str, $enclosure_open, 0, $i) !== substr_count($str, $enclosure_close, 0, $i);
                if ($enclosure_is_open) {
                    $str[$i] = "\0";
                }
            }
        }

        return $str;
    }
301501
public static function substr_replace($string, $replacement, $start , $length=null )
    {
        $ret = '';
        if($start>0) $ret .= self::substr($string, 0, $start);
        $ret .= $replacement;
        if($length!=null) $ret .= self::substr($string, $start+$length);
        return $ret;
    }
573970
public static function shyphenate($str)
    {
        $res = preg_match_all('/([a-z0-9]{19,})/i', $str, $matches);

        if ($res) {
            foreach ($matches[1] as $key => $match) {
                $str = str_replace($match, wordwrap($match, 10, '&shy;', true), $str);
            }
        }

        return $str;
    }
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;
	}
1277497
protected function nextChar(string $str, int &$p): ?string
    {
        $p += strspn($str, " \t\r\n", $p);
        return isset($str[$p]) ? $str[$p] : null;
    }
269192
public function wrap($str, $wrap)
    {
        return (is_string($str) && $str !== '') ? $wrap.$str.$wrap : $str;
    }
20572
private function escapeValue(&$str): string
    {
        $search = [
            $this->symbRel,
            $this->sepComp,
            $this->sepData,
            $this->symbEnd,
        ];
        $replace = [
            $this->symbRel . $this->symbRel,
            $this->symbRel . $this->sepComp,
            $this->symbRel . $this->sepData,
            $this->symbRel . $this->symbEnd,
        ];

        return \str_replace($search, $replace, $str);
    }
467593
public static function replaceRoman(string $str) : string
    {
        $str = self::strToArray($str);
        return implode('', self::replaceRomanArray($str));
    }
948703
@Override
    public FastStr replace(char oldChar, char newChar) {
        if (oldChar != newChar) {
            char[] val = this.buf; /* avoid getfield opcode */
            int len = length();
            int i = begin - 1;

            while (++i < end) {
                if (val[i] == oldChar) {
                    break;
                }
            }
            if (i < end) {
                char buf[] = new char[len];
                for (int j = begin; j < i; j++) {
                    buf[j - begin] = val[j];
                }
                while (i < end) {
                    char c = val[i];
                    buf[i - begin] = (c == oldChar) ? newChar : c;
                    i++;
                }
                return new FastStr(buf, 0, len);
            }
        }
        return this;
    }
1286858
public static Opt<String> getNonEmptyString(String str) {
        return Opt.ofNullable(emptyToNull(str.trim()));
    }
1019271
public static boolean isEmpty(String str) {
    return str == null || "".equals(str) || "".equals(str.trim());
  }
702230
@Nullable
  public static String wrapBidi (@Nullable final String sStr, final char cChar)
  {
    switch (cChar)
    {
      case RLE:
        return _wrap (sStr, RLE, PDF);
      case RLO:
        return _wrap (sStr, RLO, PDF);
      case LRE:
        return _wrap (sStr, LRE, PDF);
      case LRO:
        return _wrap (sStr, LRO, PDF);
      case RLM:
        return _wrap (sStr, RLM, RLM);
      case LRM:
        return _wrap (sStr, LRM, LRM);
      default:
        return sStr;
    }
  }
49921
public static String emptyToNull(String str) {
        return (str != null && !str.isEmpty()) ? str : null;
    }
746782
def remove_enclosure(self, left_char, right_char):
        
        assert len(left_char) == 1, \
            "Parameter left_char must be character not string"
        assert len(right_char) == 1, \
            "Parameter right_char must be character not string"
        rm_enclosure = (left_char, right_char)
        if rm_enclosure in self._enclosure:
            self._enclosure.remove(rm_enclosure)

        self._after_tld_chars = self._get_after_tld_chars()
979075
protected function _removeBlobWhenNonempty(&$str)
    {
        if ($str &&
            ($str[0] === '[') &&
            (($i = $this->_removeBlob($str, 0)) !== false) &&
            ($i !== strlen($str))) {
            $str = substr($str, $i);
            return true;
        }

        return false;
    }
3841
public static int indexOfIgnoreCase(final String str, final String searchStr) {// NOSONAR
		if (searchStr.isEmpty() || str.isEmpty()) {
			return str.indexOf(searchStr);
		}
		for (int i = 0; i < str.length(); ++i) {
			if (i + searchStr.length() > str.length()) {
				return -1;
			}
			int j = 0;
			int ii = i;
			while (ii < str.length() && j < searchStr.length()) {
				char c = Character.toLowerCase(str.charAt(ii));
				char c2 = Character.toLowerCase(searchStr.charAt(j));
				if (c != c2) {
					break;
				}
				j++;
				ii++;
			}
			if (j == searchStr.length()) {
				return i;
			}
		}
		return -1;
	}
165268
function (str) {
        // here:xx:xxx??inline
        var matches = /^<!--\s*here\:(.*?)\s*-->$/.exec(str.trim())
        if (!matches || !matches[1]) return null
        var expr = matches[1]
        var parts = expr.split('??')
        var query = querystring.parse(parts[1] || '')
        var isInline = ('inline' in query) && query.inline != 'false'
        var isWrapping = query.wrap !== 'false'
        var namespace = ''
        var reg

        expr = parts[0]
        parts = expr.split(':')
        if (parts.length > 1) {
            namespace = parts.shift()
        }
        reg = new RegExp(parts.pop())

        return {
            regexp: reg,          // resource match validate regexp
            namespace: namespace, // resource namespace match
            inline: isInline,      // whether inline resource or not
            wrap: isWrapping
        }
    }