]> Dogcows Code - chaz/yoink/blob - src/stlplus/strings/string_int.hpp
build system enhancements
[chaz/yoink] / src / stlplus / strings / string_int.hpp
1 #ifndef STLPLUS_STRING_INT
2 #define STLPLUS_STRING_INT
3 ////////////////////////////////////////////////////////////////////////////////
4
5 // Author: Andy Rushton
6 // Copyright: (c) Southampton University 1999-2004
7 // (c) Andy Rushton 2004-2009
8 // License: BSD License, see ../docs/license.html
9
10 // Convert integer types to/from string
11
12 ////////////////////////////////////////////////////////////////////////////////
13 #include "strings_fixes.hpp"
14 #include "format_types.hpp"
15 #include <string>
16 #include <stdexcept>
17
18 namespace stlplus
19 {
20
21 ////////////////////////////////////////////////////////////////////////////////
22 // Conversions of Integer types to string
23 ////////////////////////////////////////////////////////////////////////////////
24
25 // The radix (i.e. base) for these conversions can be any value from base 2 to base 36
26 // specifying any other radix causes std::invalid_argument to be thrown
27
28 // The way in which the radix is displayed is defined in radix_types.hpp
29 // If any other value is used, std::invalid_argument is thrown
30
31 // The width argument specifies the number of numerical digits to use in the result
32 // This is a minimum - if the value requires more digits then it will be wider than the width argument
33 // However, if it is smaller, then it will be extended to the specified width
34 // Then, the radix display prefix is added to this width
35
36 // For example, using the hash representation of 0 in hex with width=4 gives:
37 // 16#0000 - so there's 4 digits in the number part
38
39 std::string short_to_string(short i,
40 unsigned radix = 10,
41 radix_display_t display = radix_c_style_or_hash,
42 unsigned width = 0)
43 throw(std::invalid_argument);
44
45 std::string unsigned_short_to_string(unsigned short i,
46 unsigned radix = 10,
47 radix_display_t display = radix_c_style_or_hash,
48 unsigned width = 0)
49 throw(std::invalid_argument);
50
51 std::string int_to_string(int i,
52 unsigned radix = 10,
53 radix_display_t display = radix_c_style_or_hash,
54 unsigned width = 0)
55 throw(std::invalid_argument);
56
57 std::string unsigned_to_string(unsigned i,
58 unsigned radix = 10,
59 radix_display_t display = radix_c_style_or_hash,
60 unsigned width = 0)
61 throw(std::invalid_argument);
62
63 std::string long_to_string(long i,
64 unsigned radix = 10,
65 radix_display_t display = radix_c_style_or_hash,
66 unsigned width = 0)
67 throw(std::invalid_argument);
68
69 std::string unsigned_long_to_string(unsigned long i,
70 unsigned radix = 10,
71 radix_display_t display = radix_c_style_or_hash,
72 unsigned width = 0)
73 throw(std::invalid_argument);
74
75 ////////////////////////////////////////////////////////////////////////////////
76 // Convert a string to an integer type
77 ////////////////////////////////////////////////////////////////////////////////
78 // supports all the formats described above for the reverse conversion
79 // If the radix is set to zero, the conversions deduce the radix from the string representation
80 // So,
81 // 0b prefix is binary,
82 // 0 prefix is octal,
83 // 0x is hex
84 // <base># prefix is my hash format
85 // The radix must be either zero as explained above, or in the range 2 to 16
86 // A non-zero radix should be used when the string value has no radix information and is non-decimal
87 // e.g. the hex value FEDCBA has no indication that it is hex, so specify radix 16
88 // Any other value of radix will cause std::invalid_argument to be thrown
89
90 short string_to_short(const std::string& value,
91 unsigned radix = 0)
92 throw(std::invalid_argument);
93
94 unsigned short string_to_unsigned_short(const std::string& value,
95 unsigned radix = 0)
96 throw(std::invalid_argument);
97
98 int string_to_int(const std::string& value,
99 unsigned radix = 0)
100 throw(std::invalid_argument);
101
102 unsigned string_to_unsigned(const std::string& value,
103 unsigned radix = 0)
104 throw(std::invalid_argument);
105
106 long string_to_long(const std::string& value,
107 unsigned radix = 0)
108 throw(std::invalid_argument);
109
110 unsigned long string_to_unsigned_long(const std::string& value,
111 unsigned radix = 0)
112 throw(std::invalid_argument);
113
114 ////////////////////////////////////////////////////////////////////////////////
115
116 } // end namespace stlplus
117
118 #endif
This page took 0.035753 seconds and 4 git commands to generate.