зеркало из https://github.com/mozilla/pjs.git
support macro for: if fixed length conversion buffer too short malloc
This commit is contained in:
Родитель
12512aa7fa
Коммит
5f7b854f33
|
@ -71,6 +71,41 @@ public:
|
|||
NS_IMETHOD Convert(PRUnichar aChar, char * aDest, PRInt32 * aDestLength) = 0;
|
||||
};
|
||||
|
||||
//
|
||||
// Malloc an Encoder (unicode -> charset) buffer if the
|
||||
// result won't fit in the static buffer
|
||||
//
|
||||
// p = the buffer pointer (char*)
|
||||
// e = encoder (nsIUnicodeEncoder*)
|
||||
// s = string (PRUnichar*)
|
||||
// l = string length (PRInt32)
|
||||
// sb = static buffer (char[])
|
||||
// sbl = static buffer length (PRUint32)
|
||||
// al = actual buffer length (PRInt32)
|
||||
//
|
||||
#define ENCODER_BUFFER_ALLOC_IF_NEEDED(p,e,s,l,sb,sbl,al) \
|
||||
PR_BEGIN_MACRO \
|
||||
nsresult rv = (e)->GetMaxLength((s), (l), &(al)); \
|
||||
if (NS_SUCCEEDED(rv) \
|
||||
&& ((al) > (PRInt32)(sbl)) \
|
||||
&& (nsnull!=((p)=(char*)nsMemory::Alloc((al)+1))) \
|
||||
) { \
|
||||
} \
|
||||
else { \
|
||||
(p) = (char*)(sb); \
|
||||
(al) = (sbl); \
|
||||
} \
|
||||
PR_END_MACRO
|
||||
|
||||
//
|
||||
// Free the Encoder buffer if it was allocated
|
||||
//
|
||||
#define ENCODER_BUFFER_FREE_IF_NEEDED(p,sb) \
|
||||
PR_BEGIN_MACRO \
|
||||
if ((p) != (char*)(sb)) \
|
||||
nsMemory::Free(p); \
|
||||
PR_END_MACRO
|
||||
|
||||
/**
|
||||
* Interface for a Converter from Unicode into a Charset.
|
||||
*
|
||||
|
|
Загрузка…
Ссылка в новой задаче