Trapping errors within unpack?

L

Lloyd Zusman

I'm trying to do a simple conversion between UTF-8 and 8-bit ascii.
The key part of my program goes like this:

ARGF.each {
|line|
puts line.unpack('U*').pack('c*')
}

This works fine unless the input contains an invalid UTF-8 character
(which sometimes occurs). In that case, the 'unpack' method terminates
at the offending character, and no more translation takes place.

What I'd like to do is trap errors like that and put some sort of
special character in the output (such as '?') for each invalid UTF-8
character that is encountered, and then continue with the rest of the
input. However, I don't know how to do that within 'unpack'.

Can anyone suggest a solution?

Thanks in advance.
 
Z

Zach Dennis

Hi,

This isn't directly pertaining to ruby under cygwin, because I can
successfully compile ruby under cygwin. I am attempting to compile
wxruby under cygwin and I haven't had that much luck. All of my files
compile but when the object files are linked together they always error
out with a bunch of "undefined resource" errors. I was wondering if
anyone with more experience in this area could point me in a direction ,
like my library file isn't being found, i am missing a library file, I
should check my library file for certain method signatures, etc...

here is some of the output i get...any pointers would be of great help.
Thanks,

Zach

c++ -shared -s -L/usr/local/lib /usr/local/lib/libwxmsw242d.a -ljpeg
-ltiff -lz -lrpcrt4 -loleaut32 -lole32 -luuid -lwinspool -lwinmm
-lshell32 -lcomctl32 -lctl3d32 -ladvapi32 -lwsock32 -lkernel32 -luser32
-lgdi32 -lcomdlg32 -Wl,--enable-auto-import,--export-all
-L"/usr/local/lib" -L/usr/src/wxWindows-2.4.2/libs -o wxruby.so
htmlprocessor.o htmlwindow.o htmleasyprinting.o wx.o app.o bitmap.o
button.o calendar.o checkbox.o choice.o colour.o colourdata.o
colourdialog.o combobox.o const.o date.o dialog.o dirdialog.o event.o
evthandler.o filedialog.o font.o fontdata.o fontdialog.o frame.o gauge.o
layout.o listbox.o menu.o menubar.o messagedialog.o point.o radio.o
rect.o size.o sizer.o slider.o spin.o statictext.o textctrl.o timer.o
validator.o window.o icon.o artprovider.o log.o listctrl.o list.o
panel.o scrolledwindow.o dc.o brush.o pen.o caret.o statusbar.o
ownerdrawn.o config.o region.o cursor.o notebook.o tooltip.o mask.o
socket.o url.o stream.o toolbar.o image.o palette.o treectrl.o
classinfo.o splitterwindow.o methods.o staticbitmap.o control.o grid.o
menuitem.o textattr.o dataformat.o togglebutton.o dropsource.o
droptarget.o textdroptarget.o filedroptarget.o filedataobject.o
textdataobject.o dataobject.o dataobjectsimple.o dynamiccast.o
mdiparentframe.o mdiclientwindow.o mdichildframe.o -lruby -lcrypt

htmlprocessor.o(.text+0x3ca): In function
`_ZN15WxHtmlProcessor7ProcessEiPmm':
/usr/src/wxWindows-2.4.2/include/wx/string.h:249: undefined reference to
`_wxEmptyString'
htmlprocessor.o(.text+0x3f8): In function
`_ZN15WxHtmlProcessor7ProcessEiPmm':
/usr/src/wxruby-0.5-src/src/htmlprocessor.cpp:82: undefined reference to
`wxString::eek:perator=(char const*)'
htmlprocessor.o(.text+0x6f4): In function
`_ZNK21wxHtmlProcessorHelper7ProcessERK8wxString':
/usr/src/wxWindows-2.4.2/include/wx/string.h:311: undefined reference to
`wxString::InitWith(char const*, unsigned, unsigned)'
htmlprocessor.o(.rdata$_ZTV21wxHtmlProcessorHelper+0x14): In function
`_ZNK15wxHtmlProcessor11GetPriorityEv':
/usr/src/wxWindows-2.4.2/include/wx/html/htmlproc.h: undefined reference
to `wxObject::CreateRefData() const'
htmlprocessor.o(.rdata$_ZTV21wxHtmlProcessorHelper+0x18):/usr/src/wxWindows-2.4.2/include/wx/html/htmlproc.h:
undefined reference to `wxObject::CloneRefData(wxObjectRefData const*)
const'
htmlprocessor.o(.text$_ZNK15wxHtmlProcessor12GetClassInfoEv+0x4):/usr/src/wxWindows-2.4.2/include/wx/html/htmlproc.h:
undefined reference to `wxHtmlProcessor::sm_classwxHtmlProcessor'
htmlprocessor.o(.text$_ZN21wxHtmlProcessorHelperD1Ev+0xb):/usr/src/wxWindows-2.4.2/include/wx/html/htmlproc.h:
undefined reference to `vtable for wxObject'
htmlprocessor.o(.text$_ZN21wxHtmlProcessorHelperD1Ev+0x13):/usr/src/wxWindows-2.4.2/include/wx/html/htmlproc.h:
undefined reference to `wxObject::UnRef()'
htmlprocessor.o(.text$_ZN21wxHtmlProcessorHelperD0Ev+0xe):/usr/src/wxWindows-2.4.2/include/wx/html/htmlproc.h:
undefined reference to `vtable for wxObject'
htmlprocessor.o(.text$_ZN21wxHtmlProcessorHelperD0Ev+0x16):/usr/src/wxWindows-2.4.2/include/wx/html/htmlproc.h:
undefined reference to `wxObject::UnRef()'
htmlwindow.o(.text+0x697): In function
`_ZN12WxHtmlWindow12constructor0EiPmm':
/usr/src/wxruby-0.5-src/src/htmlwindow.cpp:110: undefined reference to
`_wxDefaultPosition'
htmlwindow.o(.text+0x6a6):/usr/src/wxruby-0.5-src/src/htmlwindow.cpp:113:
undefined reference to `_wxDefaultSize'
htmlwindow.o(.text+0x710): In function
`_ZN12WxHtmlWindow12constructor0EiPmm':
/usr/src/wxWindows-2.4.2/include/wx/string.h:311: undefined reference to
`wxString::InitWith(char const*, unsigned, unsigned)'
 
N

nobu.nokada

Hi,

At Sun, 29 Aug 2004 11:57:41 +0900,
Zach Dennis wrote in [ruby-talk:110861]:
This isn't directly pertaining to ruby under cygwin, because I can
successfully compile ruby under cygwin. I am attempting to compile
wxruby under cygwin and I haven't had that much luck. All of my files
compile but when the object files are linked together they always error
out with a bunch of "undefined resource" errors. I was wondering if
anyone with more experience in this area could point me in a direction ,
like my library file isn't being found, i am missing a library file, I
should check my library file for certain method signatures, etc...

It is a FAQ of ld.
<http://www.delorie.com/djgpp/v2faq/faq8_10.html>

The order of -l options is important. Try moving them after
the object files.
 
Z

Zach Dennis

Hi,

At Sun, 29 Aug 2004 11:57:41 +0900,
Zach Dennis wrote in [ruby-talk:110861]:

This isn't directly pertaining to ruby under cygwin, because I can
successfully compile ruby under cygwin. I am attempting to compile
wxruby under cygwin and I haven't had that much luck. All of my files
compile but when the object files are linked together they always error
out with a bunch of "undefined resource" errors. I was wondering if
anyone with more experience in this area could point me in a direction ,
like my library file isn't being found, i am missing a library file, I
should check my library file for certain method signatures, etc...

It is a FAQ of ld.
<http://www.delorie.com/djgpp/v2faq/faq8_10.html>

The order of -l options is important. Try moving them after
the object files.
Thank you Nobu, that solved the linking issue i was getting.

Zach
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top