Thu, 15 Jan 2015 21:03:48 +0100
Integrate friendly tips from Tor colleagues to make (or not) 4.5 alpha 3;
This includes removal of overloaded (but unused) methods, and addition of
a overlooked call to DataStruct::SetData(nsISupports, uint32_t, bool.)
michael@0 | 1 | /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- |
michael@0 | 2 | * |
michael@0 | 3 | * This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 4 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 5 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 6 | |
michael@0 | 7 | #ifndef nsPrimitiveHelpers_h___ |
michael@0 | 8 | #define nsPrimitiveHelpers_h___ |
michael@0 | 9 | |
michael@0 | 10 | #include "nsError.h" |
michael@0 | 11 | #include "nscore.h" |
michael@0 | 12 | |
michael@0 | 13 | class nsISupports; |
michael@0 | 14 | |
michael@0 | 15 | |
michael@0 | 16 | class nsPrimitiveHelpers |
michael@0 | 17 | { |
michael@0 | 18 | public: |
michael@0 | 19 | |
michael@0 | 20 | // Given some data and the flavor it corresponds to, creates the appropriate |
michael@0 | 21 | // nsISupports* wrapper for passing across IDL boundaries. The length parameter |
michael@0 | 22 | // should not include the null if the data is null terminated. |
michael@0 | 23 | static void CreatePrimitiveForData ( const char* aFlavor, const void* aDataBuff, |
michael@0 | 24 | uint32_t aDataLen, nsISupports** aPrimitive ) ; |
michael@0 | 25 | |
michael@0 | 26 | // Given a nsISupports* primitive and the flavor it represents, creates a new data |
michael@0 | 27 | // buffer with the data in it. This data will be null terminated, but the length |
michael@0 | 28 | // parameter does not reflect that. |
michael@0 | 29 | static void CreateDataFromPrimitive ( const char* aFlavor, nsISupports* aPrimitive, |
michael@0 | 30 | void** aDataBuff, uint32_t aDataLen ) ; |
michael@0 | 31 | |
michael@0 | 32 | // Given a unicode buffer (flavor text/unicode), this converts it to plain text using |
michael@0 | 33 | // the appropriate platform charset encoding. |inUnicodeLen| is the length of the input |
michael@0 | 34 | // string, not the # of bytes in the buffer. |outPlainTextData| is null terminated, |
michael@0 | 35 | // but its length parameter, |outPlainTextLen|, does not reflect that. |
michael@0 | 36 | static nsresult ConvertUnicodeToPlatformPlainText ( char16_t* inUnicode, int32_t inUnicodeLen, |
michael@0 | 37 | char** outPlainTextData, int32_t* outPlainTextLen ) ; |
michael@0 | 38 | |
michael@0 | 39 | // Given a char buffer (flavor text/plaikn), this converts it to unicode using |
michael@0 | 40 | // the appropriate platform charset encoding. |outUnicode| is null terminated, |
michael@0 | 41 | // but its length parameter, |outUnicodeLen|, does not reflect that. |outUnicodeLen| is |
michael@0 | 42 | // the length of the string in characters, not bytes. |
michael@0 | 43 | static nsresult ConvertPlatformPlainTextToUnicode ( const char* inText, int32_t inTextLen, |
michael@0 | 44 | char16_t** outUnicode, int32_t* outUnicodeLen ) ; |
michael@0 | 45 | |
michael@0 | 46 | }; // class nsPrimitiveHelpers |
michael@0 | 47 | |
michael@0 | 48 | |
michael@0 | 49 | |
michael@0 | 50 | class nsLinebreakHelpers |
michael@0 | 51 | { |
michael@0 | 52 | public: |
michael@0 | 53 | |
michael@0 | 54 | // Given some data, convert from the platform linebreaks into the LF expected by the |
michael@0 | 55 | // DOM. This will attempt to convert the data in place, but the buffer may still need to |
michael@0 | 56 | // be reallocated regardless (disposing the old buffer is taken care of internally, see |
michael@0 | 57 | // the note below). |
michael@0 | 58 | // |
michael@0 | 59 | // NOTE: this assumes that it can use nsMemory to dispose of the old buffer. |
michael@0 | 60 | static nsresult ConvertPlatformToDOMLinebreaks ( const char* inFlavor, void** ioData, int32_t* ioLengthInBytes ) ; |
michael@0 | 61 | |
michael@0 | 62 | }; // class nsLinebreakHelpers |
michael@0 | 63 | |
michael@0 | 64 | |
michael@0 | 65 | #endif // nsPrimitiveHelpers_h___ |