Bug 1431441 - Part 6 - Start middleman WebReplay process sandbox later r=Alex_Gaynor
[gecko.git] / xpcom / io / nsLinebreakConverter.h
bloba1678ef2d1475f7b9e8b693da726d2d83c2e9100
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef nsLinebreakConverter_h_
8 #define nsLinebreakConverter_h_
10 #include "nscore.h"
11 #include "nsString.h"
13 // utility class for converting between different line breaks.
15 class nsLinebreakConverter
17 public:
19 // Note: enum must match char* array in GetLinebreakString
20 typedef enum {
21 eLinebreakAny, // any kind of linebreak (i.e. "don't care" source)
23 eLinebreakPlatform, // platform linebreak
24 eLinebreakContent, // Content model linebreak (LF)
25 eLinebreakNet, // Form submission linebreak (CRLF)
27 eLinebreakMac, // CR
28 eLinebreakUnix, // LF
29 eLinebreakWindows, // CRLF
31 eLinebreakSpace // space characters. Only valid as destination type
33 } ELinebreakType;
35 enum {
36 kIgnoreLen = -1
39 /* ConvertLineBreaks
40 * Convert line breaks in the supplied string, allocating and returning
41 * a new buffer. Returns nullptr on failure.
42 * @param aSrc: the source string. if aSrcLen == kIgnoreLen this string is assumed
43 * to be null terminated, otherwise it must be at least aSrcLen long.
44 * @param aSrcBreaks: the line breaks in the source. If unknown, pass eLinebreakAny.
45 * If known, pass the known value, as this may be more efficient.
46 * @param aDestBreaks: the line breaks you want in the output.
47 * @param aSrcLen: length of the source. If -1, the source is assumed to be a null-
48 * terminated string.
49 * @param aOutLen: used to return character length of returned buffer, if not null.
51 static char* ConvertLineBreaks(const char* aSrc,
52 ELinebreakType aSrcBreaks, ELinebreakType aDestBreaks,
53 int32_t aSrcLen = kIgnoreLen, int32_t* aOutLen = nullptr);
56 /* ConvertUnicharLineBreaks
57 * Convert line breaks in the supplied string, allocating and returning
58 * a new buffer. Returns nullptr on failure.
59 * @param aSrc: the source string. if aSrcLen == kIgnoreLen this string is assumed
60 * to be null terminated, otherwise it must be at least aSrcLen long.
61 * @param aSrcBreaks: the line breaks in the source. If unknown, pass eLinebreakAny.
62 * If known, pass the known value, as this may be more efficient.
63 * @param aDestBreaks: the line breaks you want in the output.
64 * @param aSrcLen: length of the source, in characters. If -1, the source is assumed to be a null-
65 * terminated string.
66 * @param aOutLen: used to return character length of returned buffer, if not null.
68 static char16_t* ConvertUnicharLineBreaks(const char16_t* aSrc,
69 ELinebreakType aSrcBreaks, ELinebreakType aDestBreaks,
70 int32_t aSrcLen = kIgnoreLen, int32_t* aOutLen = nullptr);
73 /* ConvertStringLineBreaks
74 * Convert line breaks in the supplied string, changing the string buffer (i.e. in-place conversion)
75 * @param ioString: the string to be converted.
76 * @param aSrcBreaks: the line breaks in the source. If unknown, pass eLinebreakAny.
77 * If known, pass the known value, as this may be more efficient.
78 * @param aDestBreaks: the line breaks you want in the output.
79 * @param aSrcLen: length of the source, in characters. If -1, the source is assumed to be a null-
80 * terminated string.
82 static nsresult ConvertStringLineBreaks(nsString& aIoString,
83 ELinebreakType aSrcBreaks,
84 ELinebreakType aDestBreaks);
87 /* ConvertLineBreaksInSitu
88 * Convert line breaks in place if possible. NOTE: THIS MAY REALLOCATE THE BUFFER,
89 * BUT IT WON'T FREE THE OLD BUFFER (because it doesn't know how). So be prepared
90 * to keep a copy of the old pointer, and free it if this passes back a new pointer.
91 * ALSO NOTE: DON'T PASS A STATIC STRING POINTER TO THIS FUNCTION.
93 * @param ioBuffer: the source buffer. if aSrcLen == kIgnoreLen this string is assumed
94 * to be null terminated, otherwise it must be at least aSrcLen long.
95 * @param aSrcBreaks: the line breaks in the source. If unknown, pass eLinebreakAny.
96 * If known, pass the known value, as this may be more efficient.
97 * @param aDestBreaks: the line breaks you want in the output.
98 * @param aSrcLen: length of the source. If -1, the source is assumed to be a null-
99 * terminated string.
100 * @param aOutLen: used to return character length of returned buffer, if not null.
102 static nsresult ConvertLineBreaksInSitu(char** aIoBuffer,
103 ELinebreakType aSrcBreaks,
104 ELinebreakType aDestBreaks,
105 int32_t aSrcLen = kIgnoreLen,
106 int32_t* aOutLen = nullptr);
109 /* ConvertUnicharLineBreaksInSitu
110 * Convert line breaks in place if possible. NOTE: THIS MAY REALLOCATE THE BUFFER,
111 * BUT IT WON'T FREE THE OLD BUFFER (because it doesn't know how). So be prepared
112 * to keep a copy of the old pointer, and free it if this passes back a new pointer.
114 * @param ioBuffer: the source buffer. if aSrcLen == kIgnoreLen this string is assumed
115 * to be null terminated, otherwise it must be at least aSrcLen long.
116 * @param aSrcBreaks: the line breaks in the source. If unknown, pass eLinebreakAny.
117 * If known, pass the known value, as this may be more efficient.
118 * @param aDestBreaks: the line breaks you want in the output.
119 * @param aSrcLen: length of the source in characters. If -1, the source is assumed to be a null-
120 * terminated string.
121 * @param aOutLen: used to return character length of returned buffer, if not null.
123 static nsresult ConvertUnicharLineBreaksInSitu(char16_t** aIoBuffer,
124 ELinebreakType aSrcBreaks,
125 ELinebreakType aDestBreaks,
126 int32_t aSrcLen = kIgnoreLen,
127 int32_t* aOutLen = nullptr);
131 #endif // nsLinebreakConverter_h_