Berger, Daniel
2008-Nov-10 22:29 UTC
[Win32utils-devel] PathFindExtension and wide strings
Hi, What''s happening here? require ''windows/path'' require ''windows/unicode'' include Windows::Path include Windows::Unicode file_a = ''bar.txt'' file_w = multi_to_wide(file_a) p PathFindExtensionA(file_a) # ''.txt'' => OK p PathFindExtensionW(file_w) # ''.'' => WRONG Is Ruby chopping the result because of an embedding null? How do we deal with it? Thanks, Dan This communication is the property of Qwest and may contain confidential or privileged information. Unauthorized use of this communication is strictly prohibited and may be unlawful. If you have received this communication in error, please immediately notify the sender by reply e-mail and destroy all copies of the communication and any attachments.
2008/11/11 Berger, Daniel <Daniel.Berger at qwest.com>:> Hi, > > What''s happening here? > > require ''windows/path'' > require ''windows/unicode'' > > include Windows::Path > include Windows::Unicode > > file_a = ''bar.txt'' > file_w = multi_to_wide(file_a) > > p PathFindExtensionA(file_a) # ''.txt'' => OK > p PathFindExtensionW(file_w) # ''.'' => WRONG > > Is Ruby chopping the result because of an embedding null? How do we deal > with it? >The result is chopped by this code in api.c: case _T_STRING: v_return = rb_str_new2((TCHAR*)return_value); break; In case of Unicode something like this would be possible: case _T_STRING: v_return = rb_str_new((TCHAR*)return_value, wcslen((wchar_t*)return_value)); break; Regards, Park Heesob
Heesob Park wrote:> 2008/11/11 Berger, Daniel <Daniel.Berger at qwest.com>: >> Hi, >> >> What''s happening here? >> >> require ''windows/path'' >> require ''windows/unicode'' >> >> include Windows::Path >> include Windows::Unicode >> >> file_a = ''bar.txt'' >> file_w = multi_to_wide(file_a) >> >> p PathFindExtensionA(file_a) # ''.txt'' => OK >> p PathFindExtensionW(file_w) # ''.'' => WRONG >> >> Is Ruby chopping the result because of an embedding null? How do we deal >> with it? >> > The result is chopped by this code in api.c: > > case _T_STRING: > v_return = rb_str_new2((TCHAR*)return_value); > break; > > In case of Unicode something like this would be possible: > > case _T_STRING: > v_return = rb_str_new((TCHAR*)return_value, > wcslen((wchar_t*)return_value)); > break;Ah, yes, thanks. That will work for ANSI, too, won''t it? I don''t have my C dev environment setup on this laptop yet (I''ve been lazy), so I can''t test. If it will work for both Unicode and ANSI then please test and commit the change if all goes well. If not, what do you recommend? Thanks, Dan
2008/11/11 Daniel Berger <djberg96 at gmail.com>:> Heesob Park wrote: >> >> 2008/11/11 Berger, Daniel <Daniel.Berger at qwest.com>: >>> >>> Hi, >>> >>> What''s happening here? >>> >>> require ''windows/path'' >>> require ''windows/unicode'' >>> >>> include Windows::Path >>> include Windows::Unicode >>> >>> file_a = ''bar.txt'' >>> file_w = multi_to_wide(file_a) >>> >>> p PathFindExtensionA(file_a) # ''.txt'' => OK >>> p PathFindExtensionW(file_w) # ''.'' => WRONG >>> >>> Is Ruby chopping the result because of an embedding null? How do we deal >>> with it? >>> >> The result is chopped by this code in api.c: >> >> case _T_STRING: >> v_return = rb_str_new2((TCHAR*)return_value); >> break; >> >> In case of Unicode something like this would be possible: >> >> case _T_STRING: >> v_return = rb_str_new((TCHAR*)return_value, >> wcslen((wchar_t*)return_value)); >> break; > > Ah, yes, thanks. > > That will work for ANSI, too, won''t it? I don''t have my C dev environment > setup on this laptop yet (I''ve been lazy), so I can''t test. > > If it will work for both Unicode and ANSI then please test and commit the > change if all goes well. If not, what do you recommend? >That is not working for ANSI. Though there might be a better way to detect unicode string, I recommend this code: case _T_STRING: { VALUE v_proc = rb_iv_get(self, "@effective_function_name"); char *proc = RSTRING(v_proc)->ptr; if(proc[strlen(proc)-1]==''W'') v_return = rb_str_new((TCHAR*)return_value, wcslen((wchar_t*)return_value)*2); else v_return = rb_str_new2((TCHAR*)return_value); } Regards, Park Heesob
Berger, Daniel
2008-Nov-11 15:08 UTC
[Win32utils-devel] PathFindExtension and wide strings
> -----Original Message----- > From: win32utils-devel-bounces at rubyforge.org > [mailto:win32utils-devel-bounces at rubyforge.org] On Behalf Of > Heesob Park > Sent: Monday, November 10, 2008 7:20 PM > To: Development and ideas for win32utils projects > Subject: Re: [Win32utils-devel] PathFindExtension and wide strings > > 2008/11/11 Daniel Berger <djberg96 at gmail.com>: > > Heesob Park wrote: > >> > >> 2008/11/11 Berger, Daniel <Daniel.Berger at qwest.com>: > >>> > >>> Hi, > >>> > >>> What''s happening here? > >>> > >>> require ''windows/path'' > >>> require ''windows/unicode'' > >>> > >>> include Windows::Path > >>> include Windows::Unicode > >>> > >>> file_a = ''bar.txt'' > >>> file_w = multi_to_wide(file_a) > >>> > >>> p PathFindExtensionA(file_a) # ''.txt'' => OK > >>> p PathFindExtensionW(file_w) # ''.'' => WRONG > >>> > >>> Is Ruby chopping the result because of an embedding null? > How do we > >>> deal with it? > >>> > >> The result is chopped by this code in api.c: > >> > >> case _T_STRING: > >> v_return = rb_str_new2((TCHAR*)return_value); > >> break; > >> > >> In case of Unicode something like this would be possible: > >> > >> case _T_STRING: > >> v_return = rb_str_new((TCHAR*)return_value, > >> wcslen((wchar_t*)return_value)); > >> break; > > > > Ah, yes, thanks. > > > > That will work for ANSI, too, won''t it? I don''t have my C dev > > environment setup on this laptop yet (I''ve been lazy), so I > can''t test. > > > > If it will work for both Unicode and ANSI then please test > and commit > > the change if all goes well. If not, what do you recommend? > > > That is not working for ANSI. > Though there might be a better way to detect unicode string, > I recommend this code: > > case _T_STRING: > { > VALUE v_proc = rb_iv_get(self, "@effective_function_name"); > char *proc = RSTRING(v_proc)->ptr; > if(proc[strlen(proc)-1]==''W'') > v_return = rb_str_new((TCHAR*)return_value, > wcslen((wchar_t*)return_value)*2); > else > v_return = rb_str_new2((TCHAR*)return_value); > }Ok, thanks. I implemented that for both T_STRING and T_POINTER. Hope that was ok. Regards, Dan This communication is the property of Qwest and may contain confidential or privileged information. Unauthorized use of this communication is strictly prohibited and may be unlawful. If you have received this communication in error, please immediately notify the sender by reply e-mail and destroy all copies of the communication and any attachments.