[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Dealing with multiple encodings in the same app

Isak Hansen

3/8/2007 10:58:00 AM

Our (rails) app is mainly utf-8, so we set kcode to u.

However, we need to generate pdfs using the cp1252 encoding, as the
FPDF library doesn't have unicode support.
Translating strings work fine using iconv, but the library is using
sprintf internally, which blows up on non-utf8 characters.

E.g.:

s = ("" << 73 << 241 << 116 << 234 << 114 << 110 << 228 << 116 << 105
<< 111 << 110 << 97 << 108 << 105 << 122 << 230 << 116 << 105 << 248
<< 110) # valid cp1252-string
puts sprintf("aa %s bb", s)

...which discards the last two characters of s.


Suggestions appreciated,
Isak

3 Answers

Manfred Stienstra

3/8/2007 12:14:00 PM

0

On Mar 8, 11:58 am, "Isak" <isak.han...@gmail.com> wrote:
> Our (rails) app is mainly utf-8, so we set kcode to u.

>From Rails 1.2 on KCODE is always set the 'u', so you might not have
to set it anymore.

> However, we need to generate pdfs using the cp1252 encoding, as the
> FPDF library doesn't have unicode support.

Ok, so FPDF doesn't support Unicode.

> Translating strings work fine using iconv, but the library is using
> sprintf internally, which blows up on non-utf8 characters.

But you can only feed it utf-8 characters?

Isak Hansen

3/8/2007 2:21:00 PM

0

On Mar 8, 1:13 pm, "Manfred Stienstra" <manf...@gmail.com> wrote:
>
> Ok, so FPDF doesn't support Unicode.
> But you can only feed it utf-8 characters?

That's the gist of it, at least when running ruby with kcode = 'u'.

I replaced the 4 occurances of sprintf("%X %s bbb", X, txt) with
sprintf("%X ", X) + txt + " bbb", which fixed our issues.
Reasonable approach, or is there a better way?


Isak

Eli Grubman

7/21/2008 3:37:00 AM

0

On Mon, 21 Jul 2008 02:31:38 GMT, flaviaR@verizon.net wrote:

>
>On 19-Jul-2008, PersianInmaster@gmail.com wrote:
>
>> Israel is a miserable failure , ther world saw this week by prisoner
>> swap that the jewish vermins take a bow for hisbollh.
>
>& you would be the first to bitch if Israel treated Hezbollah &
>it (sic) supporters the way they needed to be treated.
>
>Susan

'Israel' already treats 'converts' the way they need to be treated,
you thick Irish cunt!

Eli