|
|
|
#1 |
|
Messages: n/a
Hébergeur: |
Hello, people!
I'm very new to smarty, and while studying variables and modifiers I stumbled upon the following situation with capitalize modifier: template {"The world didn't end yesterday"|capitalize} produces output The World Didn'T End Yesterday Letter T after the apostrophe isn't exactly the new word? So, is this a bug or is this on purpose? Thanks, Dmitriy |
|
|
|
#2 |
|
Messages: n/a
Hébergeur: |
On Thu, Nov 24, 2005 at 02:23:15PM +0200, Dep wrote:
> Hello, people! > I'm very new to smarty, and while studying variables and modifiers I > stumbled upon the following situation with capitalize modifier: > template > {"The world didn't end yesterday"|capitalize} > > produces output > The World Didn'T End Yesterday > > Letter T after the apostrophe isn't exactly the new word? So, is this > a bug or is this on purpose? php's pcre-functions see the "'" as a word delimiter. so count this behaviour as "on purpose". > Thanks, > Dmitriy > > -- > Smarty General Mailing List (http://smarty.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php |
|
|
|
#3 |
|
Messages: n/a
Hébergeur: |
On Nov 24, 2005, at 6:55 AM, messju mohr wrote:
> count this behaviour as "on purpose" Just because something is "on purpose" doesn't mean it's not a bug. According to the documentation, "[capitalize] is used to capitalize the first letter of all words in a variable." In the word "didn't", the "T" is not the first letter. Therefore, it is a bug. It's either in the code or in the documentation. I don't care which you fix, but it most certainly *is* a difference in behavior from the expectation. A dependency on pcre doesn't make it any less of a bug. -daniel -- http://www.hedrick.org/daniel?sig |
|
|
|
#4 |
|
Messages: n/a
Hébergeur: |
If you put it that way, it should say:
DidN't But the parser does not speak english... Besides that - I think "didn't" is not correctly written english (I remember something like that from my english lessons). Aldough you pronounce it like didn't or whouldn't or couldn't, you write it like 'did not', 'whould not' or 'could not'. In other words: the smarty capitalize modifier works correctly, but your written english is buggy .Daniel Hedrick wrote: > On Nov 24, 2005, at 6:55 AM, messju mohr wrote: > >> count this behaviour as "on purpose" > > > Just because something is "on purpose" doesn't mean it's not a bug. > > According to the documentation, "[capitalize] is used to capitalize > the first letter of all words in a variable." > > In the word "didn't", the "T" is not the first letter. > > Therefore, it is a bug. > > It's either in the code or in the documentation. I don't care which > you fix, but it most certainly *is* a difference in behavior from the > expectation. A dependency on pcre doesn't make it any less of a bug. > > -daniel > -- > http://www.hedrick.org/daniel?sig > > > |
|
|
|
#5 |
|
Messages: n/a
Hébergeur: |
Hello Harrie,
Thursday, November 24, 2005, 5:20:20 PM, you wrote: HV> If you put it that way, it should say: HV> DidN't HV> But the parser does not speak english... HV> Besides that - I think "didn't" is not correctly written english (I HV> remember something like that from my english lessons). Aldough you HV> pronounce it like didn't or whouldn't or couldn't, you write it like HV> 'did not', 'whould not' or 'could not'. In other words: the smarty HV> capitalize modifier works correctly, but your written english is buggy .Words "Didn't, wouldn't, couldn't" etc are absolutely 100% correct written English. Best regards, Dmitriy |
|
|
|
#6 |
|
Messages: n/a
Hébergeur: |
On Thu, Nov 24, 2005 at 05:41:50PM +0200, Dep wrote:
> Hello Harrie, > > Thursday, November 24, 2005, 5:20:20 PM, you wrote: > > HV> If you put it that way, it should say: > > HV> DidN't > > HV> But the parser does not speak english... > > HV> Besides that - I think "didn't" is not correctly written english (I > HV> remember something like that from my english lessons). Aldough you > HV> pronounce it like didn't or whouldn't or couldn't, you write it like > HV> 'did not', 'whould not' or 'could not'. In other words: the smarty > HV> capitalize modifier works correctly, but your written english is buggy .> > Words "Didn't, wouldn't, couldn't" etc are absolutely 100% correct > written English. Smarty doesn't know that your string is "absolutely 100% correct written English". and probably will never know. > Best regards, Dmitriy > > -- > Smarty General Mailing List (http://smarty.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php |
|
|
|
#7 |
|
Messages: n/a
Hébergeur: |
mm> Smarty doesn't know that your string is "absolutely 100% correct
mm> written English". and probably will never know. Sure, I understand that. But in such case it would be not a bad thing to at least include a note in SMARTY documentation, regarding that one particular case - since we cannot and shouldn't mess with PCRE word delimiters That would prevent questions such as mine fromappearing. |
|
|
|
#8 |
|
Messages: n/a
Hébergeur: |
Dep wrote:
> mm> Smarty doesn't know that your string is "absolutely 100% correct > mm> written English". and probably will never know. > > Sure, I understand that. But in such case it would be not a bad thing > to at least include a note in SMARTY documentation, regarding that one > particular case +1. Contractions ending in n't and 's are extremely common in English, and they're definitely not word boundaries. So at least the English documentation should note this. Daniel Hedrick wrote: > I don't care which you fix, but it most certainly *is* a difference > in behavior from the expectation. I agree that it's a bug, but Smarty is Open Source, remember, so perhaps *you* can fix it yourself and then fill us in on what you did. My quick solution is to modify [smarty]/libs/plugins/modifier.capitalize.php. The _ char is not seen as a word boundary by PCRE, so here's a modified version of smarty_modifier_capitalize() that uses a quick str_replace to circumvent the n't and 's problem for those of us using Smarty with English text. Using a preg_replace to avoid the word-initial 's would be more elegant, but str_replace is much faster than preg_replace, so this works pretty well, or at least better than default behavior. modifier.capitalize.php: function smarty_modifier_capitalize($string, $uc_digits = false) { //replace common contraction endings with placeholders //that PCRE will not see as a word boundary $apos = array('n\'t ','\'s ','\'re '); $tmps = array('n__apos__t ','__apos__s ','__apos__re '); $string = str_replace($apos,$tmps,$string); //do the real work smarty_modifier_capitalize_ucfirst(null, $uc_digits); $string = preg_replace_callback('!\b\w+\b!', 'smarty_modifier_capitalize_ucfirst', $string); //restore the contractions and return return str_replace($tmps,$apos,$string); } example.tpl: {assign value="max's horse didn't fall. 'someone' is coming. they're here!" var="capt"} {$capt|capitalize} Output: Max's Horse Didn't Fall. 'Someone' Is Coming. They're Here! -- Max Schwanekamp http://www.neptunewebworks.com/ |
|
![]() |
| Outils de la discussion | |
|
|