]> Dogcows Code - chaz/yoink/blobdiff - src/stlplus/portability/dprintf.hpp
cleanup stlplus files
[chaz/yoink] / src / stlplus / portability / dprintf.hpp
index f7de78b1bcdbb2439fd72d726854692d804a387f..360e5c10a6b0bc90c8cfbcdedc378eb0cbe31aaf 100644 (file)
-#ifndef STLPLUS_DPRINTF\r
-#define STLPLUS_DPRINTF\r
-////////////////////////////////////////////////////////////////////////////////\r
-\r
-//   Author:    Andy Rushton\r
-//   Copyright: (c) Southampton University 1999-2004\r
-//              (c) Andy Rushton           2004-2009\r
-//   License:   BSD License, see ../docs/license.html\r
-\r
-//   Provides an sprintf-like function acting on STL strings. The 'd' in dprintf\r
-//   stands for "dynamic" in that the string is a dynamic string whereas a char*\r
-//   buffer would be static (in size that is, not static in C terms).\r
-\r
-//   The obvious solution to the problem of in-memory formatted output is to use\r
-//   sprintf(), but this is a potentially dangerous operation since it will quite\r
-//   happily charge off the end of the string it is printing to and thereby\r
-//   corrupt memory. This kind of buffer-overflow vulnerability is the source of\r
-//   most security failures exploited by virus-writers. It means that sprintf\r
-//   should *never* be used and should be made obsolete.\r
-\r
-//   In any case, using arbitrary-sized fixed-length buffers is not part of any\r
-//   quality-orientated design philosophy.\r
-\r
-//   Most operating systems now have a safe version of sprintf, but this is\r
-//   non-standard. The functions in this file are platform-independent interfaces\r
-//   to the underlying safe implementation.\r
-\r
-//   I would like to make this set of functions obsolete too, since I believe the\r
-//   C runtime should be deprecated in favour of C++ runtime which uses dynamic\r
-//   strings and can handle exceptions. However, there is as yet no C++\r
-//   equivalent functionality to some of the string-handling available through\r
-//   the printf-like functions, so it has to stay for now.\r
-\r
-//     int dprintf (std::string& buffer, const char* format, ...);\r
-\r
-//       Formats the message by appending to the std::string buffer according to\r
-//       the formatting codes in the format string. The return int is the number\r
-//       of characters generated by this call, i.e. the increase in the length of\r
-//       the std::string.\r
-\r
-//     int vdprintf (std::string& buffer, const char* format, va_list args);\r
-\r
-//       As above, but using a pre-initialised va_args argument list. Useful for\r
-//       nesting dprintf calls within variable argument functions.\r
-\r
-//     std::string dformat (const char* format, ...);\r
-\r
-//       Similar to dprintf() above, except the result is formatted into a new\r
-//       std::string which is returned by the function. Very useful for inline\r
-//       calls within an iostream expression.\r
-\r
-//       e.g.    cout << "Total: " << dformat("%6i",t) << endl;\r
-\r
-//     std::string vdformat (const char* format, va_list);\r
-  \r
-//       As above, but using a pre-initialised va_args argument list. Useful for nesting\r
-//       dformat calls within variable argument functions.\r
-\r
-//   The format string supports the following format codes as in the C runtime library:\r
-\r
-//     % [ flags ] [ field ] [ . precision ] [ modifier ] [ conversion ]\r
-\r
-//     flags:\r
-//       -    - left justified\r
-//       +    - print sign for +ve numbers\r
-//       ' '  - leading space where + sign would be\r
-//       0    - leading zeros to width of field\r
-//       #    - alternate format\r
-\r
-//     field:\r
-//       a numeric argument specifying the field width - default = 0\r
-//       * means take the next va_arg as the field width - if negative then left justify\r
-\r
-//     precision:\r
-//       a numeric argument the meaning of which depends on the conversion -\r
-//       - %s - max characters from a string - default = strlen()\r
-//       - %e, %f - decimal places to be displayed - default = 6\r
-//       - %g - significant digits to be displayed - default = 6\r
-//       - all integer conversions - minimum digits to display - default = 0\r
-//       * means take the next va_arg as the field width - if negative then left justify\r
-\r
-//     modifier:\r
-//       h    - short or unsigned short\r
-//       l    - long or unsigned long\r
-//       L    - long double\r
-\r
-//     conversions:\r
-//       d, i - short/int/long as decimal\r
-//       u    - short/int/long as unsigned decimal\r
-//       o    - short/int/long as unsigned octal - # adds leading 0\r
-//       x, X - short/int/long as unsigned hexadecimal - # adds leading 0x\r
-//       c    - char\r
-//       s    - char*\r
-//       f    - double/long double as fixed point\r
-//       e, E - double/long double as floating point\r
-//       g, G - double/long double as fixed point/floating point depending on value\r
-//       p    - void* as unsigned hexadecimal\r
-//       %    - literal %\r
-//       n    - int* as recipient of length of formatted string so far\r
-\r
-////////////////////////////////////////////////////////////////////////////////\r
-#include "portability_fixes.hpp"\r
-#include <string>\r
-#include <stdexcept>\r
-#include <stdarg.h>\r
-\r
-namespace stlplus\r
-{\r
-\r
-  // format by appending to a string and return the increase in length\r
-  // if there is an error, return a negative number and leave the string unchanged\r
-  int dprintf (std::string& formatted, const char* format, ...);\r
-  int vdprintf (std::string& formatted, const char* format, va_list args);\r
-\r
-  // format into a new string and return the result\r
-  // if there is an error, throw an exception\r
-  std::string dformat (const char* format, ...) throw(std::invalid_argument);\r
-  std::string vdformat (const char* format, va_list) throw(std::invalid_argument);\r
-\r
-} // end namespace stlplus\r
-\r
-#endif\r
+#ifndef STLPLUS_DPRINTF
+#define STLPLUS_DPRINTF
+////////////////////////////////////////////////////////////////////////////////
+
+//   Author:    Andy Rushton
+//   Copyright: (c) Southampton University 1999-2004
+//              (c) Andy Rushton           2004-2009
+//   License:   BSD License, see ../docs/license.html
+
+//   Provides an sprintf-like function acting on STL strings. The 'd' in dprintf
+//   stands for "dynamic" in that the string is a dynamic string whereas a char*
+//   buffer would be static (in size that is, not static in C terms).
+
+//   The obvious solution to the problem of in-memory formatted output is to use
+//   sprintf(), but this is a potentially dangerous operation since it will quite
+//   happily charge off the end of the string it is printing to and thereby
+//   corrupt memory. This kind of buffer-overflow vulnerability is the source of
+//   most security failures exploited by virus-writers. It means that sprintf
+//   should *never* be used and should be made obsolete.
+
+//   In any case, using arbitrary-sized fixed-length buffers is not part of any
+//   quality-orientated design philosophy.
+
+//   Most operating systems now have a safe version of sprintf, but this is
+//   non-standard. The functions in this file are platform-independent interfaces
+//   to the underlying safe implementation.
+
+//   I would like to make this set of functions obsolete too, since I believe the
+//   C runtime should be deprecated in favour of C++ runtime which uses dynamic
+//   strings and can handle exceptions. However, there is as yet no C++
+//   equivalent functionality to some of the string-handling available through
+//   the printf-like functions, so it has to stay for now.
+
+//     int dprintf (std::string& buffer, const char* format, ...);
+
+//       Formats the message by appending to the std::string buffer according to
+//       the formatting codes in the format string. The return int is the number
+//       of characters generated by this call, i.e. the increase in the length of
+//       the std::string.
+
+//     int vdprintf (std::string& buffer, const char* format, va_list args);
+
+//       As above, but using a pre-initialised va_args argument list. Useful for
+//       nesting dprintf calls within variable argument functions.
+
+//     std::string dformat (const char* format, ...);
+
+//       Similar to dprintf() above, except the result is formatted into a new
+//       std::string which is returned by the function. Very useful for inline
+//       calls within an iostream expression.
+
+//       e.g.    cout << "Total: " << dformat("%6i",t) << endl;
+
+//     std::string vdformat (const char* format, va_list);
+  
+//       As above, but using a pre-initialised va_args argument list. Useful for nesting
+//       dformat calls within variable argument functions.
+
+//   The format string supports the following format codes as in the C runtime library:
+
+//     % [ flags ] [ field ] [ . precision ] [ modifier ] [ conversion ]
+
+//     flags:
+//       -    - left justified
+//       +    - print sign for +ve numbers
+//       ' '  - leading space where + sign would be
+//       0    - leading zeros to width of field
+//       #    - alternate format
+
+//     field:
+//       a numeric argument specifying the field width - default = 0
+//       * means take the next va_arg as the field width - if negative then left justify
+
+//     precision:
+//       a numeric argument the meaning of which depends on the conversion -
+//       - %s - max characters from a string - default = strlen()
+//       - %e, %f - decimal places to be displayed - default = 6
+//       - %g - significant digits to be displayed - default = 6
+//       - all integer conversions - minimum digits to display - default = 0
+//       * means take the next va_arg as the field width - if negative then left justify
+
+//     modifier:
+//       h    - short or unsigned short
+//       l    - long or unsigned long
+//       L    - long double
+
+//     conversions:
+//       d, i - short/int/long as decimal
+//       u    - short/int/long as unsigned decimal
+//       o    - short/int/long as unsigned octal - # adds leading 0
+//       x, X - short/int/long as unsigned hexadecimal - # adds leading 0x
+//       c    - char
+//       s    - char*
+//       f    - double/long double as fixed point
+//       e, E - double/long double as floating point
+//       g, G - double/long double as fixed point/floating point depending on value
+//       p    - void* as unsigned hexadecimal
+//       %    - literal %
+//       n    - int* as recipient of length of formatted string so far
+
+////////////////////////////////////////////////////////////////////////////////
+#include "portability_fixes.hpp"
+#include <string>
+#include <stdexcept>
+#include <stdarg.h>
+
+namespace stlplus
+{
+
+  // format by appending to a string and return the increase in length
+  // if there is an error, return a negative number and leave the string unchanged
+  int dprintf (std::string& formatted, const char* format, ...);
+  int vdprintf (std::string& formatted, const char* format, va_list args);
+
+  // format into a new string and return the result
+  // if there is an error, throw an exception
+  std::string dformat (const char* format, ...) throw(std::invalid_argument);
+  std::string vdformat (const char* format, va_list) throw(std::invalid_argument);
+
+} // end namespace stlplus
+
+#endif
This page took 0.02793 seconds and 4 git commands to generate.