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

Bauss via Digitalmars-d digitalmars-d at puremagic.com
Tue Jan 24 13:15:24 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

It really isn't if you understand how the types are operating 
when compiled. There is theoretically no such thing as a 
character when it comes to actual data types. It's nothing but a 
number on the OS level. Unless it's a Unicode etc. then it's a 
sequence of numbers to form code points


More information about the Digitalmars-d mailing list