HH\Lib\Str\replace_every_nonrecursive_ci_l

Meta Engineer?

This is available as Str\replace_every_nonrecursive_ci_l in the www repository.

Returns the "haystack" string with all occurrences of the keys of $replacements replaced by the corresponding values (case-insensitive)

namespace HH\Lib\Str;

function replace_every_nonrecursive_ci_l(
  \HH\Lib\Locale\Locale $locale,
  string $haystack,
  KeyedContainer<string, string> $replacements,
): string;

Once a substring has been replaced, its new value will not be searched again.

Locale-specific rules for case-insensitive comparisons will be used, and strings will be normalized before comparing if the locale specifies an encoding that supports multiple representations of the same characters, such as UTF-8.

If there are multiple overlapping matches, the match occuring earlier in $haystack takes precedence. If a replacer is a case-insensitive prefix of another (like "Car" and "CARPET"), the longer one (carpet) takes precedence. The ordering of $replacements therefore doesn't matter.

When two replacers are passed that are identical except for case, an InvalidArgumentException is thrown.

Time complexity: O(a + length * b), where a is the sum of all key lengths and b is the sum of distinct key lengths (length is the length of $haystack)

Guide

Parameters

Returns

  • string