Possible bug in skipOver() from std/algorithm/searching.d

Stefan Koch via Digitalmars-d digitalmars-d at puremagic.com
Sun Jan 22 03:25:54 PST 2017


On Sunday, 22 January 2017 at 11:20:18 UTC, Danny Arends wrote:
> On Sunday, 22 January 2017 at 10:30:14 UTC, Stefan Koch wrote:
>> On Sunday, 22 January 2017 at 10:01:09 UTC, Danny Arends wrote:
>>> On Sunday, 22 January 2017 at 09:55:49 UTC, Danny Arends 
>>> wrote:
>>>> Hey all,
>>>>
>>>> I encountered some unexpected behavior in std.format, I was 
>>>> parsing Wavefront obj file, and ran into an issue. I updated 
>>>> the compiler to the latest stable version (// DMD64 D 
>>>> Compiler v2.072.2), however I think it's a Phobos related 
>>>> issue.
>>>>
>>>> [...]
>>>
>>> Two further observations:
>>>
>>> (Obs 1)
>>>
>>> 47 is ascii code for forwards slash '/'
>>>
>>> (Obs 2)
>>>
>>> Changing the line:
>>>
>>> l.skipOver(x);
>>>
>>> to:
>>>
>>> l.skipOver(to!string(x));
>>>
>>> Does not show the bug.
>>
>> This is not a bug.
>> But working as intended.
>> you call skip over with an (char[] skip, int overThis)
>> and skip over will do comparions like this (if (skip[pos] == 
>> overThis))
>> and since '\' == 47;
>> it will skip over that one.
>
> Yeah I kind of figured that, however it is very confusing the 
> skipOver() function, first tries to match an integer input as a 
> ascii code.
>
> However if this ascii code is NOT found (e.g. when x = 46, 
> ascii code for '.') it promotes the integer to a string, and 
> then skips passed the string 46.
>
> I think the promotion of the input integer to string shouldn't 
> happen, or should be clearly documented..
>
> Greetings
> Danny

No it never promotes the integer to a string.
it compares a char to an uint.
You pass a string and an int to it.
And the elements of the string are getting compared to the uint
See this overload
https://dlang.org/phobos/std_algorithm_searching.html#.skipOver.2




More information about the Digitalmars-d mailing list