iOS UTF7 encoding/decoding -


i have issue utf7 decoding. able isolate problem, creating following sample code:

nsstringencoding stringencoding = myfunctionfortranslatecodepagetoencoding(codepage); // see end of string, it's important const char * testbuffer ="aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa+adw-";  nsstring * teststring = [[nsstring alloc] initwithbytes:testbuffer length:strlen(testbuffer) encoding:stringencoding]; 

where:

strlen(testbuffer) 508,

'codepage' 65000,

'stringencoding' 2214592768 (probably utf-7, expected, can't find clear confirmation…).

'+adw-' utf7 sequence '<'.

in example teststring nil, conversion fails. here strange things:

  1. when remove 1 'a' testbuffer, conversion works, teststring created properly. when add 1 or more 'a', doesn't work.
  2. when 'damage' utf7 encoded symbol @ end (the 1 in example, '+adw-'), works fine. can change '.adw-' or '+adw.' , buffer converted properly. of course, 'damaged' symbol not decoded, it's written literally conversion works. produces "…aaaaa.adw-" in nsstring. can cut buffer 1, i'll have "…aaaaa+adw" , converted (as utf7 symbol incomplete).
  3. when add ascii character @ end of buffer, after utf7 symbol, works. i.e. "…aaaaa+adw-a" converted nsstring "…aaa>a".
  4. when buffer contains more utf7 symbols, length when starts failing changes. it's not 508 or more characters.
  5. i can use other utf7 symbol @ end. doesn't matter.

i've tried replace initwithbytes: method initwithcstring. didn't check possible cases, in tested ones behaves same initwithbytes:. i've performed tests on ios 6.0.

do have ideas how deal utf7 encoded strings?


Comments

Popular posts from this blog

how to insert data php javascript mysql with multiple array session 2 -

multithreading - Exception in Application constructor -

windows - CertCreateCertificateContext returns CRYPT_E_ASN1_BADTAG / 8009310b -