Opera 12.15 Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

stdlib_pi.h 3.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /* -*- Mode: c++; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*-
  2. **
  3. ** Copyright (C) 2006-2007 Opera Software ASA. All rights reserved.
  4. **
  5. ** This file is part of the Opera web browser. It may not be distributed
  6. ** under any circumstances.
  7. */
  8. #ifndef STDLIB_PI_H
  9. #define STDLIB_PI_H
  10. #ifndef STDLIB_DTOA_CONVERSION
  11. /**
  12. * Porting interfaces for stdlib's fallback number formatters for platforms
  13. * that can't use the thirdparty strtod/dtoa library.
  14. *
  15. * These APIs need to be folded into Opera's regular PI at some point, but
  16. * at least this way they are visible.
  17. *
  18. * For all of these the rules are:
  19. *
  20. * - The ONLY valid decimal point is '.'. Formatters must never
  21. * produce, and scanners must never scan, any other form of decimal
  22. * point. This usually means that if you're using system functions
  23. * to do your dirty work you must force the LC_NUMERIC locale to "C"
  24. * in your implementations.
  25. *
  26. * - The ONLY valid exponent markers are 'e' and 'E'. Formatters
  27. * must never produce other markers than these, and scanners must
  28. * understand both upper and lower case and not scan other markers.
  29. *
  30. * There is some overlap of functionality among some of the functions, in
  31. * order to allow platforms to choose the best set of functions.
  32. *
  33. * None of these functions should be called except from within stdlib. Most
  34. * clients (including most clients inside stdlib!) should call op_ functions
  35. * instead.
  36. *
  37. * The file stdlib_pi.cpp contains some implementation sketches and notes
  38. * that can be used by platforms to construct suitable implementations.
  39. */
  40. class StdlibPI
  41. {
  42. public:
  43. #ifndef HAVE_STRTOD
  44. /**
  45. * Read a double-precision floating point number.
  46. *
  47. * \param p The input string
  48. * \param endp Location that receives a pointer to the first
  49. * location not consumed
  50. * \return The number read.
  51. */
  52. static double StringToDouble(const char* p, char** endp);
  53. #endif // !HAVE_STRTOD
  54. /**
  55. * Format a double according to a printf %f, %g, or %e specification, with
  56. * no field width but with an optional precision specifier.
  57. *
  58. * This function should normally never be called except from within
  59. * stdlib. Most clients should use the OpDoubleFormat interface instead.
  60. *
  61. * \param buffer The output buffer
  62. * \param bufsiz The size of that buffer (including space for the NUL)
  63. * \param fmt The format string
  64. * \param d The number to format
  65. */
  66. static void SPrintfDouble(char* buffer, int bufsiz, const char* fmt, double d);
  67. /**
  68. * Format a double-precision number as with the quasi-standard dtoa(). This function
  69. * may be a no-op.
  70. *
  71. * Returns TRUE if it did anything.
  72. */
  73. static BOOL LocaleSafeDTOA( double d, char* b, int precision=-1 );
  74. /**
  75. * Format a double-precision number as with the quasi-standard etoa(). This function
  76. * may be a no-op.
  77. *
  78. * Returns TRUE if it did anything.
  79. */
  80. static BOOL LocaleSafeETOA( double d, char* b, int precision );
  81. };
  82. #endif // !STDLIB_DTOA_CONVERSION
  83. #endif // STDLIB_PI_H