PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > php.smarty.general > capitalize modifier
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
capitalize modifier

Réponse
 
LinkBack Outils de la discussion
Vieux 24/11/2005, 13h23   #1
Dep
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut capitalize modifier

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
  Réponse avec citation
Vieux 24/11/2005, 13h55   #2
messju mohr
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: [SMARTY] capitalize modifier

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

  Réponse avec citation
Vieux 24/11/2005, 16h04   #3
Daniel Hedrick
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: [SMARTY] capitalize modifier

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



  Réponse avec citation
Vieux 24/11/2005, 16h20   #4
Harrie Verveer
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: [SMARTY] capitalize modifier

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
>
>
>

  Réponse avec citation
Vieux 24/11/2005, 16h41   #5
Dep
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re[2]: [SMARTY] capitalize modifier

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
  Réponse avec citation
Vieux 24/11/2005, 18h01   #6
messju mohr
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: [SMARTY] capitalize modifier

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

  Réponse avec citation
Vieux 24/11/2005, 18h42   #7
Dep
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re[2]: [SMARTY] capitalize modifier

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 from
appearing.
  Réponse avec citation
Vieux 24/11/2005, 20h06   #8
Max Schwanekamp
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: [SMARTY] capitalize modifier

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/
  Réponse avec citation
Vieux 26/11/2005, 21h21   #9
Daniel Hedrick
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: [SMARTY] capitalize modifier

On Nov 24, 2005, at 1:06 PM, Max Schwanekamp wrote:
> perhaps *you* can fix it yourself and then fill us in on what you did.


I made another mental note as to why I don't use most of the
convenience functions of the Smarty templating system.

Don't get me wrong... I like Smarty a lot. I think it does a great
job of allowing me to separate logic from presentation. But much like
trying to drive nails with a screwdriver, I generally don't use a
template engine to capitalize my strings for me. ;-)

-daniel
--
http://www.hedrick.org/daniel?sig



  Réponse avec citation
Vieux 27/11/2005, 03h37   #10
A.J. Brown
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut RE: [SMARTY] capitalize modifier

Capitalization isn't necessarily a function of logic. It can be, but most
of the time it isn't. For example, if you want to display all names in
caps...the logic has no business formatting them as so, and shouldn't care
either. If you wanted to later drop the requirement of displaying all names
in caps, you should change the client template, not the logic. Another
example with the same case: if you use the same logic for two different
client systems, one might require all capitals for the display, and the
other might not.

On the other hand, if your LOGIC requires all capitals (ex: SKU's) then
forcing capitals is a function of model/logic, and not display.


Whenever possible, you have to think "is this required for my logic, or
preferred for my display?".


A.J. Brown


-----Original Message-----
From: Daniel Hedrick [mailto:daniel@hedrick.org]
Sent: Saturday, November 26, 2005 3:22 PM
To: Smarty-General
Subject: Re: [SMARTY] capitalize modifier

On Nov 24, 2005, at 1:06 PM, Max Schwanekamp wrote:
> perhaps *you* can fix it yourself and then fill us in on what you did.


I made another mental note as to why I don't use most of the
convenience functions of the Smarty templating system.

Don't get me wrong... I like Smarty a lot. I think it does a great
job of allowing me to separate logic from presentation. But much like
trying to drive nails with a screwdriver, I generally don't use a
template engine to capitalize my strings for me. ;-)

-daniel
--
http://www.hedrick.org/daniel?sig



  Réponse avec citation
Vieux 27/11/2005, 03h37   #11
A.J. Brown
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut {Blocked Content} RE: [SMARTY] capitalize modifier

Warning: This message has had one or more attachments removed
Warning: (not named).
Warning: Please read the "ChisanoMarketingComm-Attachment-Warning.txt" attachment(s) for more information.

Capitalization isn't necessarily a function of logic. It can be, but most
of the time it isn't. For example, if you want to display all names in
caps...the logic has no business formatting them as so, and shouldn't care
either. If you wanted to later drop the requirement of displaying all names
in caps, you should change the client template, not the logic. Another
example with the same case: if you use the same logic for two different
client systems, one might require all capitals for the display, and the
other might not.

On the other hand, if your LOGIC requires all capitals (ex: SKU's) then
forcing capitals is a function of model/logic, and not display.


Whenever possible, you have to think "is this required for my logic, or
preferred for my display?".


A.J. Brown


-----Original Message-----
From: Daniel Hedrick [mailto:daniel@hedrick.org]
Sent: Saturday, November 26, 2005 3:22 PM
To: Smarty-General
Subject: Re: [SMARTY] capitalize modifier

On Nov 24, 2005, at 1:06 PM, Max Schwanekamp wrote:
> perhaps *you* can fix it yourself and then fill us in on what you did.


I made another mental note as to why I don't use most of the
convenience functions of the Smarty templating system.

Don't get me wrong... I like Smarty a lot. I think it does a great
job of allowing me to separate logic from presentation. But much like
trying to drive nails with a screwdriver, I generally don't use a
template engine to capitalize my strings for me. ;-)

-daniel
--
http://www.hedrick.org/daniel?sig



  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 16h59.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,18671 seconds with 19 queries