@@ -964,12 +964,12 @@ class basic_memory_buffer : public detail::buffer<T> {
964
964
965
965
using memory_buffer = basic_memory_buffer<char>;
966
966
967
-
template <typename Char, size_t SIZE>
968
-
FMT_NODISCARD auto to_string(const basic_memory_buffer<Char, SIZE>& buf)
969
-
-> std::basic_string<Char> {
967
+
template <size_t SIZE>
968
+
FMT_NODISCARD auto to_string(basic_memory_buffer<char, SIZE>& buf)
969
+
-> std::string {
970
970
auto size = buf.size();
971
-
detail::assume(size < std::basic_string<Char>().max_size());
972
-
return std::basic_string<Char>(buf.data(), size);
971
+
detail::assume(size < std::string().max_size());
972
+
return {buf.data(), size};
973
973
}
974
974
975
975
// A writer to a buffered stream. It doesn't own the underlying stream.
@@ -1020,7 +1020,7 @@ FMT_CONSTEXPR auto make_arg(T& val) -> basic_format_arg<Context> {
1020
1020
}
1021
1021
1022
1022
FMT_API auto write_console(int fd, string_view text) -> bool;
1023
-
FMT_API void print(std::FILE*, string_view);
1023
+
FMT_API void print(FILE*, string_view);
1024
1024
} // namespace detail
1025
1025
1026
1026
FMT_BEGIN_EXPORT
@@ -3868,14 +3868,6 @@ void vformat_to(buffer<Char>& buf, basic_string_view<Char> fmt,
3868
3868
fmt, format_handler<Char>{parse_context<Char>(fmt), {out, args, loc}});
3869
3869
}
3870
3870
3871
-
template <typename Locale>
3872
-
auto vformat(const Locale& loc, string_view fmt, format_args args)
3873
-
-> std::string {
3874
-
auto buf = memory_buffer();
3875
-
detail::vformat_to(buf, fmt, args, detail::locale_ref(loc));
3876
-
return {buf.data(), buf.size()};
3877
-
}
3878
-
3879
3871
using format_func = void (*)(detail::buffer<char>&, int, const char*);
3880
3872
3881
3873
FMT_API void format_error_code(buffer<char>& out, int error_code,
@@ -3915,112 +3907,8 @@ FMT_CONSTEXPR auto native_formatter<T, Char, TYPE>::format(
3915
3907
specs_.precision_ref, ctx);
3916
3908
return write<Char>(ctx.out(), val, specs, ctx.locale());
3917
3909
}
3918
-
3919
3910
} // namespace detail
3920
3911
3921
-
FMT_BEGIN_EXPORT
3922
-
FMT_API auto vsystem_error(int error_code, string_view fmt, format_args args)
3923
-
-> std::system_error;
3924
-
3925
-
/**
3926
-
* Constructs `std::system_error` with a message formatted with
3927
-
* `fmt::format(fmt, args...)`.
3928
-
* `error_code` is a system error code as given by `errno`.
3929
-
*
3930
-
* **Example**:
3931
-
*
3932
-
* // This throws std::system_error with the description
3933
-
* // cannot open file 'madeup': No such file or directory
3934
-
* // or similar (system message may vary).
3935
-
* const char* filename = "madeup";
3936
-
* std::FILE* file = std::fopen(filename, "r");
3937
-
* if (!file)
3938
-
* throw fmt::system_error(errno, "cannot open file '{}'", filename);
3939
-
*/
3940
-
template <typename... T>
3941
-
auto system_error(int error_code, format_string<T...> fmt, T&&... args)
3942
-
-> std::system_error {
3943
-
return vsystem_error(error_code, fmt.str, vargs<T...>{{args...}});
3944
-
}
3945
-
3946
-
/**
3947
-
* Formats an error message for an error returned by an operating system or a
3948
-
* language runtime, for example a file opening error, and writes it to `out`.
3949
-
* The format is the same as the one used by `std::system_error(ec, message)`
3950
-
* where `ec` is `std::error_code(error_code, std::generic_category())`.
3951
-
* It is implementation-defined but normally looks like:
3952
-
*
3953
-
* <message>: <system-message>
3954
-
*
3955
-
* where `<message>` is the passed message and `<system-message>` is the system
3956
-
* message corresponding to the error code.
3957
-
* `error_code` is a system error code as given by `errno`.
3958
-
*/
3959
-
FMT_API void format_system_error(detail::buffer<char>& out, int error_code,
3960
-
const char* message) noexcept;
3961
-
3962
-
// Reports a system error without throwing an exception.
3963
-
// Can be used to report errors from destructors.
3964
-
FMT_API void report_system_error(int error_code, const char* message) noexcept;
3965
-
3966
-
/// A fast integer formatter.
3967
-
class format_int {
3968
-
private:
3969
-
// Buffer should be large enough to hold all digits (digits10 + 1),
3970
-
// a sign and a null character.
3971
-
enum { buffer_size = std::numeric_limits<unsigned long long>::digits10 + 3 };
3972
-
mutable char buffer_[buffer_size];
3973
-
char* str_;
3974
-
3975
-
template <typename UInt>
3976
-
FMT_CONSTEXPR20 auto format_unsigned(UInt value) -> char* {
3977
-
auto n = static_cast<detail::uint32_or_64_or_128_t<UInt>>(value);
3978
-
return detail::do_format_decimal(buffer_, n, buffer_size - 1);
3979
-
}
3980
-
3981
-
template <typename Int>
3982
-
FMT_CONSTEXPR20 auto format_signed(Int value) -> char* {
3983
-
auto abs_value = static_cast<detail::uint32_or_64_or_128_t<Int>>(value);
3984
-
bool negative = value < 0;
3985
-
if (negative) abs_value = 0 - abs_value;
3986
-
auto begin = format_unsigned(abs_value);
3987
-
if (negative) *--begin = '-';
3988
-
return begin;
3989
-
}
3990
-
3991
-
public:
3992
-
explicit FMT_CONSTEXPR20 format_int(int value) : str_(format_signed(value)) {}
3993
-
explicit FMT_CONSTEXPR20 format_int(long value)
3994
-
: str_(format_signed(value)) {}
3995
-
explicit FMT_CONSTEXPR20 format_int(long long value)
3996
-
: str_(format_signed(value)) {}
3997
-
explicit FMT_CONSTEXPR20 format_int(unsigned value)
3998
-
: str_(format_unsigned(value)) {}
3999
-
explicit FMT_CONSTEXPR20 format_int(unsigned long value)
4000
-
: str_(format_unsigned(value)) {}
4001
-
explicit FMT_CONSTEXPR20 format_int(unsigned long long value)
4002
-
: str_(format_unsigned(value)) {}
4003
-
4004
-
/// Returns the number of characters written to the output buffer.
4005
-
FMT_CONSTEXPR20 auto size() const -> size_t {
4006
-
return detail::to_unsigned(buffer_ - str_ + buffer_size - 1);
4007
-
}
4008
-
4009
-
/// Returns a pointer to the output buffer content. No terminating null
4010
-
/// character is appended.
4011
-
FMT_CONSTEXPR20 auto data() const -> const char* { return str_; }
4012
-
4013
-
/// Returns a pointer to the output buffer content with terminating null
4014
-
/// character appended.
4015
-
FMT_CONSTEXPR20 auto c_str() const -> const char* {
4016
-
buffer_[buffer_size - 1] = '\0';
4017
-
return str_;
4018
-
}
4019
-
4020
-
/// Returns the content of the output buffer as an `std::string`.
4021
-
auto str() const -> std::string { return std::string(str_, size()); }
4022
-
};
4023
-
4024
3912
template <typename T, typename Char>
4025
3913
struct formatter<T, Char, enable_if_t<detail::has_format_as<T>::value>>
4026
3914
: formatter<detail::format_as_t<T>, Char> {
@@ -4260,10 +4148,115 @@ constexpr auto operator""_a(const char* s, size_t) -> detail::udl_arg<char> {
4260
4148
} // namespace literals
4261
4149
#endif // FMT_USE_USER_LITERALS
4262
4150
4151
+
/// A fast integer formatter.
4152
+
class format_int {
4153
+
private:
4154
+
// Buffer should be large enough to hold all digits (digits10 + 1),
4155
+
// a sign and a null character.
4156
+
enum { buffer_size = std::numeric_limits<unsigned long long>::digits10 + 3 };
4157
+
mutable char buffer_[buffer_size];
4158
+
char* str_;
4159
+
4160
+
template <typename UInt>
4161
+
FMT_CONSTEXPR20 auto format_unsigned(UInt value) -> char* {
4162
+
auto n = static_cast<detail::uint32_or_64_or_128_t<UInt>>(value);
4163
+
return detail::do_format_decimal(buffer_, n, buffer_size - 1);
4164
+
}
4165
+
4166
+
template <typename Int>
4167
+
FMT_CONSTEXPR20 auto format_signed(Int value) -> char* {
4168
+
auto abs_value = static_cast<detail::uint32_or_64_or_128_t<Int>>(value);
4169
+
bool negative = value < 0;
4170
+
if (negative) abs_value = 0 - abs_value;
4171
+
auto begin = format_unsigned(abs_value);
4172
+
if (negative) *--begin = '-';
4173
+
return begin;
4174
+
}
4175
+
4176
+
public:
4177
+
explicit FMT_CONSTEXPR20 format_int(int value) : str_(format_signed(value)) {}
4178
+
explicit FMT_CONSTEXPR20 format_int(long value)
4179
+
: str_(format_signed(value)) {}
4180
+
explicit FMT_CONSTEXPR20 format_int(long long value)
4181
+
: str_(format_signed(value)) {}
4182
+
explicit FMT_CONSTEXPR20 format_int(unsigned value)
4183
+
: str_(format_unsigned(value)) {}
4184
+
explicit FMT_CONSTEXPR20 format_int(unsigned long value)
4185
+
: str_(format_unsigned(value)) {}
4186
+
explicit FMT_CONSTEXPR20 format_int(unsigned long long value)
4187
+
: str_(format_unsigned(value)) {}
4188
+
4189
+
/// Returns the number of characters written to the output buffer.
4190
+
FMT_CONSTEXPR20 auto size() const -> size_t {
4191
+
return detail::to_unsigned(buffer_ - str_ + buffer_size - 1);
4192
+
}
4193
+
4194
+
/// Returns a pointer to the output buffer content. No terminating null
4195
+
/// character is appended.
4196
+
FMT_CONSTEXPR20 auto data() const -> const char* { return str_; }
4197
+
4198
+
/// Returns a pointer to the output buffer content with terminating null
4199
+
/// character appended.
4200
+
FMT_CONSTEXPR20 auto c_str() const -> const char* {
4201
+
buffer_[buffer_size - 1] = '\0';
4202
+
return str_;
4203
+
}
4204
+
4205
+
/// Returns the content of the output buffer as an `std::string`.
4206
+
auto str() const -> std::string { return std::string(str_, size()); }
4207
+
};
4208
+
4209
+
FMT_BEGIN_EXPORT
4210
+
FMT_API auto vsystem_error(int error_code, string_view fmt, format_args args)
4211
+
-> std::system_error;
4212
+
4213
+
/**
4214
+
* Constructs `std::system_error` with a message formatted with
4215
+
* `fmt::format(fmt, args...)`.
4216
+
* `error_code` is a system error code as given by `errno`.
4217
+
*
4218
+
* **Example**:
4219
+
*
4220
+
* // This throws std::system_error with the description
4221
+
* // cannot open file 'madeup': No such file or directory
4222
+
* // or similar (system message may vary).
4223
+
* const char* filename = "madeup";
4224
+
* FILE* file = fopen(filename, "r");
4225
+
* if (!file)
4226
+
* throw fmt::system_error(errno, "cannot open file '{}'", filename);
4227
+
*/
4228
+
template <typename... T>
4229
+
auto system_error(int error_code, format_string<T...> fmt, T&&... args)
4230
+
-> std::system_error {
4231
+
return vsystem_error(error_code, fmt.str, vargs<T...>{{args...}});
4232
+
}
4233
+
4234
+
/**
4235
+
* Formats an error message for an error returned by an operating system or a
4236
+
* language runtime, for example a file opening error, and writes it to `out`.
4237
+
* The format is the same as the one used by `std::system_error(ec, message)`
4238
+
* where `ec` is `std::error_code(error_code, std::generic_category())`.
4239
+
* It is implementation-defined but normally looks like:
4240
+
*
4241
+
* <message>: <system-message>
4242
+
*
4243
+
* where `<message>` is the passed message and `<system-message>` is the system
4244
+
* message corresponding to the error code.
4245
+
* `error_code` is a system error code as given by `errno`.
4246
+
*/
4247
+
FMT_API void format_system_error(detail::buffer<char>& out, int error_code,
4248
+
const char* message) noexcept;
4249
+
4250
+
// Reports a system error without throwing an exception.
4251
+
// Can be used to report errors from destructors.
4252
+
FMT_API void report_system_error(int error_code, const char* message) noexcept;
4253
+
4263
4254
template <typename Locale, FMT_ENABLE_IF(detail::is_locale<Locale>::value)>
4264
4255
auto vformat(const Locale& loc, string_view fmt, format_args args)
4265
4256
-> std::string {
4266
-
return detail::vformat(loc, fmt, args);
4257
+
auto buf = memory_buffer();
4258
+
detail::vformat_to(buf, fmt, args, detail::locale_ref(loc));
4259
+
return {buf.data(), buf.size()};
4267
4260
}
4268
4261
4269
4262
template <typename Locale, typename... T,
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4