xpcom/io/nsLinebreakConverter.h

Tue, 06 Jan 2015 21:39:09 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Tue, 06 Jan 2015 21:39:09 +0100
branch
TOR_BUG_9701
changeset 8
97036ab72558
permissions
-rw-r--r--

Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.

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

mercurial