Bug 452317 - FeedConverter.js: QueryInterface should throw NS_ERROR_NO_INTERFACE...
[wine-gecko.git] / xpcom / io / nsLinebreakConverter.h
blobec4bce57e2b80945c9ad1efa317674a8312c733a
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
13 * License.
15 * The Original Code is mozilla.org code.
17 * The Initial Developer of the Original Code is
18 * Netscape Communications Corporation.
19 * Portions created by the Initial Developer are Copyright (C) 1998
20 * the Initial Developer. All Rights Reserved.
22 * Contributor(s):
24 * Alternatively, the contents of this file may be used under the terms of
25 * either of the GNU General Public License Version 2 or later (the "GPL"),
26 * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27 * in which case the provisions of the GPL or the LGPL are applicable instead
28 * of those above. If you wish to allow use of your version of this file only
29 * under the terms of either the GPL or the LGPL, and not to allow others to
30 * use your version of this file under the terms of the MPL, indicate your
31 * decision by deleting the provisions above and replace them with the notice
32 * and other provisions required by the GPL or the LGPL. If you do not delete
33 * the provisions above, a recipient may use your version of this file under
34 * the terms of any one of the MPL, the GPL or the LGPL.
36 * ***** END LICENSE BLOCK ***** */
38 #ifndef nsLinebreakConverter_h_
39 #define nsLinebreakConverter_h_
42 #include "nscore.h"
43 #include "nsString.h"
45 // utility class for converting between different line breaks.
47 class NS_COM nsLinebreakConverter
49 public:
51 // Note: enum must match char* array in GetLinebreakString
52 typedef enum {
53 eLinebreakAny, // any kind of linebreak (i.e. "don't care" source)
55 eLinebreakPlatform, // platform linebreak
56 eLinebreakContent, // Content model linebreak (LF)
57 eLinebreakNet, // Form submission linebreak (CRLF)
59 eLinebreakMac, // CR
60 eLinebreakUnix, // LF
61 eLinebreakWindows // CRLF
63 } ELinebreakType;
65 enum {
66 kIgnoreLen = -1
69 /* ConvertLineBreaks
70 * Convert line breaks in the supplied string, allocating and returning
71 * a new buffer. Returns nsnull on failure.
72 * @param aSrc: the source string. if aSrcLen == kIgnoreLen this string is assumed
73 * to be null terminated, otherwise it must be at least aSrcLen long.
74 * @param aSrcBreaks: the line breaks in the source. If unknown, pass eLinebreakAny.
75 * If known, pass the known value, as this may be more efficient.
76 * @param aDestBreaks: the line breaks you want in the output.
77 * @param aSrcLen: length of the source. If -1, the source is assumed to be a null-
78 * terminated string.
79 * @param aOutLen: used to return character length of returned buffer, if not null.
81 static char* ConvertLineBreaks(const char* aSrc,
82 ELinebreakType aSrcBreaks, ELinebreakType aDestBreaks,
83 PRInt32 aSrcLen = kIgnoreLen, PRInt32* aOutLen = nsnull);
86 /* ConvertUnicharLineBreaks
87 * Convert line breaks in the supplied string, allocating and returning
88 * a new buffer. Returns nsnull on failure.
89 * @param aSrc: the source string. if aSrcLen == kIgnoreLen this string is assumed
90 * to be null terminated, otherwise it must be at least aSrcLen long.
91 * @param aSrcBreaks: the line breaks in the source. If unknown, pass eLinebreakAny.
92 * If known, pass the known value, as this may be more efficient.
93 * @param aDestBreaks: the line breaks you want in the output.
94 * @param aSrcLen: length of the source, in characters. If -1, the source is assumed to be a null-
95 * terminated string.
96 * @param aOutLen: used to return character length of returned buffer, if not null.
98 static PRUnichar* ConvertUnicharLineBreaks(const PRUnichar* aSrc,
99 ELinebreakType aSrcBreaks, ELinebreakType aDestBreaks,
100 PRInt32 aSrcLen = kIgnoreLen, PRInt32* aOutLen = nsnull);
103 /* ConvertStringLineBreaks
104 * Convert line breaks in the supplied string, changing the string buffer (i.e. in-place conversion)
105 * @param ioString: the string to be converted.
106 * @param aSrcBreaks: the line breaks in the source. If unknown, pass eLinebreakAny.
107 * If known, pass the known value, as this may be more efficient.
108 * @param aDestBreaks: the line breaks you want in the output.
109 * @param aSrcLen: length of the source, in characters. If -1, the source is assumed to be a null-
110 * terminated string.
112 static nsresult ConvertStringLineBreaks(nsString& ioString, ELinebreakType aSrcBreaks, ELinebreakType aDestBreaks);
115 /* ConvertLineBreaksInSitu
116 * Convert line breaks in place if possible. NOTE: THIS MAY REALLOCATE THE BUFFER,
117 * BUT IT WON'T FREE THE OLD BUFFER (because it doesn't know how). So be prepared
118 * to keep a copy of the old pointer, and free it if this passes back a new pointer.
119 * ALSO NOTE: DON'T PASS A STATIC STRING POINTER TO THIS FUNCTION.
121 * @param ioBuffer: the source buffer. if aSrcLen == kIgnoreLen this string is assumed
122 * to be null terminated, otherwise it must be at least aSrcLen long.
123 * @param aSrcBreaks: the line breaks in the source. If unknown, pass eLinebreakAny.
124 * If known, pass the known value, as this may be more efficient.
125 * @param aDestBreaks: the line breaks you want in the output.
126 * @param aSrcLen: length of the source. If -1, the source is assumed to be a null-
127 * terminated string.
128 * @param aOutLen: used to return character length of returned buffer, if not null.
130 static nsresult ConvertLineBreaksInSitu(char **ioBuffer, ELinebreakType aSrcBreaks, ELinebreakType aDestBreaks,
131 PRInt32 aSrcLen = kIgnoreLen, PRInt32* aOutLen = nsnull);
134 /* ConvertUnicharLineBreaksInSitu
135 * Convert line breaks in place if possible. NOTE: THIS MAY REALLOCATE THE BUFFER,
136 * BUT IT WON'T FREE THE OLD BUFFER (because it doesn't know how). So be prepared
137 * to keep a copy of the old pointer, and free it if this passes back a new pointer.
139 * @param ioBuffer: the source buffer. if aSrcLen == kIgnoreLen this string is assumed
140 * to be null terminated, otherwise it must be at least aSrcLen long.
141 * @param aSrcBreaks: the line breaks in the source. If unknown, pass eLinebreakAny.
142 * If known, pass the known value, as this may be more efficient.
143 * @param aDestBreaks: the line breaks you want in the output.
144 * @param aSrcLen: length of the source in characters. If -1, the source is assumed to be a null-
145 * terminated string.
146 * @param aOutLen: used to return character length of returned buffer, if not null.
148 static nsresult ConvertUnicharLineBreaksInSitu(PRUnichar **ioBuffer, ELinebreakType aSrcBreaks, ELinebreakType aDestBreaks,
149 PRInt32 aSrcLen = kIgnoreLen, PRInt32* aOutLen = nsnull);
156 #endif // nsLinebreakConverter_h_