2 # Copyright (C) 2004 Brion Vibber <brion@pobox.com>
3 # http://www.mediawiki.org/
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 2 of the License, or
8 # (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License along
16 # with this program; if not, write to the Free Software Foundation, Inc.,
17 # 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 # http://www.gnu.org/copyleft/gpl.html
21 * Unicode normalization routines for working with UTF-8 strings.
22 * Currently assumes that input strings are valid UTF-8!
24 * Not as fast as I'd like, but should be usable for most purposes.
25 * UtfNormal::toNFC() will bail early if given ASCII text or text
26 * it can quickly deterimine is already normalized.
28 * All functions can be called static.
30 * See description of forms at http://www.unicode.org/reports/tr15/
36 require_once 'UtfNormalUtil.php';
38 global $utfCombiningClass, $utfCanonicalComp, $utfCanonicalDecomp;
39 $utfCombiningClass = NULL;
40 $utfCanonicalComp = NULL;
41 $utfCanonicalDecomp = NULL;
43 # Load compatibility decompositions on demand if they are needed.
44 global $utfCompatibilityDecomp;
45 $utfCompatibilityDecomp = NULL;
47 define( 'UNICODE_HANGUL_FIRST', 0xac00 );
48 define( 'UNICODE_HANGUL_LAST', 0xd7a3 );
50 define( 'UNICODE_HANGUL_LBASE', 0x1100 );
51 define( 'UNICODE_HANGUL_VBASE', 0x1161 );
52 define( 'UNICODE_HANGUL_TBASE', 0x11a7 );
54 define( 'UNICODE_HANGUL_LCOUNT', 19 );
55 define( 'UNICODE_HANGUL_VCOUNT', 21 );
56 define( 'UNICODE_HANGUL_TCOUNT', 28 );
57 define( 'UNICODE_HANGUL_NCOUNT', UNICODE_HANGUL_VCOUNT
* UNICODE_HANGUL_TCOUNT
);
59 define( 'UNICODE_HANGUL_LEND', UNICODE_HANGUL_LBASE + UNICODE_HANGUL_LCOUNT
- 1 );
60 define( 'UNICODE_HANGUL_VEND', UNICODE_HANGUL_VBASE + UNICODE_HANGUL_VCOUNT
- 1 );
61 define( 'UNICODE_HANGUL_TEND', UNICODE_HANGUL_TBASE + UNICODE_HANGUL_TCOUNT
- 1 );
63 define( 'UNICODE_SURROGATE_FIRST', 0xd800 );
64 define( 'UNICODE_SURROGATE_LAST', 0xdfff );
65 define( 'UNICODE_MAX', 0x10ffff );
66 define( 'UNICODE_REPLACEMENT', 0xfffd );
69 define( 'UTF8_HANGUL_FIRST', codepointToUtf8( UNICODE_HANGUL_FIRST
) );
70 define( 'UTF8_HANGUL_LAST', codepointToUtf8( UNICODE_HANGUL_LAST
) );
72 define( 'UTF8_HANGUL_LBASE', codepointToUtf8( UNICODE_HANGUL_LBASE
) );
73 define( 'UTF8_HANGUL_VBASE', codepointToUtf8( UNICODE_HANGUL_VBASE
) );
74 define( 'UTF8_HANGUL_TBASE', codepointToUtf8( UNICODE_HANGUL_TBASE
) );
76 define( 'UTF8_HANGUL_LEND', codepointToUtf8( UNICODE_HANGUL_LEND
) );
77 define( 'UTF8_HANGUL_VEND', codepointToUtf8( UNICODE_HANGUL_VEND
) );
78 define( 'UTF8_HANGUL_TEND', codepointToUtf8( UNICODE_HANGUL_TEND
) );
80 define( 'UTF8_SURROGATE_FIRST', codepointToUtf8( UNICODE_SURROGATE_FIRST
) );
81 define( 'UTF8_SURROGATE_LAST', codepointToUtf8( UNICODE_SURROGATE_LAST
) );
82 define( 'UTF8_MAX', codepointToUtf8( UNICODE_MAX
) );
83 define( 'UTF8_REPLACEMENT', codepointToUtf8( UNICODE_REPLACEMENT
) );
84 #define( 'UTF8_REPLACEMENT', '!' );
86 define( 'UTF8_OVERLONG_A', "\xc1\xbf" );
87 define( 'UTF8_OVERLONG_B', "\xe0\x9f\xbf" );
88 define( 'UTF8_OVERLONG_C', "\xf0\x8f\xbf\xbf" );
90 # These two ranges are illegal
91 define( 'UTF8_FDD0', codepointToUtf8( 0xfdd0 ) );
92 define( 'UTF8_FDEF', codepointToUtf8( 0xfdef ) );
93 define( 'UTF8_FFFE', codepointToUtf8( 0xfffe ) );
94 define( 'UTF8_FFFF', codepointToUtf8( 0xffff ) );
96 define( 'UTF8_HEAD', false );
97 define( 'UTF8_TAIL', true );
101 * For using the ICU wrapper
103 define( 'UNORM_NONE', 1 );
104 define( 'UNORM_NFD', 2 );
105 define( 'UNORM_NFKD', 3 );
106 define( 'UNORM_NFC', 4 );
107 define( 'UNORM_DEFAULT', UNORM_NFC
);
108 define( 'UNORM_NFKC', 5 );
109 define( 'UNORM_FCD', 6 );
111 define( 'NORMALIZE_ICU', function_exists( 'utf8_normalize' ) );
119 * The ultimate convenience function! Clean up invalid UTF-8 sequences,
120 * and convert to normal form C, canonical composition.
122 * Fast return for pure ASCII strings; some lesser optimizations for
123 * strings containing only known-good characters. Not as fast as toNFC().
125 * @param string $string a UTF-8 string
126 * @return string a clean, shiny, normalized UTF-8 string
128 function cleanUp( $string ) {
129 if( NORMALIZE_ICU
) {
130 # We exclude a few chars that ICU would not.
131 $string = preg_replace(
132 '/[\x00-\x08\x0b\x0c\x0e-\x1f]/',
135 $string = str_replace( UTF8_FFFE
, UTF8_REPLACEMENT
, $string );
136 $string = str_replace( UTF8_FFFF
, UTF8_REPLACEMENT
, $string );
138 # UnicodeString constructor fails if the string ends with a
139 # head byte. Add a junk char at the end, we'll strip it off.
140 return rtrim( utf8_normalize( $string . "\x01", UNORM_NFC
), "\x01" );
141 } elseif( UtfNormal
::quickIsNFCVerify( $string ) ) {
142 # Side effect -- $string has had UTF-8 errors cleaned up.
145 return UtfNormal
::NFC( $string );
150 * Convert a UTF-8 string to normal form C, canonical composition.
151 * Fast return for pure ASCII strings; some lesser optimizations for
152 * strings containing only known-good characters.
154 * @param string $string a valid UTF-8 string. Input is not validated.
155 * @return string a UTF-8 string in normal form C
157 function toNFC( $string ) {
159 return utf8_normalize( $string, UNORM_NFC
);
160 elseif( UtfNormal
::quickIsNFC( $string ) )
163 return UtfNormal
::NFC( $string );
167 * Convert a UTF-8 string to normal form D, canonical decomposition.
168 * Fast return for pure ASCII strings.
170 * @param string $string a valid UTF-8 string. Input is not validated.
171 * @return string a UTF-8 string in normal form D
173 function toNFD( $string ) {
175 return utf8_normalize( $string, UNORM_NFD
);
176 elseif( preg_match( '/[\x80-\xff]/', $string ) )
177 return UtfNormal
::NFD( $string );
183 * Convert a UTF-8 string to normal form KC, compatibility composition.
184 * This may cause irreversible information loss, use judiciously.
185 * Fast return for pure ASCII strings.
187 * @param string $string a valid UTF-8 string. Input is not validated.
188 * @return string a UTF-8 string in normal form KC
190 function toNFKC( $string ) {
192 return utf8_normalize( $string, UNORM_NFKC
);
193 elseif( preg_match( '/[\x80-\xff]/', $string ) )
194 return UtfNormal
::NFKC( $string );
200 * Convert a UTF-8 string to normal form KD, compatibility decomposition.
201 * This may cause irreversible information loss, use judiciously.
202 * Fast return for pure ASCII strings.
204 * @param string $string a valid UTF-8 string. Input is not validated.
205 * @return string a UTF-8 string in normal form KD
207 function toNFKD( $string ) {
209 return utf8_normalize( $string, UNORM_NFKD
);
210 elseif( preg_match( '/[\x80-\xff]/', $string ) )
211 return UtfNormal
::NFKD( $string );
217 * Load the basic composition data if necessary
220 function loadData() {
221 global $utfCombiningClass, $utfCanonicalComp, $utfCanonicalDecomp;
222 if( !isset( $utfCombiningClass ) ) {
223 require_once( 'UtfNormalData.inc' );
228 * Returns true if the string is _definitely_ in NFC.
229 * Returns false if not or uncertain.
230 * @param string $string a valid UTF-8 string. Input is not validated.
233 function quickIsNFC( $string ) {
234 # ASCII is always valid NFC!
235 # If it's pure ASCII, let it through.
236 if( !preg_match( '/[\x80-\xff]/', $string ) ) return true;
238 UtfNormal
::loadData();
239 global $utfCheckNFC, $utfCombiningClass;
240 $len = strlen( $string );
241 for( $i = 0; $i < $len; $i++
) {
246 } elseif( $n >= 0xf0 ) {
247 $c = substr( $string, $i, 4 );
249 } elseif( $n >= 0xe0 ) {
250 $c = substr( $string, $i, 3 );
252 } elseif( $n >= 0xc0 ) {
253 $c = substr( $string, $i, 2 );
256 if( isset( $utfCheckNFC[$c] ) ) {
257 # If it's NO or MAYBE, bail and do the slow check.
260 if( isset( $utfCombiningClass[$c] ) ) {
261 # Combining character? We might have to do sorting, at least.
269 * Returns true if the string is _definitely_ in NFC.
270 * Returns false if not or uncertain.
271 * @param string $string a UTF-8 string, altered on output to be valid UTF-8 safe for XML.
273 function quickIsNFCVerify( &$string ) {
274 # Screen out some characters that eg won't be allowed in XML
275 $string = preg_replace( '/[\x00-\x08\x0b\x0c\x0e-\x1f]/', UTF8_REPLACEMENT
, $string );
277 # ASCII is always valid NFC!
278 # If we're only ever given plain ASCII, we can avoid the overhead
279 # of initializing the decomposition tables by skipping out early.
280 if( !preg_match( '/[\x80-\xff]/', $string ) ) return true;
282 static $checkit = null, $tailBytes = null, $utfCheckOrCombining = null;
283 if( !isset( $checkit ) ) {
284 # Load/build some scary lookup tables...
285 UtfNormal
::loadData();
286 global $utfCheckNFC, $utfCombiningClass;
288 $utfCheckOrCombining = array_merge( $utfCheckNFC, $utfCombiningClass );
290 # Head bytes for sequences which we should do further validity checks
291 $checkit = array_flip( array_map( 'chr',
292 array( 0xc0, 0xc1, 0xe0, 0xed, 0xef,
293 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
294 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff ) ) );
296 # Each UTF-8 head byte is followed by a certain
297 # number of tail bytes.
298 $tailBytes = array();
299 for( $n = 0; $n < 256; $n++
) {
302 } elseif( $n < 0xe0 ) {
304 } elseif( $n < 0xf0 ) {
306 } elseif( $n < 0xf8 ) {
308 } elseif( $n < 0xfc ) {
310 } elseif( $n < 0xfe ) {
315 $tailBytes[chr($n)] = $remaining;
319 # Chop the text into pure-ASCII and non-ASCII areas;
320 # large ASCII parts can be handled much more quickly.
321 # Don't chop up Unicode areas for punctuation, though,
322 # that wastes energy.
324 '/([\x00-\x7f]+|[\x80-\xff][\x00-\x40\x5b-\x5f\x7b-\xff]*)/',
330 foreach( $matches[1] as $str ) {
331 $chunk = strlen( $str );
333 if( $str{0} < "\x80" ) {
334 # ASCII chunk: guaranteed to be valid UTF-8
335 # and in normal form C, so skip over it.
340 # We'll have to examine the chunk byte by byte to ensure
341 # that it consists of valid UTF-8 sequences, and to see
342 # if any of them might not be normalized.
344 # Since PHP is not the fastest language on earth, some of
345 # this code is a little ugly with inner loop optimizations.
348 $len = $chunk +
1; # Counting down is faster. I'm *so* sorry.
350 for( $i = -1; --$len; ) {
351 if( $remaining = $tailBytes[$c = $str{++
$i}] ) {
353 $sequence = $head = $c;
355 # Look for the defined number of tail bytes...
356 if( --$len && ( $c = $str{++
$i} ) >= "\x80" && $c < "\xc0" ) {
357 # Legal tail bytes are nice.
361 # Premature end of string!
362 # Drop a replacement character into output to
363 # represent the invalid UTF-8 sequence.
364 $replace[] = array( UTF8_REPLACEMENT
,
365 $base +
$i +
1 - strlen( $sequence ),
366 strlen( $sequence ) );
369 # Illegal tail byte; abandon the sequence.
370 $replace[] = array( UTF8_REPLACEMENT
,
371 $base +
$i - strlen( $sequence ),
372 strlen( $sequence ) );
373 # Back up and reprocess this byte; it may itself
374 # be a legal ASCII or UTF-8 sequence head.
380 } while( --$remaining );
382 if( isset( $checkit[$head] ) ) {
383 # Do some more detailed validity checks, for
384 # invalid characters and illegal sequences.
385 if( $head == "\xed" ) {
386 # 0xed is relatively frequent in Korean, which
387 # abuts the surrogate area, so we're doing
388 # this check separately to speed things up.
390 if( $sequence >= UTF8_SURROGATE_FIRST
) {
391 # Surrogates are legal only in UTF-16 code.
392 # They are totally forbidden here in UTF-8
394 $replace[] = array( UTF8_REPLACEMENT
,
395 $base +
$i +
1 - strlen( $sequence ),
396 strlen( $sequence ) );
401 # Slower, but rarer checks...
404 # "Overlong sequences" are those that are syntactically
405 # correct but use more UTF-8 bytes than are necessary to
406 # encode a character. Naïve string comparisons can be
407 # tricked into failing to see a match for an ASCII
408 # character, for instance, which can be a security hole
409 # if blacklist checks are being used.
410 ($n < 0xc2 && $sequence <= UTF8_OVERLONG_A
)
411 ||
($n == 0xe0 && $sequence <= UTF8_OVERLONG_B
)
412 ||
($n == 0xf0 && $sequence <= UTF8_OVERLONG_C
)
414 # U+FFFE and U+FFFF are explicitly forbidden in Unicode.
416 ($sequence == UTF8_FFFE
)
417 ||
($sequence == UTF8_FFFF
) )
419 # Unicode has been limited to 21 bits; longer
420 # sequences are not allowed.
421 ||
($n >= 0xf0 && $sequence > UTF8_MAX
) ) {
423 $replace[] = array( UTF8_REPLACEMENT
,
424 $base +
$i +
1 - strlen( $sequence ),
425 strlen( $sequence ) );
432 if( isset( $utfCheckOrCombining[$sequence] ) ) {
433 # If it's NO or MAYBE, we'll have to rip
434 # the string apart and put it back together.
435 # That's going to be mighty slow.
436 $looksNormal = false;
439 # The sequence is legal!
441 } elseif( $c < "\x80" ) {
444 } elseif( $c < "\xc0" ) {
448 $replace[] = array( UTF8_REPLACEMENT
, $base +
$i, 1 );
450 # Don't add if we're continuing a broken sequence;
451 # we already put a replacement character when we looked
452 # at the broken sequence.
453 $replace[] = array( '', $base +
$i, 1 );
456 # Miscellaneous freaks.
457 $replace[] = array( UTF8_REPLACEMENT
, $base +
$i, 1 );
463 if( count( $replace ) ) {
464 # There were illegal UTF-8 sequences we need to fix up.
467 foreach( $replace as $rep ) {
468 list( $replacement, $start, $length ) = $rep;
469 if( $last < $start ) {
470 $out .= substr( $string, $last, $start - $last );
472 $out .= $replacement;
473 $last = $start +
$length;
475 if( $last < strlen( $string ) ) {
476 $out .= substr( $string, $last );
483 # These take a string and run the normalization on them, without
484 # checking for validity or any optimization etc. Input must be
487 * @param string $string
491 function NFC( $string ) {
492 return UtfNormal
::fastCompose( UtfNormal
::NFD( $string ) );
496 * @param string $string
500 function NFD( $string ) {
501 UtfNormal
::loadData();
502 global $utfCanonicalDecomp;
503 return UtfNormal
::fastCombiningSort(
504 UtfNormal
::fastDecompose( $string, $utfCanonicalDecomp ) );
508 * @param string $string
512 function NFKC( $string ) {
513 return UtfNormal
::fastCompose( UtfNormal
::NFKD( $string ) );
517 * @param string $string
521 function NFKD( $string ) {
522 global $utfCompatibilityDecomp;
523 if( !isset( $utfCompatibilityDecomp ) ) {
524 require_once( 'UtfNormalDataK.inc' );
526 return UtfNormal
::fastCombiningSort(
527 UtfNormal
::fastDecompose( $string, $utfCompatibilityDecomp ) );
532 * Perform decomposition of a UTF-8 string into either D or KD form
533 * (depending on which decomposition map is passed to us).
534 * Input is assumed to be *valid* UTF-8. Invalid code will break.
536 * @param string $string Valid UTF-8 string
537 * @param array $map hash of expanded decomposition map
538 * @return string a UTF-8 string decomposed, not yet normalized (needs sorting)
540 function fastDecompose( $string, &$map ) {
541 UtfNormal
::loadData();
542 $len = strlen( $string );
544 for( $i = 0; $i < $len; $i++
) {
548 # ASCII chars never decompose
552 } elseif( $n >= 0xf0 ) {
553 $c = substr( $string, $i, 4 );
555 } elseif( $n >= 0xe0 ) {
556 $c = substr( $string, $i, 3 );
558 } elseif( $n >= 0xc0 ) {
559 $c = substr( $string, $i, 2 );
562 if( isset( $map[$c] ) ) {
566 if( $c >= UTF8_HANGUL_FIRST
&& $c <= UTF8_HANGUL_LAST
) {
567 # Decompose a hangul syllable into jamo;
568 # hardcoded for three-byte UTF-8 sequence.
569 # A lookup table would be slightly faster,
570 # but adds a lot of memory & disk needs.
572 $index = ( (ord( $c{0} ) & 0x0f) << 12
573 |
(ord( $c{1} ) & 0x3f) << 6
574 |
(ord( $c{2} ) & 0x3f) )
575 - UNICODE_HANGUL_FIRST
;
576 $l = IntVal( $index / UNICODE_HANGUL_NCOUNT
);
577 $v = IntVal( ($index % UNICODE_HANGUL_NCOUNT
) / UNICODE_HANGUL_TCOUNT
);
578 $t = $index % UNICODE_HANGUL_TCOUNT
;
579 $out .= "\xe1\x84" . chr( 0x80 +
$l ) . "\xe1\x85" . chr( 0xa1 +
$v );
581 $out .= "\xe1\x87" . chr( 0x80 +
$t - 25 );
583 $out .= "\xe1\x86" . chr( 0xa7 +
$t );
594 * Sorts combining characters into canonical order. This is the
595 * final step in creating decomposed normal forms D and KD.
597 * @param string $string a valid, decomposed UTF-8 string. Input is not validated.
598 * @return string a UTF-8 string with combining characters sorted in canonical order
600 function fastCombiningSort( $string ) {
601 UtfNormal
::loadData();
602 global $utfCombiningClass;
603 $len = strlen( $string );
605 $combiners = array();
607 for( $i = 0; $i < $len; $i++
) {
612 $c = substr( $string, $i, 4 );
614 } elseif( $n >= 0xe0 ) {
615 $c = substr( $string, $i, 3 );
617 } elseif( $n >= 0xc0 ) {
618 $c = substr( $string, $i, 2 );
621 if( isset( $utfCombiningClass[$c] ) ) {
622 $lastClass = $utfCombiningClass[$c];
623 @$combiners[$lastClass] .= $c;
629 $out .= implode( '', $combiners );
630 $combiners = array();
637 $out .= implode( '', $combiners );
643 * Produces canonically composed sequences, i.e. normal form C or KC.
646 * @param string $string a valid UTF-8 string in sorted normal form D or KD. Input is not validated.
647 * @return string a UTF-8 string with canonical precomposed characters used where possible
649 function fastCompose( $string ) {
650 UtfNormal
::loadData();
651 global $utfCanonicalComp, $utfCombiningClass;
652 $len = strlen( $string );
658 $x1 = ord(substr(UTF8_HANGUL_VBASE
,0,1));
659 $x2 = ord(substr(UTF8_HANGUL_TEND
,0,1));
660 for( $i = 0; $i < $len; $i++
) {
664 # No combining characters here...
671 } elseif( $n >= 0xf0 ) {
672 $c = substr( $string, $i, 4 );
674 } elseif( $n >= 0xe0 ) {
675 $c = substr( $string, $i, 3 );
677 } elseif( $n >= 0xc0 ) {
678 $c = substr( $string, $i, 2 );
681 $pair = $startChar . $c;
683 if( isset( $utfCombiningClass[$c] ) ) {
684 # A combining char; see what we can do with it
685 $class = $utfCombiningClass[$c];
686 if( !empty( $startChar ) &&
687 $lastClass < $class &&
689 isset( $utfCanonicalComp[$pair] ) ) {
690 $startChar = $utfCanonicalComp[$pair];
701 if( $lastClass == 0 ) {
702 if( isset( $utfCanonicalComp[$pair] ) ) {
703 $startChar = $utfCanonicalComp[$pair];
707 if( $n >= $x1 && $n <= $x2 ) {
708 # WARNING: Hangul code is painfully slow.
709 # I apologize for this ugly, ugly code; however
710 # performance is even more teh suck if we call
711 # out to nice clean functions. Lookup tables are
712 # marginally faster, but require a lot of space.
714 if( $c >= UTF8_HANGUL_VBASE
&&
715 $c <= UTF8_HANGUL_VEND
&&
716 $startChar >= UTF8_HANGUL_LBASE
&&
717 $startChar <= UTF8_HANGUL_LEND
) {
719 #$lIndex = utf8ToCodepoint( $startChar ) - UNICODE_HANGUL_LBASE;
720 #$vIndex = utf8ToCodepoint( $c ) - UNICODE_HANGUL_VBASE;
721 $lIndex = ord( $startChar{2} ) - 0x80;
722 $vIndex = ord( $c{2} ) - 0xa1;
724 $hangulPoint = UNICODE_HANGUL_FIRST +
725 UNICODE_HANGUL_TCOUNT
*
726 (UNICODE_HANGUL_VCOUNT
* $lIndex +
$vIndex);
728 # Hardcode the limited-range UTF-8 conversion:
729 $startChar = chr( $hangulPoint >> 12 & 0x0f |
0xe0 ) .
730 chr( $hangulPoint >> 6 & 0x3f |
0x80 ) .
731 chr( $hangulPoint & 0x3f |
0x80 );
734 } elseif( $c >= UTF8_HANGUL_TBASE
&&
735 $c <= UTF8_HANGUL_TEND
&&
736 $startChar >= UTF8_HANGUL_FIRST
&&
737 $startChar <= UTF8_HANGUL_LAST
&&
739 # $tIndex = utf8ToCodepoint( $c ) - UNICODE_HANGUL_TBASE;
740 $tIndex = ord( $c{2} ) - 0xa7;
741 if( $tIndex < 0 ) $tIndex = ord( $c{2} ) - 0x80 +
(0x11c0 - 0x11a7);
743 # Increment the code point by $tIndex, without
744 # the function overhead of decoding and recoding UTF-8
746 $tail = ord( $startChar{2} ) +
$tIndex;
749 $mid = ord( $startChar{1} ) +
1;
751 $startChar{0} = chr( ord( $startChar{0} ) +
1 );
754 $startChar{1} = chr( $mid );
756 $startChar{2} = chr( $tail );
758 # If there's another jamo char after this, *don't* try to merge it.
771 $out .= $startChar . $combining;
776 * This is just used for the benchmark, comparing how long it takes to
777 * interate through a string without really doing anything of substance.
778 * @param string $string
781 function placebo( $string ) {
782 $len = strlen( $string );
784 for( $i = 0; $i < $len; $i++
) {