michael@0: /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 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: /* michael@0: * This code was copied from xpcom/ds/nsTextFormatter r1.3 michael@0: * Memory model and Frozen linkage changes only. michael@0: * -- Prasad michael@0: */ michael@0: michael@0: #ifndef nsTextFormatter_h___ michael@0: #define nsTextFormatter_h___ michael@0: michael@0: /* michael@0: ** API for PR printf like routines. Supports the following formats michael@0: ** %d - decimal michael@0: ** %u - unsigned decimal michael@0: ** %x - unsigned hex michael@0: ** %X - unsigned uppercase hex michael@0: ** %o - unsigned octal michael@0: ** %hd, %hu, %hx, %hX, %ho - 16-bit versions of above michael@0: ** %ld, %lu, %lx, %lX, %lo - 32-bit versions of above michael@0: ** %lld, %llu, %llx, %llX, %llo - 64 bit versions of above michael@0: ** %s - utf8 string michael@0: ** %S - char16_t string michael@0: ** %c - character michael@0: ** %p - pointer (deals with machine dependent pointer size) michael@0: ** %f - float michael@0: ** %g - float michael@0: */ michael@0: #include "prio.h" michael@0: #include michael@0: #include michael@0: #include "nscore.h" michael@0: #include "nsStringGlue.h" michael@0: michael@0: #ifdef XPCOM_GLUE michael@0: #error "nsTextFormatter is not available in the standalone glue due to NSPR dependencies." michael@0: #endif michael@0: michael@0: class NS_COM_GLUE nsTextFormatter { michael@0: michael@0: public: michael@0: michael@0: /* michael@0: * sprintf into a fixed size buffer. Guarantees that the buffer is null michael@0: * terminated. Returns the length of the written output, NOT including the michael@0: * null terminator, or (uint32_t)-1 if an error occurs. michael@0: */ michael@0: static uint32_t snprintf(char16_t *out, uint32_t outlen, const char16_t *fmt, ...); michael@0: michael@0: /* michael@0: * sprintf into a nsMemory::Alloc'd buffer. Return a pointer to michael@0: * buffer on success, nullptr on failure. michael@0: */ michael@0: static char16_t* smprintf(const char16_t *fmt, ...); michael@0: michael@0: static uint32_t ssprintf(nsAString& out, const char16_t* fmt, ...); michael@0: michael@0: /* michael@0: * va_list forms of the above. michael@0: */ michael@0: static uint32_t vsnprintf(char16_t *out, uint32_t outlen, const char16_t *fmt, va_list ap); michael@0: static char16_t* vsmprintf(const char16_t *fmt, va_list ap); michael@0: static uint32_t vssprintf(nsAString& out, const char16_t *fmt, va_list ap); michael@0: michael@0: /* michael@0: * Free the memory allocated, for the caller, by smprintf. michael@0: * -- Deprecated -- michael@0: * Callers can substitute calling smprintf_free with nsMemory::Free michael@0: */ michael@0: static void smprintf_free(char16_t *mem); michael@0: michael@0: }; michael@0: michael@0: #endif /* nsTextFormatter_h___ */