|
Boost Users : |
From: Stefan Strasser (sstrasser_at_[hidden])
Date: 2005-03-11 19:26:29
Robert Ramey schrieb:
> So your case might be altered to interate not on the input characters but
> rather on the output
Thanks!
iterating on output works. in case someone else on the list is
interested, below's the code.
> a) i notices you're using a 32 bit wchar_t - note that this is non-portable.
> I would think about using std::vector<boost::int_least32>. or maybe instead
> of using the "magic" number 32 you might want to try something like
> (sizeof(wchar_t) * 8).
32: yes, I've sent example code.
int_least32: wstring/wchar_t is ok, it's a representation of a c++ wide
string literal. (google for "metac++" for a reason)
>
> b) I'm not sure I remember where I handled the padding. you should double
> check that your if your original binary string isn't modulo 6 bits you might
> find it filled with 0 after a round trip through base64.
I'm not sure what you mean here, how can an unencoded string whose CharT
is always > 6 bits be filled with 0 after round trip? base64 can, and
that's fine.
thanks again!
typedef
transform_width<binary_from_base64<std::string::const_iterator>,sizeof(wchar_t)*8,6>
base64;
std::size_t destsize=enc.size() * 6 / (8 * sizeof(wchar_t));
tthis->resize(destsize);
base64 it(enc.begin());
for(unsigned int c=0;c<destsize;++c,++it) (*this)[c]=*it;
-- > > Robert Ramey > > Stefan Strasser wrote: > >>Hi, >> >>I need to write a std::wstring which can contain binary data like \0 >>to a xml attribute, so I'm converting it to base64 but I have problems >>decoding it: >>std::copy(decode(in.begin()),decode(in.end()),); >> >>is this a correct way to decode base64? >>it works, but only if (bits % 6 == 0). >>otherwise the program is abort()ed due to an exception. >> >>the string was encoded by >>base64_from_binary<transform_width<std::wstring::const_iterator,6,32> >> >>Thanks, > > > > > > _______________________________________________ > Boost-users mailing list > Boost-users_at_[hidden] > http://lists.boost.org/mailman/listinfo.cgi/boost-users > > -- Stefan Strasser
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net