1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/intl/uconv/src/nsReplacementToUnicode.cpp Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,56 @@ 1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.7 + 1.8 +#include "nsReplacementToUnicode.h" 1.9 + 1.10 +nsReplacementToUnicode::nsReplacementToUnicode() 1.11 + : mSeenByte(false) 1.12 +{ 1.13 +} 1.14 + 1.15 +NS_IMETHODIMP 1.16 +nsReplacementToUnicode::Convert(const char* aSrc, 1.17 + int32_t* aSrcLength, 1.18 + char16_t* aDest, 1.19 + int32_t* aDestLength) 1.20 +{ 1.21 + if (mSeenByte || !(*aSrcLength)) { 1.22 + *aDestLength = 0; 1.23 + return NS_PARTIAL_MORE_INPUT; 1.24 + } 1.25 + if (mErrBehavior == kOnError_Signal) { 1.26 + mSeenByte = true; 1.27 + *aSrcLength = 0; 1.28 + *aDestLength = 0; 1.29 + return NS_ERROR_ILLEGAL_INPUT; 1.30 + } 1.31 + if (!(*aDestLength)) { 1.32 + *aSrcLength = -1; 1.33 + return NS_PARTIAL_MORE_OUTPUT; 1.34 + } 1.35 + mSeenByte = true; 1.36 + *aDest = 0xFFFD; 1.37 + *aDestLength = 1; 1.38 + return NS_PARTIAL_MORE_INPUT; 1.39 +} 1.40 + 1.41 +NS_IMETHODIMP 1.42 +nsReplacementToUnicode::GetMaxLength(const char* aSrc, 1.43 + int32_t aSrcLength, 1.44 + int32_t* aDestLength) 1.45 +{ 1.46 + if (!mSeenByte && aSrcLength > 0) { 1.47 + *aDestLength = 1; 1.48 + } else { 1.49 + *aDestLength = 0; 1.50 + } 1.51 + return NS_EXACT_LENGTH; 1.52 +} 1.53 + 1.54 +NS_IMETHODIMP 1.55 +nsReplacementToUnicode::Reset() 1.56 +{ 1.57 + mSeenByte = false; 1.58 + return NS_OK; 1.59 +}