Bug in string.erl
Raimo Niskanen
raimo@REDACTED
Thu Nov 6 09:01:09 CET 2003
I have put this on my TODO list for R10, let's hope I find the time. I
saw that there are more functions in the module that possibly also are
too forgiving.
--
/ Raimo Niskanen, Erlang/OTP, Ericsson AB
Robert Virding wrote:
> ----- Original Message -----
> From: "Joe Armstrong" <joe@REDACTED>
> To: <erlang-questions@REDACTED>
> Sent: Tuesday, November 04, 2003 8:02 PM
> Subject: Bug in string.erl
>
>
>> But is was an atom ... did I get an exit - No for
>>
>> > string:substr(aa, 1, 20).
>> []
>>
>> Wow (Static type systems 1, Joe 0)
>>
>> The code in string.erl says
>>
>> --- quote ---
>>
>> substr1([C|String], L) when L > 0 -> [C|substr1(String, L-1)];
>> substr1(String, L) -> []. %Be nice!
>>
>> --- end quote ---
>>
>> I rather like the "%Be nice!" comment.
>>
>> IMHO all the functions in string should exit when the "string" argument
>>is not a list - I'm not asking that you "deep check" the list but a little
>>help might be nice
>
>
> Yes it is defintely a bug. The problem is that I was trying to be nice in the case where the desried substring length is longer than the remaining string inwhich case the substring just gets the remaining characters. So
>
> string:substr("abcd", 2, 5) -> "cd"
>
> The second should of course be:
>
> substr1(String, L) when list(String) -> []. %Be nice!
>
> Robert
>
More information about the erlang-questions
mailing list