]>
Dogcows Code - chaz/yoink/blob - src/stlplus/strings/string_int.hpp
1 #ifndef STLPLUS_STRING_INT
2 #define STLPLUS_STRING_INT
3 ////////////////////////////////////////////////////////////////////////////////
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
10 // Convert integer types to/from string
12 ////////////////////////////////////////////////////////////////////////////////
13 #include "strings_fixes.hpp"
14 #include "format_types.hpp"
21 ////////////////////////////////////////////////////////////////////////////////
22 // Conversions of Integer types to string
23 ////////////////////////////////////////////////////////////////////////////////
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
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
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
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
39 std::string
short_to_string(short i
,
41 radix_display_t display
= radix_c_style_or_hash
,
43 throw(std::invalid_argument
);
45 std::string
unsigned_short_to_string(unsigned short i
,
47 radix_display_t display
= radix_c_style_or_hash
,
49 throw(std::invalid_argument
);
51 std::string
int_to_string(int i
,
53 radix_display_t display
= radix_c_style_or_hash
,
55 throw(std::invalid_argument
);
57 std::string
unsigned_to_string(unsigned i
,
59 radix_display_t display
= radix_c_style_or_hash
,
61 throw(std::invalid_argument
);
63 std::string
long_to_string(long i
,
65 radix_display_t display
= radix_c_style_or_hash
,
67 throw(std::invalid_argument
);
69 std::string
unsigned_long_to_string(unsigned long i
,
71 radix_display_t display
= radix_c_style_or_hash
,
73 throw(std::invalid_argument
);
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
81 // 0b prefix is binary,
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
90 short string_to_short(const std::string
& value
,
92 throw(std::invalid_argument
);
94 unsigned short string_to_unsigned_short(const std::string
& value
,
96 throw(std::invalid_argument
);
98 int string_to_int(const std::string
& value
,
100 throw(std::invalid_argument
);
102 unsigned string_to_unsigned(const std::string
& value
,
104 throw(std::invalid_argument
);
106 long string_to_long(const std::string
& value
,
108 throw(std::invalid_argument
);
110 unsigned long string_to_unsigned_long(const std::string
& value
,
112 throw(std::invalid_argument
);
114 ////////////////////////////////////////////////////////////////////////////////
116 } // end namespace stlplus
This page took 0.036579 seconds and 4 git commands to generate.