michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #include "nsReplacementToUnicode.h" michael@0: michael@0: nsReplacementToUnicode::nsReplacementToUnicode() michael@0: : mSeenByte(false) michael@0: { michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: nsReplacementToUnicode::Convert(const char* aSrc, michael@0: int32_t* aSrcLength, michael@0: char16_t* aDest, michael@0: int32_t* aDestLength) michael@0: { michael@0: if (mSeenByte || !(*aSrcLength)) { michael@0: *aDestLength = 0; michael@0: return NS_PARTIAL_MORE_INPUT; michael@0: } michael@0: if (mErrBehavior == kOnError_Signal) { michael@0: mSeenByte = true; michael@0: *aSrcLength = 0; michael@0: *aDestLength = 0; michael@0: return NS_ERROR_ILLEGAL_INPUT; michael@0: } michael@0: if (!(*aDestLength)) { michael@0: *aSrcLength = -1; michael@0: return NS_PARTIAL_MORE_OUTPUT; michael@0: } michael@0: mSeenByte = true; michael@0: *aDest = 0xFFFD; michael@0: *aDestLength = 1; michael@0: return NS_PARTIAL_MORE_INPUT; michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: nsReplacementToUnicode::GetMaxLength(const char* aSrc, michael@0: int32_t aSrcLength, michael@0: int32_t* aDestLength) michael@0: { michael@0: if (!mSeenByte && aSrcLength > 0) { michael@0: *aDestLength = 1; michael@0: } else { michael@0: *aDestLength = 0; michael@0: } michael@0: return NS_EXACT_LENGTH; michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: nsReplacementToUnicode::Reset() michael@0: { michael@0: mSeenByte = false; michael@0: return NS_OK; michael@0: }