michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- michael@0: * michael@0: * This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef nsPrimitiveHelpers_h___ michael@0: #define nsPrimitiveHelpers_h___ michael@0: michael@0: #include "nsError.h" michael@0: #include "nscore.h" michael@0: michael@0: class nsISupports; michael@0: michael@0: michael@0: class nsPrimitiveHelpers michael@0: { michael@0: public: michael@0: michael@0: // Given some data and the flavor it corresponds to, creates the appropriate michael@0: // nsISupports* wrapper for passing across IDL boundaries. The length parameter michael@0: // should not include the null if the data is null terminated. michael@0: static void CreatePrimitiveForData ( const char* aFlavor, const void* aDataBuff, michael@0: uint32_t aDataLen, nsISupports** aPrimitive ) ; michael@0: michael@0: // Given a nsISupports* primitive and the flavor it represents, creates a new data michael@0: // buffer with the data in it. This data will be null terminated, but the length michael@0: // parameter does not reflect that. michael@0: static void CreateDataFromPrimitive ( const char* aFlavor, nsISupports* aPrimitive, michael@0: void** aDataBuff, uint32_t aDataLen ) ; michael@0: michael@0: // Given a unicode buffer (flavor text/unicode), this converts it to plain text using michael@0: // the appropriate platform charset encoding. |inUnicodeLen| is the length of the input michael@0: // string, not the # of bytes in the buffer. |outPlainTextData| is null terminated, michael@0: // but its length parameter, |outPlainTextLen|, does not reflect that. michael@0: static nsresult ConvertUnicodeToPlatformPlainText ( char16_t* inUnicode, int32_t inUnicodeLen, michael@0: char** outPlainTextData, int32_t* outPlainTextLen ) ; michael@0: michael@0: // Given a char buffer (flavor text/plaikn), this converts it to unicode using michael@0: // the appropriate platform charset encoding. |outUnicode| is null terminated, michael@0: // but its length parameter, |outUnicodeLen|, does not reflect that. |outUnicodeLen| is michael@0: // the length of the string in characters, not bytes. michael@0: static nsresult ConvertPlatformPlainTextToUnicode ( const char* inText, int32_t inTextLen, michael@0: char16_t** outUnicode, int32_t* outUnicodeLen ) ; michael@0: michael@0: }; // class nsPrimitiveHelpers michael@0: michael@0: michael@0: michael@0: class nsLinebreakHelpers michael@0: { michael@0: public: michael@0: michael@0: // Given some data, convert from the platform linebreaks into the LF expected by the michael@0: // DOM. This will attempt to convert the data in place, but the buffer may still need to michael@0: // be reallocated regardless (disposing the old buffer is taken care of internally, see michael@0: // the note below). michael@0: // michael@0: // NOTE: this assumes that it can use nsMemory to dispose of the old buffer. michael@0: static nsresult ConvertPlatformToDOMLinebreaks ( const char* inFlavor, void** ioData, int32_t* ioLengthInBytes ) ; michael@0: michael@0: }; // class nsLinebreakHelpers michael@0: michael@0: michael@0: #endif // nsPrimitiveHelpers_h___