nsIUTF8ConverterService.idl 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
  2. /* vim:expandtab:shiftwidth=4:tabstop=4:
  3. */
  4. /* This Source Code Form is subject to the terms of the Mozilla Public
  5. * License, v. 2.0. If a copy of the MPL was not distributed with this
  6. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  7. #include "nsISupports.idl"
  8. [scriptable, uuid(249f52a3-2599-4b00-ba40-0481364831a2)]
  9. interface nsIUTF8ConverterService : nsISupports
  10. {
  11. /**
  12. * Ensure that |aString| is encoded in UTF-8. If not,
  13. * convert to UTF-8 assuming it's encoded in |aCharset|
  14. * and return the converted string in UTF-8.
  15. *
  16. * @param aString a string to ensure its UTF8ness
  17. * @param aCharset the charset to convert from if |aString| is not in UTF-8
  18. * @param aSkipCheck determines whether or not to skip 'ASCIIness' and
  19. * 'UTF8ness' check. Set this to PR_TRUE only if you suspect that
  20. * aString can be mistaken for ASCII / UTF-8 but is actually NOT
  21. * in ASCII / UTF-8 so that aString has to go through the conversion.
  22. * skipping ASCIIness/UTF8ness check.
  23. * The most common case is the input is in 7bit non-ASCII charsets
  24. * like ISO-2022-JP, HZ or UTF-7 (in its original form or
  25. * a modified form used in IMAP folder names).
  26. * @param aAllowSubstitution when true, allow the decoder to substitute
  27. * invalid input sequences by replacement characters (defaults to
  28. * true)
  29. * @return the converted string in UTF-8.
  30. * @throws NS_ERROR_UCONV_NOCONV when there is no decoder for aCharset
  31. * or error code of nsIUnicodeDecoder in case of conversion failure
  32. */
  33. [optional_argc]
  34. AUTF8String convertStringToUTF8(in ACString aString,
  35. in string aCharset,
  36. in boolean aSkipCheck,
  37. [optional] in boolean aAllowSubstitution);
  38. /* XXX : To-be-added. convertStringFromUTF8 */
  39. /**
  40. * Ensure that |aSpec| (after URL-unescaping it) is encoded in UTF-8.
  41. * If not, convert it to UTF-8, assuming it's encoded in |aCharset|,
  42. * and return the result.
  43. *
  44. * <p>Make sure that all characters outside US-ASCII in your input spec
  45. * are url-escaped if your spec is not in UTF-8 (before url-escaping)
  46. * because the presence of non-ASCII characters is <strong>blindly</strong>
  47. * regarded as an indication that your input spec is in unescaped UTF-8
  48. * and it will be returned without further processing. No valid spec
  49. * going around in Mozilla code would break this assumption.
  50. *
  51. * <p>XXX The above may change in the future depending on the usage pattern.
  52. *
  53. * @param aSpec an url-escaped URI spec to ensure its UTF8ness
  54. * @param aCharset the charset to convert from if |aSpec| is not in UTF-8
  55. * @return the converted spec in UTF-8.
  56. * @throws NS_ERROR_UCONV_NOCONV when there is no decoder for aCharset
  57. * or error code of nsIUnicodeDecoder in case of conversion failure
  58. */
  59. AUTF8String convertURISpecToUTF8(in ACString aSpec,
  60. in string aCharset);
  61. };