- // In case a title has a PUA code in it, make it sort
- // under the header for the character it would replace
- // to avoid inconsistent behaviour. This class mostly
- // assumes that people will not use PUA codes.
- return parent::getFirstLetter(
- str_replace( $this->puaSubset, $this->alphabet, $string )
- );
+ $sortkey = $this->getSortKey( $string );
+
+ // In case a title begins with a character from our alphabet, return the corresponding
+ // first-letter. (This also happens if the title has a corresponding PUA code in it, to avoid
+ // inconsistent behaviour. This class mostly assumes that people will not use PUA codes.)
+ $index = array_search( substr( $sortkey, 0, 4 ), $this->puaSubset );
+ if ( $index !== false ) {
+ return $this->firstLetters[ $index ];
+ }
+
+ // String begins with a character outside of our alphabet, fall back
+ return parent::getFirstLetter( $string );