Hi,

On 2011.05.18 23:11, Ron Pinkas wrote:
>>    ? len( hb_aTokens( ""    , "|" ) )
>>    ? len( hb_aTokens( "|"   , "|" ) )
>>    ? len( hb_aTokens( "||"  , "|" ) )
>>
>> do you find above results natural?
>
> Sorry I really don't understand. I expect 0, 2, 3 or 0,1,2 depending on
> whether terminator delimiter is expected or not (IMO there should be an
> additional argument to control such behavior). What results would you
> expect, and more importantly WHY?

I would expect return 1, 2, 3. Also, I would expect natural:
   hb_aTokens( ""    , "|" ) ->  {""}
   hb_aTokens( "a"   , "|" ) ->  {"a"}
   hb_aTokens( "|a"  , "|" ) ->  {"", "a"}
   hb_aTokens( "a|"  , "|" ) ->  {"a", ""}
   hb_aTokens( "a|b" , "|" ) ->  {"a", "b"}
without an exception for empty string.

Why? Because I expect
    hb_atokens(string+delimiter+token, delimiter)
should return array like
    hb_atokens(string, delimiter)
but with additional token in the end.

If that is true, and
   hb_atoken("|a", "|")
returns
   {"", "a"}
then
   hb_atoken("", "|")
should return
   {""}

This is simple to prove by replacing string="", token="a", and 
delimiter="|".


I would also expect no additional parameter for "feature tuning", 
because it only makes function behaviour not clean. F.e., what is 
expected function return value if parameter indicates that termination 
delimiter should be included, but there is no terminating delimiter in 
the end of string? Should hb_atokens("a|b", "|", .T.) return {"a"}? BTW, 
this common situation in parsing text files.


>> Please note that now it's not possible to serialize (convert to text) such
>> array
>>    { "" }
>> so later it can be restored from string by hb_aTokens() function.
>
> Sorry, I don't understand why? What logic do you use to de-serialize such
> array?

I guess Przemek is talking about
   FUNC funcname( aTokens, cDelimiter )
   LOCAL cString := ""
   FOR nI := 1 TO LEN(aTokens)
      cString += IIF(nI == 1, "", cDelimiter) + aTokens[nI]
   NEXT
   RETURN cString

Without empty string exception, hb_atokens() and the function above has 
1:1 correspondence for all not empty arrays of strings (assuming strings 
does not contain delimiter). That's a nice fact. With empty string 
exception the property above is not valid.


I'm just happy we do not have such discussion on Harbour mailing list!


Regards,
Mindaugas


P.S. BTW, do we have function in [x]Harbour that returns a delimited 
string from a string array? I find
    hb_memowrit("file.txt", funcname(aLines, CHR(10)))
as much useful as
    aLines := hb_atokens(hb_memoread("file.txt"), CHR(10))

------------------------------------------------------------------------------
What Every C/C++ and Fortran developer Should Know!
Read this article and learn how Intel has extended the reach of its 
next-generation tools to help Windows* and Linux* C/C++ and Fortran 
developers boost performance applications - including clusters. 
http://p.sf.net/sfu/intel-dev2devmay
_______________________________________________
xHarbour-developers mailing list
xHarbour-developers@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/xharbour-developers

Reply via email to