nsReplacementToUnicode.cpp 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /* This Source Code Form is subject to the terms of the Mozilla Public
  2. * License, v. 2.0. If a copy of the MPL was not distributed with this
  3. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  4. #include "nsReplacementToUnicode.h"
  5. nsReplacementToUnicode::nsReplacementToUnicode()
  6. : mSeenByte(false)
  7. {
  8. }
  9. NS_IMETHODIMP
  10. nsReplacementToUnicode::Convert(const char* aSrc,
  11. int32_t* aSrcLength,
  12. char16_t* aDest,
  13. int32_t* aDestLength)
  14. {
  15. if (mSeenByte || !(*aSrcLength)) {
  16. *aDestLength = 0;
  17. return NS_PARTIAL_MORE_INPUT;
  18. }
  19. if (mErrBehavior == kOnError_Signal) {
  20. mSeenByte = true;
  21. *aSrcLength = 0;
  22. *aDestLength = 0;
  23. return NS_ERROR_ILLEGAL_INPUT;
  24. }
  25. if (!(*aDestLength)) {
  26. *aSrcLength = -1;
  27. return NS_PARTIAL_MORE_OUTPUT;
  28. }
  29. mSeenByte = true;
  30. *aDest = 0xFFFD;
  31. *aDestLength = 1;
  32. return NS_PARTIAL_MORE_INPUT;
  33. }
  34. NS_IMETHODIMP
  35. nsReplacementToUnicode::GetMaxLength(const char* aSrc,
  36. int32_t aSrcLength,
  37. int32_t* aDestLength)
  38. {
  39. if (!mSeenByte && aSrcLength > 0) {
  40. *aDestLength = 1;
  41. } else {
  42. *aDestLength = 0;
  43. }
  44. return NS_EXACT_LENGTH;
  45. }
  46. NS_IMETHODIMP
  47. nsReplacementToUnicode::Reset()
  48. {
  49. mSeenByte = false;
  50. return NS_OK;
  51. }