Patch bug48711.patch for Strings related Bug #48711
Patch version 2011-02-26 17:48 UTC
Return to Bug #48711 |
Download this patch
Patch Revisions:
Developer: jthijssen@noxlogic.nl
Index: ext/standard/tests/strings/metaphone.phpt
===================================================================
--- ext/standard/tests/strings/metaphone.phpt (revision 308566)
+++ ext/standard/tests/strings/metaphone.phpt (working copy)
@@ -35,7 +35,7 @@
string(6) "FLTFRS"
string(6) "FLTFRS"
string(26) "0FLFRWRTKRFLNKHTLSLN0KLTR0"
-string(56) "BT0XTFHRRHLTNTRTRNTPSNKLWRNRFTBF0MSWPNK0FNRKW0TSFSTLWNKS"
+string(55) "BT0XTFHRRHLTNTRTRNTPSNKLWRNRTBF0MSWPNK0FNRKW0TSFSTLWNKS"
string(69) "ANT0NTWSKNFLYNKBKTMRTRW00SPTF0R0FSRNNTBHNTT0WNTRRTWLFNK0TTMRXSBRNTBLK"
-string(56) "0NKTWSTSFRS0YKLTPRSFNT0TSTNTMNSF0MNTNSWSTPLTW00FTFLMNLFT"
+string(55) "0NKTWSTSFRS0YKLTPRSFNT0TSTNTMNSF0MNTNSWSTPLTW00FTFLMNLT"
Done
Index: ext/standard/tests/strings/bug48711.phpt
===================================================================
--- ext/standard/tests/strings/bug48711.phpt (revision 0)
+++ ext/standard/tests/strings/bug48711.phpt (revision 0)
@@ -0,0 +1,25 @@
+--TEST--
+Check if function returns correct values
+--CREDITS--
+G.A. de Graaf
+# Enrise Testfest 21-02-2011
+--FILE--
+<?php
+ var_dump(metaphone('School', 0, false));
+ var_dump(metaphone('School'));
+ var_dump(metaphone('character'));
+ var_dump(metaphone('character', 0, false));
+ var_dump(metaphone('chroma'));
+ var_dump(metaphone('chroma', 0, false));
+ var_dump(metaphone('Ghent'));
+ var_dump(metaphone('Knight'));
+?>
+--EXPECT--
+string(3) "SKL"
+string(3) "SXL"
+string(5) "KRKTR"
+string(5) "KRKTR"
+string(3) "XRM"
+string(3) "KRM"
+string(3) "KNT"
+string(2) "NT"
Index: ext/standard/metaphone.c
===================================================================
--- ext/standard/metaphone.c (revision 308566)
+++ ext/standard/metaphone.c (working copy)
@@ -27,7 +27,7 @@
static int metaphone(unsigned char *word, int word_len, long max_phonemes, char **phoned_word, int traditional);
-/* {{{ proto string metaphone(string text[, int phones])
+/* {{{ proto string metaphone(string text[, int phones, [bool traditional]])
Break english phrases down into their phonemes */
PHP_FUNCTION(metaphone)
{
@@ -35,13 +35,14 @@
char *result = 0;
int str_len;
long phones = 0;
+ int traditional = 1;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|l", &str, &str_len,
- &phones) == FAILURE) {
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|lb", &str, &str_len,
+ &phones, &traditional) == FAILURE) {
return;
}
- if (metaphone((unsigned char *)str, str_len, phones, &result, 1) == 0) {
+ if (metaphone((unsigned char *)str, str_len, phones, &result, traditional) == 0) {
RETVAL_STRING(result, 0);
} else {
if (result) {
@@ -216,8 +217,19 @@
w_idx++;
}
break;
+ case 'C':
+ if (Next_Letter == 'H' && isvowel(After_Next_Letter)) { /* character */
+ Phonize('K');
+ w_idx += 2;
+ }
+ break;
/* [GKP]N becomes N */
case 'G':
+ if (Next_Letter == 'H') { /* 'ghent' */
+ Phonize('K');
+ w_idx += 2;
+ break;
+ }
case 'K':
case 'P':
if (Next_Letter == 'N') {
@@ -232,7 +244,7 @@
if (Next_Letter == 'R') {
Phonize(Next_Letter);
w_idx += 2;
- } else if (Next_Letter == 'H' || isvowel(Next_Letter)) {
+ } else if (Next_Letter == 'H' || isalpha(Next_Letter)) {
Phonize('W');
w_idx += 2;
}
@@ -342,6 +354,7 @@
case 'G':
if (Next_Letter == 'H') {
if (!(NOGHTOF(Look_Back_Letter(3)) ||
+ !(isvowel(After_Next_Letter)) ||
Look_Back_Letter(4) == 'H')) {
Phonize('F');
skip_letter++;
|