auto
  @   !ˆl–Ãa¾”Êj"TŒ‚ã`S�ÿ�þD&åY²I#q¸Z+ÀþÓƒy×ßÒ_ˆI|¥�+y,ÀÑ "_    !/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
 * vim: set ts=8 sts=2 et sw=2 tw=80:
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

/* Printf-like functions, with canned variants that malloc their result.  */

#ifndef mozilla_Printf_h
#define mozilla_Printf_h

/*
** API for PR printf like routines.
**
** These exist partly for historical reasons -- initially they were in
** NSPR, then forked in tree and modified in js/ -- but now the prime
** motivation is both closer control over the exact formatting (with
** one exception, see below) and also the ability to control where
** exactly the generated results are sent.
**
** It might seem that this could all be dispensed with in favor of a
** wrapper around |vsnprintf| -- except that this implementation
** guarantees that the %s format will accept a NULL pointer, whereas
** with standard functions this is undefined.
**
** This supports the following formats.  It implements a subset of the
** standard formats; due to the use of MOZ_FORMAT_PRINTF, it is not
** permissible to extend the standard, aside from relaxing undefined
** behavior.
**
**      %d - decimal
**      %u - unsigned decimal
**      %x - unsigned hex
**      %X - unsigned uppercase hex
**      %o - unsigned octal
**      %hd, %hu, %hx, %hX, %ho - "short" versions of above
**      %ld, %lu, %lx, %lX, %lo - "long" versions of above
**      %lld, %llu, %llx, %llX, %llo - "long long" versions of above
**      %zd, %zo, %zu, %zx, %zX - size_t versions of above
**      %Id, %Io, %Iu, %Ix, %IX - size_t versions of above (for Windows compat).
**           Note that MSVC 2015 and newer supports the z length modifier so
**           users should prefer using %z instead of %I. We are supporting %I in
**           addition to %z in case third-party code that uses %I gets routed to
**           use this printf implementation.
**      %s - string
**      %S, %ls - wide string, that is wchar_t*
**      %c - character
**      %p - pointer (deals with machine dependent pointer size)
**      %f - float; note that this is actually formatted using the
**           system's native printf, and so the results may vary
**      %g - float; note that this is actually formatted using the
**           system's native printf, and so the results may vary
*/

#include "mozilla/AllocPolicy.h"
#include "mozilla/Assertions.h"
#include "mozilla/Attributes.h"
#include "mozilla/IntegerPrintfMacros.h"
#include "mozilla/Types.h"
#include "mozilla/UniquePtr.h"

#include <stdarg.h>
#include <string.h>

namespace mozilla {

/*
 * This class may be subclassed to provide a way to get the output of
 * a printf-like call, as the output is generated.
 */
class PrintfTarget {
 public:
  /* The Printf-like interface.  */
  bool MFBT_API print(const char* format, ...) MOZ_FORMAT_PRINTF(2, 3);

  /* The Vprintf-like interface.  */
  bool MFBT_API vprint(const char* format, va_list) MOZ_FORMAT_PRINTF(2, 0);

  /* Fast paths for formatting integers as though by %d, %o, %u, or %x.
     Since octal and hex formatting always treat numbers as unsigned, there
     are no signed overloads for AppendInt{Oct,Hex}.  */
  bool MFBT_API appendIntDec(int32_t);
  bool MFBT_API appendIntDec(uint32_t);
  bool MFBT_API appendIntOct(uint32_t);
  bool MFBT_API appendIntHex(uint32_t);
  bool MFBT_API appendIntDec(int64_t);
  bool MFBT_API appendIntDec(uint64_t);
  bool MFBT_API appendIntOct(uint64_t);
  bool MFBT_API appendIntHex(uint64_t);

 protected:
  MFBT_API PrintfTarget();
  virtual ~PrintfTarget() = default;

  /* Subclasses override this.  It is called when more output is
     available.  It may be called with len==0.  This should return
     true on success, or false on failure.  */
  virtual bool append(const char* sp, size_t len) = 0;

 private:
  /* Number of bytes emitted so far.  */
  size_t mEmi