vcard#decode fails on UTF-16 files because the test uses the wrong character. It should as follows... vcard.rb 682: when /^\x00\x42/i 683; string = string.unpack(''n*'').pack(''U*'') 684: when /^\x42\x00/i 685: string = string.unpack(''v*'').pack(''U*'') And there should probably be a similar test for lower case ''b'' as well, as per the documentation.
Quoting henryj at paradise.net.nz, on Sat, Feb 24, 2007 at 03:38:30PM +1300:> vcard#decode fails on UTF-16 files because the test uses the wrong > character. It should as follows... > > vcard.rb > 682: when /^\x00\x42/i > 683; string = string.unpack(''n*'').pack(''U*'') > 684: when /^\x42\x00/i > 685: string = string.unpack(''v*'').pack(''U*'') > > And there should probably be a similar test for lower case ''b'' as > well, as per the documentation.The test for ''b'' is already there, b is x62. The comparison is supposed to be case-insensitive, and seems to work fine: ensemble:~/p/ruby/svn-trunk % ruby1.8 -e ''s="\0B"; p s; p s =~ /\x00\x62/'' "\000B" nil ensemble:~/p/ruby/svn-trunk % ruby1.8 -e ''s="\0B"; p s; p s =~ /\x00\x62/i'' "\000B" 0 I have a suspicion that you are using ruby 1.6, is that possible? I can change the regexs to /^\0B/i and /^B\0/i, which seems to work with ruby 1.6, but I don''t believe vPim will work on ruby 1.6 anymore. I used to run the unit tests against it and tried to make it work with both, because I use OS X 10.3 sometimes, but then gave up, it was too hard to stay compatible, and ruby 1.8.1 was released a long, long time ago. Sam
On Mon, Feb 26, 2007 at 09:13:35PM +1300, Henry Maddocks wrote:> >>And there should probably be a similar test for lower case ''b'' as > >>well, as per the documentation. > > > >The test for ''b'' is already there, b is x62. The comparison is > >supposed > >to be case-insensitive, and seems to work fine: > > > >ensemble:~/p/ruby/svn-trunk % ruby1.8 -e ''s="\0B"; p s; p s =~ /\x00\x62/'' > >"\000B" > >nil > >ensemble:~/p/ruby/svn-trunk % ruby1.8 -e ''s="\0B"; p s; p s =~ /\x00\x62/i'' > >"\000B" > >0 > > I''m using 1.8.5. You are right, lower case b is x62. Upper case B is > x42 which is why my code was failing. How is the code case insensitive?Can you try these commands? <your-ruby> --version <your-ruby> -e ''s="\0B"; p s; p s =~ /\x00\x62/i'' The i option in the regex -----------------------^ makes the comparison insensitive. Sam
On 27/02/2007, at 11:11 AM, Sam Roberts wrote:> Can you try these commands? > > <your-ruby> --version > <your-ruby> -e ''s="\0B"; p s; p s =~ /\x00\x62/i'' > > The i option in the regex -----------------------^ makes the > comparison > insensitive.henry$ ruby --version ruby 1.8.5 (2006-08-25) [powerpc-darwin8.8.0] henry$ ruby -e ''s="\0B"; p s; p s =~ /\x00\x62/i'' "\000B" nil henry$ ruby -e ''s="\0B"; p s; p s =~ /\x00\x42/i'' "\000B" 0 henry$