From: Michael Ow <mo...@us...> - 2008-03-05 19:00:26
|
In ICU4C, callbacks are set using ucnv_setFromUCallback and ucnv_setToUCallback functions. In calling these functions, you can specify the context to be used in the callback. Currently in ICU4J, the only way to set the callback is to use the java nio methods of onmalformedInput and onUnmappableInput. In these methods, you pass the ErrorAction to specify the action that takes place on the error. However, there is no way to set the context or to specify using a substitute or escape sequence like you can in ICU4C. I propose adding the following two methods in CharsetDecoderICU and CharsetEncoderICU (respectively): public final void setToUCallback(CoderResult err, CharsetCallback.Decoder newCallback, Object newContext) { if (err.isMalformed()) { onMalformedInput = newCallback; } else if (err.isUnmappable()) { onUnmappableCharacter = newCallback; } else { /* Error: Only malformed and unmappable are handled. */ } if (toUContext == null || !toUContext.equals(newContext)) { toUContext = newContext; } } public final void setFromUCallback(CoderResult err, CharsetCallback.Decoder newCallback, Object newContext) { if (err.isMalformed()) { onMalformedInput = newCallback; } else if (err.isUnmappable()) { onUnmappableCharacter = newCallback; } else { /* Error: Only malformed and unmappable are handled. */ } if (toUContext == null || !toUContext.equals(newContext)) { toUContext = newContext; } } So the user specifies the CharsetCallback object. He can use the ones provided in ICU4J CharsetCallback or create their own. -Michael Ow |