digitalmars.D.learn - Bug with std.string.indexOf and case sensivity
- Alexandre L. (14/14) May 16 2014 Hello,
- =?UTF-8?B?QWxpIMOHZWhyZWxp?= (3/17) May 16 2014 All return 0 with dmd git head.
- Alexandre L. (8/35) May 16 2014 Hi Ali,
- Alexandre L. (19/21) May 16 2014 Nevermind that.
- =?UTF-8?B?QWxpIMOHZWhyZWxp?= (5/26) May 16 2014 I can't explain right now how it happens but I suspect that there is an
- Alexandre L. (4/42) May 16 2014 That would make perfect sense.
Hello, I was playing around with indexOf when I noticed that the parameter CaseSensitive seems to have a weird behavior. Let's say the following code: string str = "Les chemises sont sèches"; write(std.string.indexOf(str, "Les")); // Returns 0, as expected write(std.string.indexOf(str, "les", CaseSensitive.no)); // Returns -1 while it should return 0 write(std.string.indexOf(str, "Les", CaseSensitive.yes)); // Returns -1 while it should return 0 I'm using DMD 2.065 and if I am not mistaken, I think it was working fine with DMD 2.064. Or is it that I do not understand what CaseSensitive really do? Alexandre L.
May 16 2014
On 05/16/2014 04:52 PM, Alexandre L. wrote:Hello, I was playing around with indexOf when I noticed that the parameter CaseSensitive seems to have a weird behavior. Let's say the following code: string str = "Les chemises sont sèches"; write(std.string.indexOf(str, "Les")); // Returns 0, as expected write(std.string.indexOf(str, "les", CaseSensitive.no)); // Returns -1 while it should return 0 write(std.string.indexOf(str, "Les", CaseSensitive.yes)); // Returns -1 while it should return 0 I'm using DMD 2.065 and if I am not mistaken, I think it was working fine with DMD 2.064. Or is it that I do not understand what CaseSensitive really do? Alexandre L.All return 0 with dmd git head. Ali
May 16 2014
On Saturday, 17 May 2014 at 00:31:14 UTC, Ali Çehreli wrote:On 05/16/2014 04:52 PM, Alexandre L. wrote:Hi Ali, Thanks for your reply. I'm not working with the git head so it seems the issue was probably fixed after? Note that I am compiling as "dmd -w -O -unittest" I'll try to fetch git head and get everything working. Alexandre L.Hello, I was playing around with indexOf when I noticed that the parameter CaseSensitive seems to have a weird behavior. Let's say the following code: string str = "Les chemises sont sèches"; write(std.string.indexOf(str, "Les")); // Returns 0, as expected write(std.string.indexOf(str, "les", CaseSensitive.no)); // Returns -1 while it should return 0 write(std.string.indexOf(str, "Les", CaseSensitive.yes)); // Returns -1 while it should return 0 I'm using DMD 2.065 and if I am not mistaken, I think it was working fine with DMD 2.064. Or is it that I do not understand what CaseSensitive really do? Alexandre L.All return 0 with dmd git head. Ali
May 16 2014
I'll try to fetch git head and get everything working. Alexandre L.Nevermind that. For some reasons, the bug was happening when my main.d file looked like this: import std.stdio; //import std.string; // will work when imported int main() { string str = "Les chemises"; // doesnt work write(std.string.indexOf(str, "Les", CaseSensivity.yes)); return 0; } --- While it works when importing std.string. Note that I was using exactly the same enum (at least, I thought ?) than std.string enum CaseSensivity { no, yes } Whatever, it works now. I just need to don't forget to import std.string. Alexandre L.
May 16 2014
On 05/16/2014 05:55 PM, Alexandre L. wrote:I can't explain right now how it happens but I suspect that there is an implicit conversion issue and your enum literal is taken as the startIdx parameter of one of the many overloads of indexOf. AliI'll try to fetch git head and get everything working. Alexandre L.Nevermind that. For some reasons, the bug was happening when my main.d file looked like this: import std.stdio; //import std.string; // will work when imported int main() { string str = "Les chemises"; // doesnt work write(std.string.indexOf(str, "Les", CaseSensivity.yes));return 0; } --- While it works when importing std.string. Note that I was using exactly the same enum (at least, I thought ?) than std.string enum CaseSensivity { no, yes } Whatever, it works now. I just need to don't forget to import std.string. Alexandre L.
May 16 2014
On Saturday, 17 May 2014 at 01:08:47 UTC, Ali Çehreli wrote:On 05/16/2014 05:55 PM, Alexandre L. wrote:That would make perfect sense. Thanks for the help. I'll try to investigate further later. Alexandre L.looked likeI'll try to fetch git head and get everything working. Alexandre L.Nevermind that. For some reasons, the bug was happening when my main.d filethis: import std.stdio; //import std.string; // will work when imported int main() { string str = "Les chemises"; // doesnt work write(std.string.indexOf(str, "Les", CaseSensivity.yes));I can't explain right now how it happens but I suspect that there is an implicit conversion issue and your enum literal is taken as the startIdx parameter of one of the many overloads of indexOf. Alireturn 0; } --- While it works when importing std.string. Note that I wasusing exactlythe same enum (at least, I thought ?) than std.string enum CaseSensivity { no, yes } Whatever, it works now. I just need to don't forget to importstd.string.Alexandre L.
May 16 2014