VirtualBox

source: vbox/trunk/src/libs/xpcom18a4/xpcom/io/nsLinebreakConverter.h@ 44770

最後變更 在這個檔案從44770是 1,由 vboxsync 提交於 55 年 前

import

  • 屬性 svn:eol-style 設為 native
  • 屬性 svn:keywords 設為 Author Date Id Revision
檔案大小: 7.3 KB
 
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
4 *
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/
9 *
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.
14 *
15 * The Original Code is mozilla.org code.
16 *
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.
21 *
22 * Contributor(s):
23 *
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.
35 *
36 * ***** END LICENSE BLOCK ***** */
37
38#ifndef nsLinebreakConverter_h_
39#define nsLinebreakConverter_h_
40
41
42#include "nscore.h"
43#include "nsString.h"
44
45// utility class for converting between different line breaks.
46
47class NS_COM nsLinebreakConverter
48{
49public:
50
51 // Note: enum must match char* array in GetLinebreakString
52 typedef enum {
53 eLinebreakAny, // any kind of linebreak (i.e. "don't care" source)
54
55 eLinebreakPlatform, // platform linebreak
56 eLinebreakContent, // Content model linebreak (LF)
57 eLinebreakNet, // Form submission linebreak (CRLF)
58
59 eLinebreakMac, // CR
60 eLinebreakUnix, // LF
61 eLinebreakWindows // CRLF
62
63 } ELinebreakType;
64
65 enum {
66 kIgnoreLen = -1
67 };
68
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.
80 */
81 static char* ConvertLineBreaks(const char* aSrc,
82 ELinebreakType aSrcBreaks, ELinebreakType aDestBreaks,
83 PRInt32 aSrcLen = kIgnoreLen, PRInt32* aOutLen = nsnull);
84
85
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.
97 */
98 static PRUnichar* ConvertUnicharLineBreaks(const PRUnichar* aSrc,
99 ELinebreakType aSrcBreaks, ELinebreakType aDestBreaks,
100 PRInt32 aSrcLen = kIgnoreLen, PRInt32* aOutLen = nsnull);
101
102
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.
111 */
112 static nsresult ConvertStringLineBreaks(nsString& ioString, ELinebreakType aSrcBreaks, ELinebreakType aDestBreaks);
113
114
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.
120 *
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.
129 */
130 static nsresult ConvertLineBreaksInSitu(char **ioBuffer, ELinebreakType aSrcBreaks, ELinebreakType aDestBreaks,
131 PRInt32 aSrcLen = kIgnoreLen, PRInt32* aOutLen = nsnull);
132
133
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.
138 *
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.
147 */
148 static nsresult ConvertUnicharLineBreaksInSitu(PRUnichar **ioBuffer, ELinebreakType aSrcBreaks, ELinebreakType aDestBreaks,
149 PRInt32 aSrcLen = kIgnoreLen, PRInt32* aOutLen = nsnull);
150
151};
152
153
154
155
156#endif // nsLinebreakConverter_h_
注意: 瀏覽 TracBrowser 來幫助您使用儲存庫瀏覽器

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette