Hi all, After a recent ruby-talk thread I decided to go back and refactor the File.basename method in win32-file. Sure enough, after a I added some more tests I discovered a couple minor bugs. After reworking it, I still can''t get one test to pass. Specifically, multiple trailing slashes. Here''s the test that shows the issue: assert_equal("bar", File.basename("C:/foo/bar\\\\")) Instead of "bar", I end up with "bar\" because I only call PathRemoveBackslash() once. I figured I could solve it with something like this: while(PathRemoveBackslash(path)){} But that doesn''t work. I thought you could just call this until you hit NULL, but I can''t seem to make it work. I suspect the answer is easy, I''m just not seeing it for some reason. Ideas? Dan
Hi Dan,> Hi all, > > After a recent ruby-talk thread I decided to go back and refactor the > File.basename method in win32-file. Sure enough, after a I added some > more tests I discovered a couple minor bugs. > > After reworking it, I still can''t get one test to pass. Specifically, > multiple trailing slashes. Here''s the test that shows the issue: > > assert_equal("bar", File.basename("C:/foo/bar\\\\")) > > Instead of "bar", I end up with "bar\" because I only call > PathRemoveBackslash() once. I figured I could solve it with something > like this: > > while(PathRemoveBackslash(path)){} > > But that doesn''t work. I thought you could just call this until you hit > NULL, but I can''t seem to make it work. I suspect the answer is easy, > I''m just not seeing it for some reason. > > Ideas? > > Dan >The msdn document reads Returns the address of the NULL that replaced the backslash, or the address of the last character if it''s not a backslash. ^^^^^^^^^^^^^^^^ You should use while(!*PathRemoveBackslash(path)); Regards, Park Heesob
Park Heesob wrote:> Hi Dan,> > The msdn document reads > Returns the address of the NULL that replaced the backslash, or the > address of the last character if it''s not a backslash. > > ^^^^^^^^^^^^^^^^ > > You should use > > while(!*PathRemoveBackslash(path)); > > Regards, > > Park HeesobDang, I thought I tried that and it didn''t work. I must have done something wrong. Thanks! Dan