0

I am using OSTranslate to convert my mail body content to Unicode String. Which is working fine for char* less then WORD size 65535.

WORD Length = MAXWORD;
actualOutLength = OSTranslate(OS_TRANSLATE_LMBCS_TO_UNICODE, (char*)inPtr,
Length, (char*)outPtr, Length);

After conversion the output array contains only a part of a source string.

Please Suggest what is the correct approach to set the size as my input string size is exceeding MAXWORD size limit.

Haseena Parkar
  • 939
  • 2
  • 12
  • 28

1 Answers1

0

One way I've come up with is that if (MAXWORD-actualOutLength<4) then take the output buffer and do the reverse translate using OS_TRANSLATE_UNICODE_TO_LMBCS. You will throw away this result -- but the length returned is the length of the portion of your original input buffer that was processed. So you can use that length to advance your inPtr, call OSTranslate again with OS_TRANSLATE_LMBCS_TO_UNICODE again and continue building your extended output buffer in a loop until you exhaust your input buffer. Note that this would only work if your input string is LMBCS optimized for Group 1. If it was optimized for a different group, the reverse translation length will probably not align with the characters in your input buffer.

Another way would be to use NLS_get in a loop to count out characters in the input buffer up to MAXWORD/2. You can then use either NLS_translate or OSTranslate on a the first part of the input buffer and be sure that the output will fit within MAXWORD. Then start counting again from the last pointer you received back from NLS_get, and continue in a loop until you have run through the entire input buffer.

Richard Schwartz
  • 14,463
  • 2
  • 23
  • 41
  • Hey thanks for the solution! I have implemented the second solution by reading data in chunk of MAXWORD/2 but consider a scenerio of boundary condition where we have a chinese char occupying 3 byte out of which say first byte appears in first chunk and next two bytes are in next chunk will that affect the solution? – Haseena Parkar Apr 12 '12 at 05:17
  • Yes, I do understand the boundary condition you are talking about. That is why I suggested using the NLS_get() function to scan and count the characters. The NLS functions in the Notes C API toolkit are built to handle LMBCS characters correctly. – Richard Schwartz Apr 12 '12 at 09:59
  • I have jumbled up few things, i will really apprecaite if you can give me a sample code for reading data using NLS_get function. – Haseena Parkar Apr 12 '12 at 13:10
  • Sorry. I don't have any sample code for the NLS calls, but the doc in the Notes C API toolkit looks pretty straightforward. Each time you call it, the **ppString argument will advance to the next multi-byte character in the input buffer, so you can use this to count the characters. So you can save your starting pointer, call NLS_get N times in a loop and now you have the ending pointer for N multibyte characters in your buffer. It looks like you will have to subtract the starting pointer from the ending pointer to get the length, but then you can call OSTranslate for N chars. – Richard Schwartz Apr 12 '12 at 18:43
  • If it works for you, please come back and leave a comment. I am very interested in knowing the result. – Richard Schwartz Apr 13 '12 at 14:19
  • will try it on Monday as i am on leave. Surely will drop a comment on completion. Thanks! – Haseena Parkar Apr 13 '12 at 14:41
  • Hi rhsatrhs: your guidence have been helping me a lot to achieve the milestone, i got stuck at a point thought if you could help me for reading inline images from a file, please see the below link http://www-10.lotus.com/ldd/nd85forum.nsf/DateAllThreadedWeb/ee37907f5262691f85257a5d003f9cac?OpenDocument – Haseena Parkar Aug 24 '12 at 04:51
  • No, sorry. I saw your post in the Lotus forum, and I would have answered there if I could have, but I have no knowledge of the internal image format. – Richard Schwartz Aug 24 '12 at 20:25
  • Hi rhsatrhs: Is it possible to store contacts in the mail.nsf, i have a client requirement to combine contacts and mails into same NSF file. Could you please suggest how can i achieve it? – Haseena Parkar Dec 03 '12 at 14:37
  • You should open that as a separate question and address it to everyone, not specifically to me. – Richard Schwartz Dec 03 '12 at 15:08