Re: Comments on Math_BaseX - was Re: [PEAR-DEV] Question about package.xml
| From: | Dave Mertens | Date: | Wed, 11 Dec 2002 18:14:01 +0000 |
| Subject: | Re: Comments on Math_BaseX - was Re: [PEAR-DEV] Question about package.xml | ||
| References: | 1 2 | Groups: | php.pear.dev |
| Request: | Send a blank email to pear-dev+get-11562@lists.php.net to get a copy of this message | ||
On Tue, Dec 10, 2002 at 01:43:22PM -0800, Jesus M. Castagnetto wrote:
> It might be more explicit to name if Math_BaseConvert (but that is debatable,
> Math_BaseX would also work fine), also the init() method might be better named
> as setBase() accepting a base number (e.g. 2 or 23) and use the default
> conventions for bases 2 to 36 (i.e. the charset [0-9A-Z], the range() function
> will help here), if the base number is bigger than 36 then check for an
> optional second parameter w/ the charset. Using internal lookup tables is
> always faster ;-)
This class is more flexible that only going to base36.. The character set for the base is variable.
I use this class to encode an ordernumber for use in an email. The user must reply by visiting the
link in the email.
We're using base13 (Only 13 characters from the alfabet).
This class is indeed basicly doing the same as base_convert only with a variable character set,
[0-9][A-Z][a-z][+/] will be look similar to base64 encoding, (which isn't equal to
base64_encode, because that function is using a totally different algorithm (convert 3 8-byte
numbers into 4 6-byte numbers))
Renaming the init method to setBase is fine with me.
> Also, you might want to check for the actual value of the integer passed, and
> decide to use the base_convert() function from PHP accordingly, that way most
> of the simple cases will be handled at the C level rather than in PHP code.
That's not possible if my character set is 'ACEGIKMOQSUWY'. This would be base13.
base_convert would using [0-9][A-C].
> Finally, the encode()/decode() methods might be named toBase()/toDecimal(), and
> should check that in the first method it is getting a base 10 number and in the
> second it is getting a number that has valid chars according to the set base,
> if something is not correct, then they can just return a PEAR::raiseError()
I agree that i have to add some checking to the class. toBase and toDecimal is also fine with me..
> Let me know if I can give a hand (not that I think you need it by looking at
> your code ;-)
Just watch tonight (CEST time) your CVS mails ;-)
--
With best regards,
Dave Mertens - Senior Development Manager
dmertens@ism.nl
Innovative Solutions in Media
Schiekade 101
3033 BG Rotterdam, Netherlands
T +31-10-2436060
F +31-10-2436066
http://www.ism.nl
Quality Solutions - Reliable Partner