Re: Octstr support for converting to and from HTML 4 entities.
Andreas Fink <[email protected]>
| Newsgroups | gmane.comp.mobile.kannel.devel |
|---|---|
| Message-ID | <[email protected]> |
>> > > Oh. that was me - sorry. its no hard rule, but basicly what I meant is > - don't use c strings for doing complicated stuff that the Octstr sub > system handles better and more safely. do use c-string library calls > for simple stuff that the library call would do better, especially if > the call doesnot modify the content of the string (hence - no risk for > buffer overflows). for example, when you want to compare octstrings > you can use strcmp(octstr_get_cstr(.... or you can use > octstr_compare(). this is the border line case IMO, where in this case > I would have used the octstr_compare() as it involves fewer calls. you > have already demonstrated that you can choose correctly between > complexity and safety, and you can make the same decisions here. most > importantly - don't take anything said by Kannel developers , > especially me, as hard truth - those are simply recomendations. if we > hate your code so much (not that I do) - we can change when it is in > the CVS :-) > strcmp(octstr_get_cstr(... and octstr_compare() behave DIFFERENTLY. if I remember correctly octstr_compare is case sensitive where strcmp is more or less simply comparing the bytes. I wouldnt count on it to compare on upper/lowercase and even diacritical characters. Think of this: ä is a german umlaut. to sort ä in german books, its sorted like "a". but it can also be written as "ae". now is ä = a or ä > a or ä < a? how about Ae (swiss way of writing capital ä)? how about ß which is replaced as "ss"? as you can see comparing strings is not always obvious. but it should be at least consistent. So if you can write a parameter in a config file in upper or lower case and it doesn't really matter, suddendly using strcmp would make the behaviour really strange. octstr.c is an abstraction layer. Thats what it is there for. So use it for that purpose. and frankly, the memory checking stuff is really useful in it. I'm fixing a few dozen memory leaks by using it. It points with the finger to it all the time. Very easy to fix this way. stdc sting.h stuff doesn't give you any of that. Andreas Fink Global Networks, Inc. ------------------------------------------------------------------ Tel: +41-61-6932730 Fax: +41-61-6932729 Mobile: +41-79-2457333 Global Networks, Inc. Schwarzwaldallee 16, 4058 Basel, Switzerland Web: http://www.global-networks.ch/ [email protected] ------------------------------------------------------------------ Member of the GSM Association