1 //
2 // NumberFormatter.h
3 //
4 // Library: Foundation
5 // Package: Core
6 // Module: NumberFormatter
7 //
8 // Definition of the NumberFormatter class.
9 //
10 // Copyright (c) 2004-2008, Applied Informatics Software Engineering GmbH.
11 // and Contributors.
12 //
13 // SPDX-License-Identifier: BSL-1.0
14 //
15
16
17 #ifndef Foundation_NumberFormatter_INCLUDED
18 #define Foundation_NumberFormatter_INCLUDED
19
20
21 #include "Poco/Foundation.h"
22 #include "Poco/NumericString.h"
23
24
25 namespace Poco {
26
27
28 class Foundation_API NumberFormatter
29 /// The NumberFormatter class provides static methods
30 /// for formatting numeric values into strings.
31 ///
32 /// There are two kind of static member functions:
33 /// * format* functions return a std::string containing
34 /// the formatted value.
35 /// * append* functions append the formatted value to
36 /// an existing string.
37 {
38 public:
39 enum BoolFormat
40 {
41 FMT_TRUE_FALSE,
42 FMT_YES_NO,
43 FMT_ON_OFF
44 };
45
46 static const unsigned NF_MAX_INT_STRING_LEN = 32; // increase for 64-bit binary formatting support
47 static const unsigned NF_MAX_FLT_STRING_LEN = POCO_MAX_FLT_STRING_LEN;
48
49 static std::string format(int value);
50 /// Formats an integer value in decimal notation.
51
52 static std::string format(int value, int width);
53 /// Formats an integer value in decimal notation,
54 /// right justified in a field having at least
55 /// the specified width.
56
57 static std::string format0(int value, int width);
58 /// Formats an integer value in decimal notation,
59 /// right justified and zero-padded in a field
60 /// having at least the specified width.
61
62 static std::string formatHex(int value, bool prefix = false);
63 /// Formats an int value in hexadecimal notation.
64 /// If prefix is true, "0x" prefix is prepended to the
65 /// resulting string.
66 /// The value is treated as unsigned.
67
68 static std::string formatHex(int value, int width, bool prefix = false);
69 /// Formats a int value in hexadecimal notation,
70 /// right justified and zero-padded in
71 /// a field having at least the specified width.
72 /// If prefix is true, "0x" prefix is prepended to the
73 /// resulting string.
74 /// The value is treated as unsigned.
75
76 static std::string format(unsigned value);
77 /// Formats an unsigned int value in decimal notation.
78
79 static std::string format(unsigned value, int width);
80 /// Formats an unsigned long int in decimal notation,
81 /// right justified in a field having at least the
82 /// specified width.
83
84 static std::string format0(unsigned int value, int width);
85 /// Formats an unsigned int value in decimal notation,
86 /// right justified and zero-padded in a field having at
87 /// least the specified width.
88
89 static std::string formatHex(unsigned value, bool prefix = false);
90 /// Formats an unsigned int value in hexadecimal notation.
91 /// If prefix is true, "0x" prefix is prepended to the
92 /// resulting string.
93
94 static std::string formatHex(unsigned value, int width, bool prefix = false);
95 /// Formats a int value in hexadecimal notation,
96 /// right justified and zero-padded in
97 /// a field having at least the specified width.
98 /// If prefix is true, "0x" prefix is prepended to the
99 /// resulting string.
100
101 static std::string format(long value);
102 /// Formats a long value in decimal notation.
103
104 static std::string format(long value, int width);
105 /// Formats a long value in decimal notation,
106 /// right justified in a field having at least the
107 /// specified width.
108
109 static std::string format0(long value, int width);
110 /// Formats a long value in decimal notation,
111 /// right justified and zero-padded in a field
112 /// having at least the specified width.
113
114 static std::string formatHex(long value, bool prefix = false);
115 /// Formats an unsigned long value in hexadecimal notation.
116 /// If prefix is true, "0x" prefix is prepended to the
117 /// resulting string.
118 /// The value is treated as unsigned.
119
120 static std::string formatHex(long value, int width, bool prefix = false);
121 /// Formats an unsigned long value in hexadecimal notation,
122 /// right justified and zero-padded in a field having at least the
123 /// specified width.
124 /// If prefix is true, "0x" prefix is prepended to the
125 /// resulting string.
126 /// The value is treated as unsigned.
127
128 static std::string format(unsigned long value);
129 /// Formats an unsigned long value in decimal notation.
130
131 static std::string format(unsigned long value, int width);
132 /// Formats an unsigned long value in decimal notation,
133 /// right justified in a field having at least the specified
134 /// width.
135
136 static std::string format0(unsigned long value, int width);
137 /// Formats an unsigned long value in decimal notation,
138 /// right justified and zero-padded
139 /// in a field having at least the specified width.
140
141 static std::string formatHex(unsigned long value, bool prefix = false);
142 /// Formats an unsigned long value in hexadecimal notation.
143 /// If prefix is true, "0x" prefix is prepended to the
144 /// resulting string.
145
146 static std::string formatHex(unsigned long value, int width, bool prefix = false);
147 /// Formats an unsigned long value in hexadecimal notation,
148 /// right justified and zero-padded in a field having at least the
149 /// specified width.
150 /// If prefix is true, "0x" prefix is prepended to the
151 /// resulting string.
152
153 #ifdef POCO_HAVE_INT64
154 #ifdef POCO_INT64_IS_LONG
155
156 static std::string format(long long value);
157 /// Formats a 64-bit integer value in decimal notation.
158
159 static std::string format(long long value, int width);
160 /// Formats a 64-bit integer value in decimal notation,
161 /// right justified in a field having at least the specified width.
162
163 static std::string format0(long long value, int width);
164 /// Formats a 64-bit integer value in decimal notation,
165 /// right justified and zero-padded in a field having at least
166 /// the specified width.
167
168 static std::string formatHex(long long value, bool prefix = false);
169 /// Formats a 64-bit integer value in hexadecimal notation.
170 /// If prefix is true, "0x" prefix is prepended to the
171 /// resulting string.
172 /// The value is treated as unsigned.
173
174 static std::string formatHex(long long value, int width, bool prefix = false);
175 /// Formats a 64-bit integer value in hexadecimal notation,
176 /// right justified and zero-padded in a field having at least
177 /// the specified width.
178 /// The value is treated as unsigned.
179 /// If prefix is true, "0x" prefix is prepended to the resulting string.
180
181 static std::string format(unsigned long long value);
182 /// Formats an unsigned 64-bit integer value in decimal notation.
183
184 static std::string format(unsigned long long value, int width);
185 /// Formats an unsigned 64-bit integer value in decimal notation,
186 /// right justified in a field having at least the specified width.
187
188 static std::string format0(unsigned long long value, int width);
189 /// Formats an unsigned 64-bit integer value in decimal notation,
190 /// right justified and zero-padded in a field having at least the
191 /// specified width.
192
193 static std::string formatHex(unsigned long long value, bool prefix = false);
194 /// Formats a 64-bit integer value in hexadecimal notation.
195 /// If prefix is true, "0x" prefix is prepended to the
196 /// resulting string.
197
198 static std::string formatHex(unsigned long long value, int width, bool prefix = false);
199 /// Formats a 64-bit integer value in hexadecimal notation,
200 /// right justified and zero-padded in a field having at least
201 /// the specified width. If prefix is true, "0x" prefix is
202 /// prepended to the resulting string.
203
204 #else // ifndef POCO_INT64_IS_LONG
205
206 static std::string format(Int64 value);
207 /// Formats a 64-bit integer value in decimal notation.
208
209 static std::string format(Int64 value, int width);
210 /// Formats a 64-bit integer value in decimal notation,
211 /// right justified in a field having at least the specified width.
212
213 static std::string format0(Int64 value, int width);
214 /// Formats a 64-bit integer value in decimal notation,
215 /// right justified and zero-padded in a field having at least
216 /// the specified width.
217
218 static std::string formatHex(Int64 value, bool prefix = false);
219 /// Formats a 64-bit integer value in hexadecimal notation.
220 /// If prefix is true, "0x" prefix is prepended to the
221 /// resulting string.
222 /// The value is treated as unsigned.
223
224 static std::string formatHex(Int64 value, int width, bool prefix = false);
225 /// Formats a 64-bit integer value in hexadecimal notation,
226 /// right justified and zero-padded in a field having at least
227 /// the specified width.
228 /// The value is treated as unsigned.
229 /// If prefix is true, "0x" prefix is prepended to the resulting string.
230
231 static std::string format(UInt64 value);
232 /// Formats an unsigned 64-bit integer value in decimal notation.
233
234 static std::string format(UInt64 value, int width);
235 /// Formats an unsigned 64-bit integer value in decimal notation,
236 /// right justified in a field having at least the specified width.
237
238 static std::string format0(UInt64 value, int width);
239 /// Formats an unsigned 64-bit integer value in decimal notation,
240 /// right justified and zero-padded in a field having at least the
241 /// specified width.
242
243 static std::string formatHex(UInt64 value, bool prefix = false);
244 /// Formats a 64-bit integer value in hexadecimal notation.
245 /// If prefix is true, "0x" prefix is prepended to the
246 /// resulting string.
247
248 static std::string formatHex(UInt64 value, int width, bool prefix = false);
249 /// Formats a 64-bit integer value in hexadecimal notation,
250 /// right justified and zero-padded in a field having at least
251 /// the specified width. If prefix is true, "0x" prefix is
252 /// prepended to the resulting string.
253
254 #endif // ifdef POCO_INT64_IS_LONG
255 #endif // ifdef POCO_HAVE_INT64
256
257 static std::string format(float value);
258 /// Formats a float value in decimal floating-point notation,
259 /// according to std::printf's %g format with a precision of 8 fractional digits.
260
261 static std::string format(float value, int precision);
262 /// Formats a double value in decimal floating-point notation,
263 /// according to std::printf's %f format with the given precision.
264
265 static std::string format(float value, int width, int precision);
266 /// Formats a double value in decimal floating-point notation,
267 /// right justified in a field of the specified width,
268 /// with the number of fractional digits given in precision.
269
270 static std::string format(double value);
271 /// Formats a double value in decimal floating-point notation,
272 /// according to std::printf's %g format with a precision of 16 fractional digits.
273
274 static std::string format(double value, int precision);
275 /// Formats a double value in decimal floating-point notation,
276 /// according to std::printf's %f format with the given precision.
277
278 static std::string format(double value, int width, int precision);
279 /// Formats a double value in decimal floating-point notation,
280 /// right justified in a field of the specified width,
281 /// with the number of fractional digits given in precision.
282
283 static std::string format(const void* ptr);
284 /// Formats a pointer in an eight (32-bit architectures) or
285 /// sixteen (64-bit architectures) characters wide
286 /// field in hexadecimal notation.
287
288 static std::string format(bool value, BoolFormat format = FMT_TRUE_FALSE);
289 /// Formats a bool value in decimal/text notation,
290 /// according to format parameter.
291
292 static void append(std::string& str, int value);
293 /// Formats an integer value in decimal notation.
294
295 static void append(std::string& str, int value, int width);
296 /// Formats an integer value in decimal notation,
297 /// right justified in a field having at least
298 /// the specified width.
299
300 static void append0(std::string& str, int value, int width);
301 /// Formats an integer value in decimal notation,
302 /// right justified and zero-padded in a field
303 /// having at least the specified width.
304
305 static void appendHex(std::string& str, int value);
306 /// Formats an int value in hexadecimal notation.
307 /// The value is treated as unsigned.
308
309 static void appendHex(std::string& str, int value, int width);
310 /// Formats a int value in hexadecimal notation,
311 /// right justified and zero-padded in
312 /// a field having at least the specified width.
313 /// The value is treated as unsigned.
314
315 static void append(std::string& str, unsigned value);
316 /// Formats an unsigned int value in decimal notation.
317
318 static void append(std::string& str, unsigned value, int width);
319 /// Formats an unsigned long int in decimal notation,
320 /// right justified in a field having at least the
321 /// specified width.
322
323 static void append0(std::string& str, unsigned int value, int width);
324 /// Formats an unsigned int value in decimal notation,
325 /// right justified and zero-padded in a field having at
326 /// least the specified width.
327
328 static void appendHex(std::string& str, unsigned value);
329 /// Formats an unsigned int value in hexadecimal notation.
330
331 static void appendHex(std::string& str, unsigned value, int width);
332 /// Formats a int value in hexadecimal notation,
333 /// right justified and zero-padded in
334 /// a field having at least the specified width.
335
336 static void append(std::string& str, long value);
337 /// Formats a long value in decimal notation.
338
339 static void append(std::string& str, long value, int width);
340 /// Formats a long value in decimal notation,
341 /// right justified in a field having at least the
342 /// specified width.
343
344 static void append0(std::string& str, long value, int width);
345 /// Formats a long value in decimal notation,
346 /// right justified and zero-padded in a field
347 /// having at least the specified width.
348
349 static void appendHex(std::string& str, long value);
350 /// Formats an unsigned long value in hexadecimal notation.
351 /// The value is treated as unsigned.
352
353 static void appendHex(std::string& str, long value, int width);
354 /// Formats an unsigned long value in hexadecimal notation,
355 /// right justified and zero-padded in a field having at least the
356 /// specified width.
357 /// The value is treated as unsigned.
358
359 static void append(std::string& str, unsigned long value);
360 /// Formats an unsigned long value in decimal notation.
361
362 static void append(std::string& str, unsigned long value, int width);
363 /// Formats an unsigned long value in decimal notation,
364 /// right justified in a field having at least the specified
365 /// width.
366
367 static void append0(std::string& str, unsigned long value, int width);
368 /// Formats an unsigned long value in decimal notation,
369 /// right justified and zero-padded
370 /// in a field having at least the specified width.
371
372 static void appendHex(std::string& str, unsigned long value);
373 /// Formats an unsigned long value in hexadecimal notation.
374
375 static void appendHex(std::string& str, unsigned long value, int width);
376 /// Formats an unsigned long value in hexadecimal notation,
377 /// right justified and zero-padded in a field having at least the
378 /// specified width.
379
380 #ifdef POCO_HAVE_INT64
381 #ifdef POCO_INT64_IS_LONG
382
383 static void append(std::string& str, long long value);
384 /// Formats a 64-bit integer value in decimal notation.
385
386 static void append(std::string& str, long long value, int width);
387 /// Formats a 64-bit integer value in decimal notation,
388 /// right justified in a field having at least the specified width.
389
390 static void append0(std::string& str, long long value, int width);
391 /// Formats a 64-bit integer value in decimal notation,
392 /// right justified and zero-padded in a field having at least
393 /// the specified width.
394
395 static void appendHex(std::string& str, long long value);
396 /// Formats a 64-bit integer value in hexadecimal notation.
397 /// The value is treated as unsigned.
398
399 static void appendHex(std::string& str, long long value, int width);
400 /// Formats a 64-bit integer value in hexadecimal notation,
401 /// right justified and zero-padded in a field having at least
402 /// the specified width.
403 /// The value is treated as unsigned.
404
405 static void append(std::string& str, unsigned long long value);
406 /// Formats an unsigned 64-bit integer value in decimal notation.
407
408 static void append(std::string& str, unsigned long long value, int width);
409 /// Formats an unsigned 64-bit integer value in decimal notation,
410 /// right justified in a field having at least the specified width.
411
412 static void append0(std::string& str, unsigned long long value, int width);
413 /// Formats an unsigned 64-bit integer value in decimal notation,
414 /// right justified and zero-padded in a field having at least the
415 /// specified width.
416
417 static void appendHex(std::string& str, unsigned long long value);
418 /// Formats a 64-bit integer value in hexadecimal notation.
419
420 static void appendHex(std::string& str, unsigned long long value, int width);
421 /// Formats a 64-bit integer value in hexadecimal notation,
422 /// right justified and zero-padded in a field having at least
423 /// the specified width.
424
425 #else // ifndef POCO_INT64_IS_LONG
426
427 static void append(std::string& str, Int64 value);
428 /// Formats a 64-bit integer value in decimal notation.
429
430 static void append(std::string& str, Int64 value, int width);
431 /// Formats a 64-bit integer value in decimal notation,
432 /// right justified in a field having at least the specified width.
433
434 static void append0(std::string& str, Int64 value, int width);
435 /// Formats a 64-bit integer value in decimal notation,
436 /// right justified and zero-padded in a field having at least
437 /// the specified width.
438
439 static void appendHex(std::string& str, Int64 value);
440 /// Formats a 64-bit integer value in hexadecimal notation.
441 /// The value is treated as unsigned.
442
443 static void appendHex(std::string& str, Int64 value, int width);
444 /// Formats a 64-bit integer value in hexadecimal notation,
445 /// right justified and zero-padded in a field having at least
446 /// the specified width.
447 /// The value is treated as unsigned.
448
449 static void append(std::string& str, UInt64 value);
450 /// Formats an unsigned 64-bit integer value in decimal notation.
451
452 static void append(std::string& str, UInt64 value, int width);
453 /// Formats an unsigned 64-bit integer value in decimal notation,
454 /// right justified in a field having at least the specified width.
455
456 static void append0(std::string& str, UInt64 value, int width);
457 /// Formats an unsigned 64-bit integer value in decimal notation,
458 /// right justified and zero-padded in a field having at least the
459 /// specified width.
460
461 static void appendHex(std::string& str, UInt64 value);
462 /// Formats a 64-bit integer value in hexadecimal notation.
463
464 static void appendHex(std::string& str, UInt64 value, int width);
465 /// Formats a 64-bit integer value in hexadecimal notation,
466 /// right justified and zero-padded in a field having at least
467 /// the specified width.
468
469 #endif // ifdef POCO_INT64_IS_LONG
470 #endif // ifdef POCO_HAVE_INT64
471
472 static void append(std::string& str, float value);
473 /// Formats a float value in decimal floating-point notation,
474 /// according to std::printf's %g format with a precision of 8 fractional digits.
475
476 static void append(std::string& str, float value, int precision);
477 /// Formats a double value in decimal floating-point notation,
478 /// according to std::printf's %f format with the given precision.
479
480 static void append(std::string& str, float value, int width, int precision);
481 /// Formats a double value in decimal floating-point notation,
482 /// right justified in a field of the specified width,
483 /// with the number of fractional digits given in precision.
484
485 static void append(std::string& str, double value);
486 /// Formats a double value in decimal floating-point notation,
487 /// according to std::printf's %g format with a precision of 16 fractional digits.
488
489 static void append(std::string& str, double value, int precision);
490 /// Formats a double value in decimal floating-point notation,
491 /// according to std::printf's %f format with the given precision.
492
493 static void append(std::string& str, double value, int width, int precision);
494 /// Formats a double value in decimal floating-point notation,
495 /// right justified in a field of the specified width,
496 /// with the number of fractional digits given in precision.
497
498 static void append(std::string& str, const void* ptr);
499 /// Formats a pointer in an eight (32-bit architectures) or
500 /// sixteen (64-bit architectures) characters wide
501 /// field in hexadecimal notation.
502
503 private:
504 };
505
506
507 //
508 // inlines
509 //
510
format(int value)511 inline std::string NumberFormatter::format(int value)
512 {
513 std::string result;
514 intToStr(value, 10, result);
515 return result;
516 }
517
518
format(int value,int width)519 inline std::string NumberFormatter::format(int value, int width)
520 {
521 std::string result;
522 intToStr(value, 10, result, false, width, ' ');
523 return result;
524 }
525
526
format0(int value,int width)527 inline std::string NumberFormatter::format0(int value, int width)
528 {
529 std::string result;
530 intToStr(value, 10, result, false, width, '0');
531 return result;
532 }
533
534
formatHex(int value,bool prefix)535 inline std::string NumberFormatter::formatHex(int value, bool prefix)
536 {
537 std::string result;
538 uIntToStr(static_cast<unsigned int>(value), 0x10, result, prefix);
539 return result;
540 }
541
542
formatHex(int value,int width,bool prefix)543 inline std::string NumberFormatter::formatHex(int value, int width, bool prefix)
544 {
545 std::string result;
546 uIntToStr(static_cast<unsigned int>(value), 0x10, result, prefix, width, '0');
547 return result;
548 }
549
550
format(unsigned value)551 inline std::string NumberFormatter::format(unsigned value)
552 {
553 std::string result;
554 uIntToStr(value, 10, result);
555 return result;
556 }
557
558
format(unsigned value,int width)559 inline std::string NumberFormatter::format(unsigned value, int width)
560 {
561 std::string result;
562 uIntToStr(value, 10, result, false, width, ' ');
563 return result;
564 }
565
566
format0(unsigned int value,int width)567 inline std::string NumberFormatter::format0(unsigned int value, int width)
568 {
569 std::string result;
570 uIntToStr(value, 10, result, false, width, '0');
571 return result;
572 }
573
574
formatHex(unsigned value,bool prefix)575 inline std::string NumberFormatter::formatHex(unsigned value, bool prefix)
576 {
577 std::string result;
578 uIntToStr(value, 0x10, result, prefix);
579 return result;
580 }
581
582
formatHex(unsigned value,int width,bool prefix)583 inline std::string NumberFormatter::formatHex(unsigned value, int width, bool prefix)
584 {
585 std::string result;
586 uIntToStr(value, 0x10, result, prefix, width, '0');
587 return result;
588 }
589
590
format(long value)591 inline std::string NumberFormatter::format(long value)
592 {
593 std::string result;
594 intToStr(value, 10, result);
595 return result;
596 }
597
598
format(long value,int width)599 inline std::string NumberFormatter::format(long value, int width)
600 {
601 std::string result;
602 intToStr(value, 10, result, false, width, ' ');
603 return result;
604 }
605
606
format0(long value,int width)607 inline std::string NumberFormatter::format0(long value, int width)
608 {
609 std::string result;
610 intToStr(value, 10, result, false, width, '0');
611 return result;
612 }
613
614
formatHex(long value,bool prefix)615 inline std::string NumberFormatter::formatHex(long value, bool prefix)
616 {
617 std::string result;
618 uIntToStr(static_cast<unsigned long>(value), 0x10, result, prefix);
619 return result;
620 }
621
622
formatHex(long value,int width,bool prefix)623 inline std::string NumberFormatter::formatHex(long value, int width, bool prefix)
624 {
625 std::string result;
626 uIntToStr(static_cast<unsigned long>(value), 0x10, result, prefix, width, '0');
627 return result;
628 }
629
630
format(unsigned long value)631 inline std::string NumberFormatter::format(unsigned long value)
632 {
633 std::string result;
634 uIntToStr(value, 10, result);
635 return result;
636 }
637
638
format(unsigned long value,int width)639 inline std::string NumberFormatter::format(unsigned long value, int width)
640 {
641 std::string result;
642 uIntToStr(value, 10, result, false, width, ' ');
643 return result;
644 }
645
646
format0(unsigned long value,int width)647 inline std::string NumberFormatter::format0(unsigned long value, int width)
648 {
649 std::string result;
650 uIntToStr(value, 10, result, false, width, '0');
651 return result;
652 }
653
654
formatHex(unsigned long value,bool prefix)655 inline std::string NumberFormatter::formatHex(unsigned long value, bool prefix)
656 {
657 std::string result;
658 uIntToStr(value, 0x10, result, prefix);
659 return result;
660 }
661
662
formatHex(unsigned long value,int width,bool prefix)663 inline std::string NumberFormatter::formatHex(unsigned long value, int width, bool prefix)
664 {
665 std::string result;
666 uIntToStr(value, 0x10, result, prefix, width, '0');
667 return result;
668 }
669
670
671 #ifdef POCO_HAVE_INT64
672 #ifdef POCO_INT64_IS_LONG
673
674
format(long long value)675 inline std::string NumberFormatter::format(long long value)
676 {
677 std::string result;
678 intToStr(value, 10, result);
679 return result;
680 }
681
682
format(long long value,int width)683 inline std::string NumberFormatter::format(long long value, int width)
684 {
685 std::string result;
686 intToStr(value, 10, result, false, width, ' ');
687 return result;
688 }
689
690
format0(long long value,int width)691 inline std::string NumberFormatter::format0(long long value, int width)
692 {
693 std::string result;
694 intToStr(value, 10, result, false, width, '0');
695 return result;
696 }
697
698
formatHex(long long value,bool prefix)699 inline std::string NumberFormatter::formatHex(long long value, bool prefix)
700 {
701 std::string result;
702 uIntToStr(static_cast<unsigned long long>(value), 0x10, result, prefix);
703 return result;
704 }
705
706
formatHex(long long value,int width,bool prefix)707 inline std::string NumberFormatter::formatHex(long long value, int width, bool prefix)
708 {
709 std::string result;
710 uIntToStr(static_cast<unsigned long long>(value), 0x10, result, prefix, width, '0');
711 return result;
712 }
713
714
format(unsigned long long value)715 inline std::string NumberFormatter::format(unsigned long long value)
716 {
717 std::string result;
718 uIntToStr(value, 10, result);
719 return result;
720 }
721
722
format(unsigned long long value,int width)723 inline std::string NumberFormatter::format(unsigned long long value, int width)
724 {
725 std::string result;
726 uIntToStr(value, 10, result, false, width, ' ');
727 return result;
728 }
729
730
format0(unsigned long long value,int width)731 inline std::string NumberFormatter::format0(unsigned long long value, int width)
732 {
733 std::string result;
734 uIntToStr(value, 10, result, false, width, '0');
735 return result;
736 }
737
738
formatHex(unsigned long long value,bool prefix)739 inline std::string NumberFormatter::formatHex(unsigned long long value, bool prefix)
740 {
741 std::string result;
742 uIntToStr(value, 0x10, result, prefix);
743 return result;
744 }
745
746
formatHex(unsigned long long value,int width,bool prefix)747 inline std::string NumberFormatter::formatHex(unsigned long long value, int width, bool prefix)
748 {
749 std::string result;
750 uIntToStr(value, 0x10, result, prefix, width, '0');
751 return result;
752 }
753
754
755 #else // ifndef POCO_LONG_IS_64_BIT
756
757
format(Int64 value)758 inline std::string NumberFormatter::format(Int64 value)
759 {
760 std::string result;
761 intToStr(value, 10, result);
762 return result;
763 }
764
765
format(Int64 value,int width)766 inline std::string NumberFormatter::format(Int64 value, int width)
767 {
768 std::string result;
769 intToStr(value, 10, result, false, width, ' ');
770 return result;
771 }
772
773
format0(Int64 value,int width)774 inline std::string NumberFormatter::format0(Int64 value, int width)
775 {
776 std::string result;
777 intToStr(value, 10, result, false, width, '0');
778 return result;
779 }
780
781
formatHex(Int64 value,bool prefix)782 inline std::string NumberFormatter::formatHex(Int64 value, bool prefix)
783 {
784 std::string result;
785 uIntToStr(static_cast<UInt64>(value), 0x10, result, prefix);
786 return result;
787 }
788
789
formatHex(Int64 value,int width,bool prefix)790 inline std::string NumberFormatter::formatHex(Int64 value, int width, bool prefix)
791 {
792 std::string result;
793 uIntToStr(static_cast<UInt64>(value), 0x10, result, prefix, width, '0');
794 return result;
795 }
796
797
format(UInt64 value)798 inline std::string NumberFormatter::format(UInt64 value)
799 {
800 std::string result;
801 uIntToStr(value, 10, result);
802 return result;
803 }
804
805
format(UInt64 value,int width)806 inline std::string NumberFormatter::format(UInt64 value, int width)
807 {
808 std::string result;
809 uIntToStr(value, 10, result, false, width, ' ');
810 return result;
811 }
812
813
format0(UInt64 value,int width)814 inline std::string NumberFormatter::format0(UInt64 value, int width)
815 {
816 std::string result;
817 uIntToStr(value, 10, result, false, width, '0');
818 return result;
819 }
820
821
formatHex(UInt64 value,bool prefix)822 inline std::string NumberFormatter::formatHex(UInt64 value, bool prefix)
823 {
824 std::string result;
825 uIntToStr(value, 0x10, result, prefix);
826 return result;
827 }
828
829
formatHex(UInt64 value,int width,bool prefix)830 inline std::string NumberFormatter::formatHex(UInt64 value, int width, bool prefix)
831 {
832 std::string result;
833 uIntToStr(value, 0x10, result, prefix, width, '0');
834 return result;
835 }
836
837
838 #endif // ifdef POCO_INT64_IS_LONG
839 #endif // ifdef POCO_HAVE_INT64
840
841
format(float value)842 inline std::string NumberFormatter::format(float value)
843 {
844 char buffer[POCO_MAX_FLT_STRING_LEN];
845 floatToStr(buffer, POCO_MAX_FLT_STRING_LEN, value);
846 return std::string(buffer);
847 }
848
849
format(float value,int precision)850 inline std::string NumberFormatter::format(float value, int precision)
851 {
852 char buffer[POCO_MAX_FLT_STRING_LEN];
853 floatToFixedStr(buffer, POCO_MAX_FLT_STRING_LEN, value, precision);
854 return std::string(buffer);
855 }
856
857
format(float value,int width,int precision)858 inline std::string NumberFormatter::format(float value, int width, int precision)
859 {
860 std::string result;
861 floatToFixedStr(result, value, precision, width);
862 return result;
863 }
864
865
format(double value)866 inline std::string NumberFormatter::format(double value)
867 {
868 char buffer[POCO_MAX_FLT_STRING_LEN];
869 doubleToStr(buffer, POCO_MAX_FLT_STRING_LEN, value);
870 return std::string(buffer);
871 }
872
873
format(double value,int precision)874 inline std::string NumberFormatter::format(double value, int precision)
875 {
876 char buffer[POCO_MAX_FLT_STRING_LEN];
877 doubleToFixedStr(buffer, POCO_MAX_FLT_STRING_LEN, value, precision);
878 return std::string(buffer);
879 }
880
881
format(double value,int width,int precision)882 inline std::string NumberFormatter::format(double value, int width, int precision)
883 {
884 std::string result;
885 doubleToFixedStr(result, value, precision, width);
886 return result;
887 }
888
889
format(const void * ptr)890 inline std::string NumberFormatter::format(const void* ptr)
891 {
892 std::string result;
893 append(result, ptr);
894 return result;
895 }
896
897
898 } // namespace Poco
899
900
901 #endif // Foundation_NumberFormatter_INCLUDED
902