0

The converter ucnv_convertEx() in the ICU library optionally requires a 'pivot' buffer. The correspondent pointers may be set to NULL, but what is actually the purpose of that? Is it faster? Is it not enough to not increment the source pointer beyond the last converted byte + 1?

一二三
  • 21,059
  • 11
  • 65
  • 74
Frank-Rene Schäfer
  • 3,182
  • 27
  • 51

1 Answers1

1

The "pivot" buffer is just scratch space that is used to temporarily hold the conversion from the source to UTF-16, and then from UTF-16 to the target (if a direct conversion between the source and target doesn't exist). That is, ucnv_convertEx() converts from the source to the target by "pivoting" through UTF-16.

If you don't supply a pivot buffer, an internal buffer (of 1024 stack-allocated UChars) is used instead.

Supplying a pivot buffer may be more efficient if you already have a large amount of space allocated (so the conversion to and from UTF-16 happens all at once), or you want to inspect the intermediate conversion if there are errors.

一二三
  • 21,059
  • 11
  • 65
  • 74
  • So, in conversion sequences, the pivot buffer should be possibly reset without effecting the conversion. However, it seems that the conversion function keeps stuff in that stomach, so its more than just a chunk of memory that ICU may use. I cannot use the memory between sequences of calls to 'ucnv_convertEx', can I? – Frank-Rene Schäfer Oct 20 '15 at 09:43
  • 1
    You can do whatever you like with it between calls. The pivot buffer doesn't contain any state, but `ucnv_convertEx()` doesn't bother to clean it out when it's done. – 一二三 Oct 20 '15 at 11:07
  • If this is correct, why do I pass a pointer to a pointer as 'pivot iterator'? A simple pointer would be enough. – Frank-Rene Schäfer Oct 20 '15 at 17:49
  • I found the following which falsifies your statement from the documentation of ucnv_convertEx(): <<>> – Frank-Rene Schäfer Oct 20 '15 at 22:00
  • 1
    The important part there is "for streaming conversion", where each chunk may not result in a complete conversion (i.e., the error code isn't a `U_SUCCESS()`). – 一二三 Oct 20 '15 at 22:29
  • Of course, streaming. I cannot think of another use-case where the maintenance of an internal state makes sense. I will post another question about the internal state of the ICU converter. – Frank-Rene Schäfer Oct 21 '15 at 06:43