cppannotations/annotations/yo/string/convertors.yo
Frank B. Brokken 75d04f6683 typos
2016-11-08 21:54:15 +01:00

109 lines
5.4 KiB
Text

Several string conversion functions are available operating on or producing
tt(std::string) objects. These functions are listed below in alphabetic
order. They are not member functions, but class-less (free) functions declared
in the tt(std) namespace. The tthi(string) header file must be included
before they can be used.
itemization(
ithtq(stof)(float stof(std::string const &str, size_t *pos = 0))
(Initial whitespace characters in tt(str) are ignored. Then the
following sequences of characters are converted to a tt(float) value,
which is returned:
itemization(
it() A decimal floating point constant:
itemization(
it() An optional + or - character
it() A series of decimal digits, possibly containing one decimal
point character
it() An optional e or E character, followed by an optional - or +
character, followed by a series of decimal digits
)
it() A hexadecimal floating point constant:
itemization(
it() An optional + or - character
it() 0x or 0X
it() A series of hexadecimal digits, possibly containing one
decimal point character
it() An optional p or P character, followed by an optional - or +
character, followed by a series of decimal digits
)
it() An infinity expression:
itemization(
it() An optional + or - character
it() The words tt(inf) or tt(infinity) (case insensitive words)
)
it() A `not a number' expression:
itemization(
it() An optional + or - character
it() The words tt(nan) or tt(nan(alphanumeric character sequence))
(tt(nan) is a case insensitive word), resulting in a tt(NaN)
floating point value
)
)
If tt(pos != 0) the index of the first character in tt(str) which was
not converted is returned in tt(*pos). A tt(std::invalid_argument)
exception is thrown if the characters in tt(str) could not be
converted to a tt(float), a tt(std::out_of_range) exception is thrown
if the converted value would have exceeded the range of tt(float)
values.)
ithtq(stod)(double stod(std::string const &str, size_t *pos = 0))
(A conversion as described with tt(stof) is performed, but now to a
value of type tt(double).)
ithtq(stold)(double stold(std::string const &str, size_t *pos = 0))
(A conversion as described with tt(stof) is performed, but now to a
value of type tt(long double).)
ithtq(stoi)(int stoi(std::string const &str, size_t *pos = 0,
int base = 10))
(Initial whitespace characters in tt(str) are ignored. Then all
characters representing numeric constants of the number system whose
tt(base) is specified are converted to an tt(int) value, which is
returned. An optional + or - character may prefix the numeric
characters. Values starting with 0 are automatically interpreted as
octal values, values starting with 0x or 0X as hexadecimal
characters. The value tt(base) must be between 2 and 36. If tt(pos !=
0) the index of the first character in tt(str) which was not converted
is returned in tt(*pos). A tt(std::invalid_argument) exception is
thrown if the characters in tt(str) could not be converted to an
tt(int), a tt(std::out_of_range) exception is thrown if the converted
value would have exceeded the range of tt(int) values.
Here is an example of its use:
verb(
int value = stoi(string(" -123")); // assigns value -123
value = stoi(string(" 123"), 0, 5); // assigns value 38
)
)
ithtq(stol)(long stol(std::string const &str, size_t *pos = 0,
int base = 10))
(A conversion as described with tt(stoi) is performed, but now to a
value of type tt(long).)
ithtq(stoll)(long long stoll(std::string const &str, size_t *pos = 0,
int base = 10))
(A conversion as described with tt(stoi) is performed, but now to a
value of type tt(long long).)
ithtq(stoul)(unsigned long stoul(std::string const &str, size_t *pos = 0,
int base = 10))
(A conversion as described with tt(stoi) (not allowing an initial + or
- character) is performed, but now to a value of type tt(unsigned
long).)
ithtq(stoull)(unsigned long long stoull(std::string const &str,
size_t *pos = 0, int base = 10))
(A conversion as described with tt(stoul) is performed, but now to a
value of type tt(unsigned long long).)
ithtq(to_string)(std::string to_string(Type value))
(Type can be of the types tt(int, long, long long, unsigned, unsigned
long, unsigned long long, float, double,) or tt(long double). The
value of the argument is converted to a textual representation, which
is returned as a tt(std::string) value.
)
ithtq(to_wstring)(std::string to_wstring(Type value))
(The conversion as described at tt(to_string) is performed, returning
a ti(std::wstring).)
)