RE: Octstr support for converting to and from HTML 4 entities.

"Oded Arbel" <[email protected]>
Newsgroups gmane.comp.mobile.kannel.devel
Message-ID <[email protected]>
 
 


-----Original Message-----
From: Andreas Fink [mailto:[email protected]]
Sent: Monday, September 23, 2002 4:13 PM
To: Oded Arbel
Cc: [email protected]
Subject: Re: Octstr support for converting to and from HTML 4 entities.





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. 

strcmp should be locale sensitive as per the POSIX standard, IIRC. it has nothing to do with case sensitivity.

  I wouldnt count on it to compare on upper/lowercase and even diacritical characters. 

Well - you should. on the contrary - while strcmp is (or at least should be) locale aware, octstr_compare() uses memcmp() internally, which does simple byte comparison. OTOH, octstr_str_compare() which IMO should behave no different then octstr_compare() uses strcmp() internally. 


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.  

if you want to be case insensitive, you can use stricmp() or octstr_case_compare(). since Rene uses octstr_str_compare() which internally uses the locale sensitive strcmp(), maybe we should change it to use octstr_compare() somehow so that comparison would be byte ordered (locale insensitive) and sort the entity list to match ?

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. 

That's why its always a good idea to use it. sometimes though, if you are careful, the std lib calls provide extra performance which is also important.
 
--
Oded Arbel
m-Wise mobile solutions
[email protected]
 
+972-9-9581711 (116)
+972-67-340014
 
::..
If you don't care where you are, then you ain't lost.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.