1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /* vim:expandtab:shiftwidth=4:tabstop=4:
3 */
4 /* ***** BEGIN LICENSE BLOCK *****
5 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
6 *
7 * The contents of this file are subject to the Mozilla Public License Version
8 * 1.1 (the "License"); you may not use this file except in compliance with
9 * the License. You may obtain a copy of the License at
10 * http://www.mozilla.org/MPL/
11 *
12 * Software distributed under the License is distributed on an "AS IS" basis,
13 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
14 * for the specific language governing rights and limitations under the
15 * License.
16 *
17 * The Original Code is mozilla.org code.
18 *
19 * The Initial Developer of the Original Code is
20 * Jungshik Shin <jshin@mailaps.org>.
21 * Portions created by the Initial Developer are Copyright (C) 2002
22 * the Initial Developer. All Rights Reserved.
23 *
24 * Contributor(s:
25 * Naoki Hotta <nhotta@netscape.com>
26 *
27 * Alternatively, the contents of this file may be used under the terms of
28 * either the GNU General Public License Version 2 or later (the "GPL"), or
29 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
30 * in which case the provisions of the GPL or the LGPL are applicable instead
31 * of those above. If you wish to allow use of your version of this file only
32 * under the terms of either the GPL or the LGPL, and not to allow others to
33 * use your version of this file under the terms of the MPL, indicate your
34 * decision by deleting the provisions above and replace them with the notice
35 * and other provisions required by the GPL or the LGPL. If you do not delete
36 * the provisions above, a recipient may use your version of this file under
37 * the terms of any one of the MPL, the GPL or the LGPL.
38 *
39 * ***** END LICENSE BLOCK ***** */
40
41 #include "nsISupports.idl"
42
43 [scriptable, uuid(249f52a3-2599-4b00-ba40-0481364831a2)]
44 interface nsIUTF8ConverterService : nsISupports
45 {
46 /**
47 * Ensure that |aString| is encoded in UTF-8. If not,
48 * convert to UTF-8 assuming it's encoded in |aCharset|
49 * and return the converted string in UTF-8.
50 *
51 * @param aString a string to ensure its UTF8ness
52 * @param aCharset the charset to convert from if |aString| is not in UTF-8
53 * @param aSkipCheck determines whether or not to skip 'ASCIIness' and
54 * 'UTF8ness' check. Set this to PR_TRUE only if you suspect that
55 * aString can be mistaken for ASCII / UTF-8 but is actually NOT
56 * in ASCII / UTF-8 so that aString has to go through the conversion.
57 * skipping ASCIIness/UTF8ness check.
58 * The most common case is the input is in 7bit non-ASCII charsets
59 * like ISO-2022-JP, HZ or UTF-7 (in its original form or
60 * a modified form used in IMAP folder names).
61 * @return the converted string in UTF-8.
62 * @throws NS_ERROR_UCONV_NOCONV when there is no decoder for aCharset
63 * or error code of nsIUnicodeDecoder in case of conversion failure
64 */
65
66 AUTF8String convertStringToUTF8(in ACString aString,
67 in string aCharset,
68 in boolean aSkipCheck);
69
70 /* XXX : To-be-added. convertStringFromUTF8 */
71
72 /**
73 * Ensure that |aSpec| (after URL-unescaping it) is encoded in UTF-8.
74 * If not, convert it to UTF-8, assuming it's encoded in |aCharset|,
75 * and return the result.
76 *
77 * <p>Make sure that all characters outside US-ASCII in your input spec
78 * are url-escaped if your spec is not in UTF-8 (before url-escaping)
79 * because the presence of non-ASCII characters is <strong>blindly</strong>
80 * regarded as an indication that your input spec is in unescaped UTF-8
81 * and it will be returned without further processing. No valid spec
82 * going around in Mozilla code would break this assumption.
83 *
84 * <p>XXX The above may change in the future depending on the usage pattern.
85 *
86 * @param aSpec an url-escaped URI spec to ensure its UTF8ness
87 * @param aCharset the charset to convert from if |aSpec| is not in UTF-8
88 * @return the converted spec in UTF-8.
89 * @throws NS_ERROR_UCONV_NOCONV when there is no decoder for aCharset
90 * or error code of nsIUnicodeDecoder in case of conversion failure
91 */
92
93 AUTF8String convertURISpecToUTF8(in ACString aSpec,
94 in string aCharset);
95 };