From 626ea5bd6e69a573c62f6afe63eb9ed72da8f668 Mon Sep 17 00:00:00 2001 From: Gammasoft Date: Mon, 16 Dec 2024 16:16:26 +0100 Subject: [PATCH] Update examples --- .../format/format_enum_class_flags/README.md | 75 +++++++++-- .../src/format_enum_class_flags.cpp | 125 ++++++++++++++---- .../README.md | 74 +++++++++-- ...format_enum_class_flags_without_helper.cpp | 125 ++++++++++++++---- .../format/format_exception/README.md | 16 ++- .../format_exception/src/format_exception.cpp | 58 +++++--- 6 files changed, 383 insertions(+), 90 deletions(-) diff --git a/examples/xtd.core.examples/format/format_enum_class_flags/README.md b/examples/xtd.core.examples/format/format_enum_class_flags/README.md index ad868f8bc3ae..cee9e3477939 100644 --- a/examples/xtd.core.examples/format/format_enum_class_flags/README.md +++ b/examples/xtd.core.examples/format/format_enum_class_flags/README.md @@ -19,16 +19,67 @@ xtdc run # Output (with colors) ``` -saturday -0b101 -0b101 -5 -5 -saturday -saturday -05 -05 -0x5 -0x5 +┌───────────────────────────────────────────────┬────────────┬──────────────────────────────────┐ +│ text_styles │ format │ representation │ +├───────────────────────────────────────────────┼────────────┼──────────────────────────────────┤ +│ text_styles::normal │ {} │ normal │ +│ text_styles::normal │ {:b} │ 0 │ +│ text_styles::normal │ {:b4} │ 0000 │ +│ text_styles::normal │ {:B} │ 0 │ +│ text_styles::normal │ {:B4} │ 0000 │ +│ text_styles::normal │ {:d} │ 0 │ +│ text_styles::normal │ {:d1} │ 0 │ +│ text_styles::normal │ {:D} │ 0 │ +│ text_styles::normal │ {:D1} │ 0 │ +│ text_styles::normal │ {:g} │ normal │ +│ text_styles::normal │ {:G} │ normal │ +│ text_styles::normal │ {:o} │ 0 │ +│ text_styles::normal │ {:o2} │ 00 │ +│ text_styles::normal │ {:O} │ 0 │ +│ text_styles::normal │ {:O2} │ 00 │ +│ text_styles::normal │ {:x} │ 0 │ +│ text_styles::normal │ {:x2} │ 00 │ +│ text_styles::normal │ {:X} │ 0 │ +│ text_styles::normal │ {:X2} │ 00 │ +├───────────────────────────────────────────────┼────────────┼──────────────────────────────────┤ +│ text_styles::bold|text_styles::italic │ {} │ bold, italic │ +│ text_styles::bold|text_styles::italic │ {:b} │ 11 │ +│ text_styles::bold|text_styles::italic │ {:b4} │ 0011 │ +│ text_styles::bold|text_styles::italic │ {:B} │ 11 │ +│ text_styles::bold|text_styles::italic │ {:B4} │ 0011 │ +│ text_styles::bold|text_styles::italic │ {:d} │ 3 │ +│ text_styles::bold|text_styles::italic │ {:d1} │ 3 │ +│ text_styles::bold|text_styles::italic │ {:D} │ 3 │ +│ text_styles::bold|text_styles::italic │ {:D1} │ 3 │ +│ text_styles::bold|text_styles::italic │ {:g} │ bold, italic │ +│ text_styles::bold|text_styles::italic │ {:G} │ bold, italic │ +│ text_styles::bold|text_styles::italic │ {:o} │ 3 │ +│ text_styles::bold|text_styles::italic │ {:o2} │ 03 │ +│ text_styles::bold|text_styles::italic │ {:O} │ 3 │ +│ text_styles::bold|text_styles::italic │ {:O2} │ 03 │ +│ text_styles::bold|text_styles::italic │ {:x} │ 3 │ +│ text_styles::bold|text_styles::italic │ {:x2} │ 03 │ +│ text_styles::bold|text_styles::italic │ {:X} │ 3 │ +│ text_styles::bold|text_styles::italic │ {:X2} │ 03 │ +├───────────────────────────────────────────────┼────────────┼──────────────────────────────────┤ +│ text_styles::strikeout │ {} │ strikeout │ +│ text_styles::strikeout │ {:b} │ 1000 │ +│ text_styles::strikeout │ {:b4} │ 1000 │ +│ text_styles::strikeout │ {:B} │ 1000 │ +│ text_styles::strikeout │ {:B4} │ 1000 │ +│ text_styles::strikeout │ {:d} │ 8 │ +│ text_styles::strikeout │ {:d1} │ 8 │ +│ text_styles::strikeout │ {:D} │ 8 │ +│ text_styles::strikeout │ {:D1} │ 8 │ +│ text_styles::strikeout │ {:g} │ strikeout │ +│ text_styles::strikeout │ {:G} │ strikeout │ +│ text_styles::strikeout │ {:o} │ 10 │ +│ text_styles::strikeout │ {:o2} │ 10 │ +│ text_styles::strikeout │ {:O} │ 10 │ +│ text_styles::strikeout │ {:O2} │ 10 │ +│ text_styles::strikeout │ {:x} │ 8 │ +│ text_styles::strikeout │ {:x2} │ 08 │ +│ text_styles::strikeout │ {:X} │ 8 │ +│ text_styles::strikeout │ {:X2} │ 08 │ +└───────────────────────────────────────────────┴────────────┴──────────────────────────────────┘ ``` - diff --git a/examples/xtd.core.examples/format/format_enum_class_flags/src/format_enum_class_flags.cpp b/examples/xtd.core.examples/format/format_enum_class_flags/src/format_enum_class_flags.cpp index 8fe6e516cbb5..c8267af9ad41 100644 --- a/examples/xtd.core.examples/format/format_enum_class_flags/src/format_enum_class_flags.cpp +++ b/examples/xtd.core.examples/format/format_enum_class_flags/src/format_enum_class_flags.cpp @@ -1,7 +1,7 @@ #include #include #include -#include +#include using namespace xtd; @@ -21,30 +21,109 @@ template<> struct xtd::enum_register { explicit operator auto() const noexcept {return xtd::enum_collection {{text_styles::normal, "normal"}, {text_styles::bold, "bold"}, {text_styles::italic, "italic"}, {text_styles::underline, "underline"}, {text_styles::strikeout, "strikeout"}};} }; +enum class cap {title, middle, end}; + +auto print_text_styles(const string& text, text_styles value, cap c) { + if (c == cap::title) + console::out + << "┌───────────────────────────────────────────────┬────────────┬──────────────────────────────────┐" << environment::new_line + << "│ text_styles │ format │ representation │" << environment::new_line + << "├───────────────────────────────────────────────┼────────────┼──────────────────────────────────┤" << environment::new_line; + + console::out << "│ " << text.pad_right(45) << " │ {} │ " << format("{}", value).pad_right(32) << " │" << environment::new_line; + console::out << "│ " << text.pad_right(45) << " │ {:b} │ " << format("{:b}", value).pad_right(32) << " │" << environment::new_line; + console::out << "│ " << text.pad_right(45) << " │ {:b4} │ " << format("{:b4}", value).pad_right(32) << " │" << environment::new_line; + console::out << "│ " << text.pad_right(45) << " │ {:B} │ " << format("{:B}", value).pad_right(32) << " │" << environment::new_line; + console::out << "│ " << text.pad_right(45) << " │ {:B4} │ " << format("{:B4}", value).pad_right(32) << " │" << environment::new_line; + console::out << "│ " << text.pad_right(45) << " │ {:d} │ " << format("{:d}", value).pad_right(32) << " │" << environment::new_line; + console::out << "│ " << text.pad_right(45) << " │ {:d1} │ " << format("{:d1}", value).pad_right(32) << " │" << environment::new_line; + console::out << "│ " << text.pad_right(45) << " │ {:D} │ " << format("{:D}", value).pad_right(32) << " │" << environment::new_line; + console::out << "│ " << text.pad_right(45) << " │ {:D1} │ " << format("{:D1}", value).pad_right(32) << " │" << environment::new_line; + console::out << "│ " << text.pad_right(45) << " │ {:g} │ " << format("{:g}", value).pad_right(32) << " │" << environment::new_line; + console::out << "│ " << text.pad_right(45) << " │ {:G} │ " << format("{:G}", value).pad_right(32) << " │" << environment::new_line; + console::out << "│ " << text.pad_right(45) << " │ {:o} │ " << format("{:o}", value).pad_right(32) << " │" << environment::new_line; + console::out << "│ " << text.pad_right(45) << " │ {:o2} │ " << format("{:o2}", value).pad_right(32) << " │" << environment::new_line; + console::out << "│ " << text.pad_right(45) << " │ {:O} │ " << format("{:O}", value).pad_right(32) << " │" << environment::new_line; + console::out << "│ " << text.pad_right(45) << " │ {:O2} │ " << format("{:O2}", value).pad_right(32) << " │" << environment::new_line; + console::out << "│ " << text.pad_right(45) << " │ {:x} │ " << format("{:x}", value).pad_right(32) << " │" << environment::new_line; + console::out << "│ " << text.pad_right(45) << " │ {:x2} │ " << format("{:x2}", value).pad_right(32) << " │" << environment::new_line; + console::out << "│ " << text.pad_right(45) << " │ {:X} │ " << format("{:X}", value).pad_right(32) << " │" << environment::new_line; + console::out << "│ " << text.pad_right(45) << " │ {:X2} │ " << format("{:X2}", value).pad_right(32) << " │" << environment::new_line; + + if (c != cap::end) + console::out << "├───────────────────────────────────────────────┼────────────┼──────────────────────────────────┤" << environment::new_line; + else + console::out << "└───────────────────────────────────────────────┴────────────┴──────────────────────────────────┘" << environment::new_line; +} + auto main() -> int { - console::out << string::format("{}", text_styles::bold | text_styles::italic) << environment::new_line; - console::out << string::format("0b{:b}", text_styles::bold | text_styles::italic) << environment::new_line; - console::out << string::format("0b{:B}", text_styles::bold | text_styles::italic) << environment::new_line; - console::out << string::format("{:d}", text_styles::bold | text_styles::italic) << environment::new_line; - console::out << string::format("{:D}", text_styles::bold | text_styles::italic) << environment::new_line; - console::out << string::format("{:g}", text_styles::bold | text_styles::italic) << environment::new_line; - console::out << string::format("{:G}", text_styles::bold | text_styles::italic) << environment::new_line; - console::out << string::format("0{:o}", text_styles::bold | text_styles::italic) << environment::new_line; - console::out << string::format("0{:O}", text_styles::bold | text_styles::italic) << environment::new_line; - console::out << string::format("0x{:x}", text_styles::bold | text_styles::italic) << environment::new_line; - console::out << string::format("0x{:X}", text_styles::bold | text_styles::italic) << environment::new_line; + print_text_styles("text_styles::normal", text_styles::normal, cap::title); + print_text_styles("text_styles::bold|text_styles::italic", text_styles::bold|text_styles::italic, cap::middle); + print_text_styles("text_styles::strikeout", text_styles::strikeout, cap::end); } // This code produces the following output : // -// saturday -// 0b101 -// 0b101 -// 5 -// 5 -// saturday -// saturday -// 05 -// 05 -// 0x5 -// 0x5 +// ┌───────────────────────────────────────────────┬────────────┬──────────────────────────────────┐ +// │ text_styles │ format │ representation │ +// ├───────────────────────────────────────────────┼────────────┼──────────────────────────────────┤ +// │ text_styles::normal │ {} │ normal │ +// │ text_styles::normal │ {:b} │ 0 │ +// │ text_styles::normal │ {:b4} │ 0000 │ +// │ text_styles::normal │ {:B} │ 0 │ +// │ text_styles::normal │ {:B4} │ 0000 │ +// │ text_styles::normal │ {:d} │ 0 │ +// │ text_styles::normal │ {:d1} │ 0 │ +// │ text_styles::normal │ {:D} │ 0 │ +// │ text_styles::normal │ {:D1} │ 0 │ +// │ text_styles::normal │ {:g} │ normal │ +// │ text_styles::normal │ {:G} │ normal │ +// │ text_styles::normal │ {:o} │ 0 │ +// │ text_styles::normal │ {:o2} │ 00 │ +// │ text_styles::normal │ {:O} │ 0 │ +// │ text_styles::normal │ {:O2} │ 00 │ +// │ text_styles::normal │ {:x} │ 0 │ +// │ text_styles::normal │ {:x2} │ 00 │ +// │ text_styles::normal │ {:X} │ 0 │ +// │ text_styles::normal │ {:X2} │ 00 │ +// ├───────────────────────────────────────────────┼────────────┼──────────────────────────────────┤ +// │ text_styles::bold|text_styles::italic │ {} │ bold, italic │ +// │ text_styles::bold|text_styles::italic │ {:b} │ 11 │ +// │ text_styles::bold|text_styles::italic │ {:b4} │ 0011 │ +// │ text_styles::bold|text_styles::italic │ {:B} │ 11 │ +// │ text_styles::bold|text_styles::italic │ {:B4} │ 0011 │ +// │ text_styles::bold|text_styles::italic │ {:d} │ 3 │ +// │ text_styles::bold|text_styles::italic │ {:d1} │ 3 │ +// │ text_styles::bold|text_styles::italic │ {:D} │ 3 │ +// │ text_styles::bold|text_styles::italic │ {:D1} │ 3 │ +// │ text_styles::bold|text_styles::italic │ {:g} │ bold, italic │ +// │ text_styles::bold|text_styles::italic │ {:G} │ bold, italic │ +// │ text_styles::bold|text_styles::italic │ {:o} │ 3 │ +// │ text_styles::bold|text_styles::italic │ {:o2} │ 03 │ +// │ text_styles::bold|text_styles::italic │ {:O} │ 3 │ +// │ text_styles::bold|text_styles::italic │ {:O2} │ 03 │ +// │ text_styles::bold|text_styles::italic │ {:x} │ 3 │ +// │ text_styles::bold|text_styles::italic │ {:x2} │ 03 │ +// │ text_styles::bold|text_styles::italic │ {:X} │ 3 │ +// │ text_styles::bold|text_styles::italic │ {:X2} │ 03 │ +// ├───────────────────────────────────────────────┼────────────┼──────────────────────────────────┤ +// │ text_styles::strikeout │ {} │ strikeout │ +// │ text_styles::strikeout │ {:b} │ 1000 │ +// │ text_styles::strikeout │ {:b4} │ 1000 │ +// │ text_styles::strikeout │ {:B} │ 1000 │ +// │ text_styles::strikeout │ {:B4} │ 1000 │ +// │ text_styles::strikeout │ {:d} │ 8 │ +// │ text_styles::strikeout │ {:d1} │ 8 │ +// │ text_styles::strikeout │ {:D} │ 8 │ +// │ text_styles::strikeout │ {:D1} │ 8 │ +// │ text_styles::strikeout │ {:g} │ strikeout │ +// │ text_styles::strikeout │ {:G} │ strikeout │ +// │ text_styles::strikeout │ {:o} │ 10 │ +// │ text_styles::strikeout │ {:o2} │ 10 │ +// │ text_styles::strikeout │ {:O} │ 10 │ +// │ text_styles::strikeout │ {:O2} │ 10 │ +// │ text_styles::strikeout │ {:x} │ 8 │ +// │ text_styles::strikeout │ {:x2} │ 08 │ +// │ text_styles::strikeout │ {:X} │ 8 │ +// │ text_styles::strikeout │ {:X2} │ 08 │ +// └───────────────────────────────────────────────┴────────────┴──────────────────────────────────┘ diff --git a/examples/xtd.core.examples/format/format_enum_class_flags_without_helper/README.md b/examples/xtd.core.examples/format/format_enum_class_flags_without_helper/README.md index dcf545940979..f2fada0037ce 100644 --- a/examples/xtd.core.examples/format/format_enum_class_flags_without_helper/README.md +++ b/examples/xtd.core.examples/format/format_enum_class_flags_without_helper/README.md @@ -19,16 +19,68 @@ xtdc run # Output (with colors) ``` -saturday -0b101 -0b101 -5 -5 -saturday -saturday -05 -05 -0x5 -0x5 +┌───────────────────────────────────────────────┬────────────┬──────────────────────────────────┐ +│ text_styles │ format │ representation │ +├───────────────────────────────────────────────┼────────────┼──────────────────────────────────┤ +│ text_styles::normal │ {} │ normal │ +│ text_styles::normal │ {:b} │ 0 │ +│ text_styles::normal │ {:b4} │ 0000 │ +│ text_styles::normal │ {:B} │ 0 │ +│ text_styles::normal │ {:B4} │ 0000 │ +│ text_styles::normal │ {:d} │ 0 │ +│ text_styles::normal │ {:d1} │ 0 │ +│ text_styles::normal │ {:D} │ 0 │ +│ text_styles::normal │ {:D1} │ 0 │ +│ text_styles::normal │ {:g} │ normal │ +│ text_styles::normal │ {:G} │ normal │ +│ text_styles::normal │ {:o} │ 0 │ +│ text_styles::normal │ {:o2} │ 00 │ +│ text_styles::normal │ {:O} │ 0 │ +│ text_styles::normal │ {:O2} │ 00 │ +│ text_styles::normal │ {:x} │ 0 │ +│ text_styles::normal │ {:x2} │ 00 │ +│ text_styles::normal │ {:X} │ 0 │ +│ text_styles::normal │ {:X2} │ 00 │ +├───────────────────────────────────────────────┼────────────┼──────────────────────────────────┤ +│ text_styles::bold|text_styles::italic │ {} │ bold, italic │ +│ text_styles::bold|text_styles::italic │ {:b} │ 11 │ +│ text_styles::bold|text_styles::italic │ {:b4} │ 0011 │ +│ text_styles::bold|text_styles::italic │ {:B} │ 11 │ +│ text_styles::bold|text_styles::italic │ {:B4} │ 0011 │ +│ text_styles::bold|text_styles::italic │ {:d} │ 3 │ +│ text_styles::bold|text_styles::italic │ {:d1} │ 3 │ +│ text_styles::bold|text_styles::italic │ {:D} │ 3 │ +│ text_styles::bold|text_styles::italic │ {:D1} │ 3 │ +│ text_styles::bold|text_styles::italic │ {:g} │ bold, italic │ +│ text_styles::bold|text_styles::italic │ {:G} │ bold, italic │ +│ text_styles::bold|text_styles::italic │ {:o} │ 3 │ +│ text_styles::bold|text_styles::italic │ {:o2} │ 03 │ +│ text_styles::bold|text_styles::italic │ {:O} │ 3 │ +│ text_styles::bold|text_styles::italic │ {:O2} │ 03 │ +│ text_styles::bold|text_styles::italic │ {:x} │ 3 │ +│ text_styles::bold|text_styles::italic │ {:x2} │ 03 │ +│ text_styles::bold|text_styles::italic │ {:X} │ 3 │ +│ text_styles::bold|text_styles::italic │ {:X2} │ 03 │ +├───────────────────────────────────────────────┼────────────┼──────────────────────────────────┤ +│ text_styles::strikeout │ {} │ strikeout │ +│ text_styles::strikeout │ {:b} │ 1000 │ +│ text_styles::strikeout │ {:b4} │ 1000 │ +│ text_styles::strikeout │ {:B} │ 1000 │ +│ text_styles::strikeout │ {:B4} │ 1000 │ +│ text_styles::strikeout │ {:d} │ 8 │ +│ text_styles::strikeout │ {:d1} │ 8 │ +│ text_styles::strikeout │ {:D} │ 8 │ +│ text_styles::strikeout │ {:D1} │ 8 │ +│ text_styles::strikeout │ {:g} │ strikeout │ +│ text_styles::strikeout │ {:G} │ strikeout │ +│ text_styles::strikeout │ {:o} │ 10 │ +│ text_styles::strikeout │ {:o2} │ 10 │ +│ text_styles::strikeout │ {:O} │ 10 │ +│ text_styles::strikeout │ {:O2} │ 10 │ +│ text_styles::strikeout │ {:x} │ 8 │ +│ text_styles::strikeout │ {:x2} │ 08 │ +│ text_styles::strikeout │ {:X} │ 8 │ +│ text_styles::strikeout │ {:X2} │ 08 │ +└───────────────────────────────────────────────┴────────────┴──────────────────────────────────┘ ``` diff --git a/examples/xtd.core.examples/format/format_enum_class_flags_without_helper/src/format_enum_class_flags_without_helper.cpp b/examples/xtd.core.examples/format/format_enum_class_flags_without_helper/src/format_enum_class_flags_without_helper.cpp index 35a8e2f0a233..b47aab79ae9e 100644 --- a/examples/xtd.core.examples/format/format_enum_class_flags_without_helper/src/format_enum_class_flags_without_helper.cpp +++ b/examples/xtd.core.examples/format/format_enum_class_flags_without_helper/src/format_enum_class_flags_without_helper.cpp @@ -2,7 +2,7 @@ #include #include #include -#include +#include using namespace xtd; @@ -27,30 +27,109 @@ template<> struct xtd::enum_register { explicit operator auto() const noexcept {return xtd::enum_collection {{text_styles::normal, "normal"}, {text_styles::bold, "bold"}, {text_styles::italic, "italic"}, {text_styles::underline, "underline"}, {text_styles::strikeout, "strikeout"}};} }; +enum class cap {title, middle, end}; + +auto print_text_styles(const string& text, text_styles value, cap c) { + if (c == cap::title) + console::out + << "┌───────────────────────────────────────────────┬────────────┬──────────────────────────────────┐" << environment::new_line + << "│ text_styles │ format │ representation │" << environment::new_line + << "├───────────────────────────────────────────────┼────────────┼──────────────────────────────────┤" << environment::new_line; + + console::out << "│ " << text.pad_right(45) << " │ {} │ " << format("{}", value).pad_right(32) << " │" << environment::new_line; + console::out << "│ " << text.pad_right(45) << " │ {:b} │ " << format("{:b}", value).pad_right(32) << " │" << environment::new_line; + console::out << "│ " << text.pad_right(45) << " │ {:b4} │ " << format("{:b4}", value).pad_right(32) << " │" << environment::new_line; + console::out << "│ " << text.pad_right(45) << " │ {:B} │ " << format("{:B}", value).pad_right(32) << " │" << environment::new_line; + console::out << "│ " << text.pad_right(45) << " │ {:B4} │ " << format("{:B4}", value).pad_right(32) << " │" << environment::new_line; + console::out << "│ " << text.pad_right(45) << " │ {:d} │ " << format("{:d}", value).pad_right(32) << " │" << environment::new_line; + console::out << "│ " << text.pad_right(45) << " │ {:d1} │ " << format("{:d1}", value).pad_right(32) << " │" << environment::new_line; + console::out << "│ " << text.pad_right(45) << " │ {:D} │ " << format("{:D}", value).pad_right(32) << " │" << environment::new_line; + console::out << "│ " << text.pad_right(45) << " │ {:D1} │ " << format("{:D1}", value).pad_right(32) << " │" << environment::new_line; + console::out << "│ " << text.pad_right(45) << " │ {:g} │ " << format("{:g}", value).pad_right(32) << " │" << environment::new_line; + console::out << "│ " << text.pad_right(45) << " │ {:G} │ " << format("{:G}", value).pad_right(32) << " │" << environment::new_line; + console::out << "│ " << text.pad_right(45) << " │ {:o} │ " << format("{:o}", value).pad_right(32) << " │" << environment::new_line; + console::out << "│ " << text.pad_right(45) << " │ {:o2} │ " << format("{:o2}", value).pad_right(32) << " │" << environment::new_line; + console::out << "│ " << text.pad_right(45) << " │ {:O} │ " << format("{:O}", value).pad_right(32) << " │" << environment::new_line; + console::out << "│ " << text.pad_right(45) << " │ {:O2} │ " << format("{:O2}", value).pad_right(32) << " │" << environment::new_line; + console::out << "│ " << text.pad_right(45) << " │ {:x} │ " << format("{:x}", value).pad_right(32) << " │" << environment::new_line; + console::out << "│ " << text.pad_right(45) << " │ {:x2} │ " << format("{:x2}", value).pad_right(32) << " │" << environment::new_line; + console::out << "│ " << text.pad_right(45) << " │ {:X} │ " << format("{:X}", value).pad_right(32) << " │" << environment::new_line; + console::out << "│ " << text.pad_right(45) << " │ {:X2} │ " << format("{:X2}", value).pad_right(32) << " │" << environment::new_line; + + if (c != cap::end) + console::out << "├───────────────────────────────────────────────┼────────────┼──────────────────────────────────┤" << environment::new_line; + else + console::out << "└───────────────────────────────────────────────┴────────────┴──────────────────────────────────┘" << environment::new_line; +} + auto main() -> int { - console::out << string::format("{}", text_styles::bold | text_styles::italic) << environment::new_line; - console::out << string::format("0b{:b}", text_styles::bold | text_styles::italic) << environment::new_line; - console::out << string::format("0b{:B}", text_styles::bold | text_styles::italic) << environment::new_line; - console::out << string::format("{:d}", text_styles::bold | text_styles::italic) << environment::new_line; - console::out << string::format("{:D}", text_styles::bold | text_styles::italic) << environment::new_line; - console::out << string::format("{:g}", text_styles::bold | text_styles::italic) << environment::new_line; - console::out << string::format("{:G}", text_styles::bold | text_styles::italic) << environment::new_line; - console::out << string::format("0{:o}", text_styles::bold | text_styles::italic) << environment::new_line; - console::out << string::format("0{:O}", text_styles::bold | text_styles::italic) << environment::new_line; - console::out << string::format("0x{:x}", text_styles::bold | text_styles::italic) << environment::new_line; - console::out << string::format("0x{:X}", text_styles::bold | text_styles::italic) << environment::new_line; + print_text_styles("text_styles::normal", text_styles::normal, cap::title); + print_text_styles("text_styles::bold|text_styles::italic", text_styles::bold|text_styles::italic, cap::middle); + print_text_styles("text_styles::strikeout", text_styles::strikeout, cap::end); } // This code produces the following output : // -// saturday -// 0b101 -// 0b101 -// 5 -// 5 -// saturday -// saturday -// 05 -// 05 -// 0x5 -// 0x5 +// ┌───────────────────────────────────────────────┬────────────┬──────────────────────────────────┐ +// │ text_styles │ format │ representation │ +// ├───────────────────────────────────────────────┼────────────┼──────────────────────────────────┤ +// │ text_styles::normal │ {} │ normal │ +// │ text_styles::normal │ {:b} │ 0 │ +// │ text_styles::normal │ {:b4} │ 0000 │ +// │ text_styles::normal │ {:B} │ 0 │ +// │ text_styles::normal │ {:B4} │ 0000 │ +// │ text_styles::normal │ {:d} │ 0 │ +// │ text_styles::normal │ {:d1} │ 0 │ +// │ text_styles::normal │ {:D} │ 0 │ +// │ text_styles::normal │ {:D1} │ 0 │ +// │ text_styles::normal │ {:g} │ normal │ +// │ text_styles::normal │ {:G} │ normal │ +// │ text_styles::normal │ {:o} │ 0 │ +// │ text_styles::normal │ {:o2} │ 00 │ +// │ text_styles::normal │ {:O} │ 0 │ +// │ text_styles::normal │ {:O2} │ 00 │ +// │ text_styles::normal │ {:x} │ 0 │ +// │ text_styles::normal │ {:x2} │ 00 │ +// │ text_styles::normal │ {:X} │ 0 │ +// │ text_styles::normal │ {:X2} │ 00 │ +// ├───────────────────────────────────────────────┼────────────┼──────────────────────────────────┤ +// │ text_styles::bold|text_styles::italic │ {} │ bold, italic │ +// │ text_styles::bold|text_styles::italic │ {:b} │ 11 │ +// │ text_styles::bold|text_styles::italic │ {:b4} │ 0011 │ +// │ text_styles::bold|text_styles::italic │ {:B} │ 11 │ +// │ text_styles::bold|text_styles::italic │ {:B4} │ 0011 │ +// │ text_styles::bold|text_styles::italic │ {:d} │ 3 │ +// │ text_styles::bold|text_styles::italic │ {:d1} │ 3 │ +// │ text_styles::bold|text_styles::italic │ {:D} │ 3 │ +// │ text_styles::bold|text_styles::italic │ {:D1} │ 3 │ +// │ text_styles::bold|text_styles::italic │ {:g} │ bold, italic │ +// │ text_styles::bold|text_styles::italic │ {:G} │ bold, italic │ +// │ text_styles::bold|text_styles::italic │ {:o} │ 3 │ +// │ text_styles::bold|text_styles::italic │ {:o2} │ 03 │ +// │ text_styles::bold|text_styles::italic │ {:O} │ 3 │ +// │ text_styles::bold|text_styles::italic │ {:O2} │ 03 │ +// │ text_styles::bold|text_styles::italic │ {:x} │ 3 │ +// │ text_styles::bold|text_styles::italic │ {:x2} │ 03 │ +// │ text_styles::bold|text_styles::italic │ {:X} │ 3 │ +// │ text_styles::bold|text_styles::italic │ {:X2} │ 03 │ +// ├───────────────────────────────────────────────┼────────────┼──────────────────────────────────┤ +// │ text_styles::strikeout │ {} │ strikeout │ +// │ text_styles::strikeout │ {:b} │ 1000 │ +// │ text_styles::strikeout │ {:b4} │ 1000 │ +// │ text_styles::strikeout │ {:B} │ 1000 │ +// │ text_styles::strikeout │ {:B4} │ 1000 │ +// │ text_styles::strikeout │ {:d} │ 8 │ +// │ text_styles::strikeout │ {:d1} │ 8 │ +// │ text_styles::strikeout │ {:D} │ 8 │ +// │ text_styles::strikeout │ {:D1} │ 8 │ +// │ text_styles::strikeout │ {:g} │ strikeout │ +// │ text_styles::strikeout │ {:G} │ strikeout │ +// │ text_styles::strikeout │ {:o} │ 10 │ +// │ text_styles::strikeout │ {:o2} │ 10 │ +// │ text_styles::strikeout │ {:O} │ 10 │ +// │ text_styles::strikeout │ {:O2} │ 10 │ +// │ text_styles::strikeout │ {:x} │ 8 │ +// │ text_styles::strikeout │ {:x2} │ 08 │ +// │ text_styles::strikeout │ {:X} │ 8 │ +// │ text_styles::strikeout │ {:X2} │ 08 │ +// └───────────────────────────────────────────────┴────────────┴──────────────────────────────────┘ diff --git a/examples/xtd.core.examples/format/format_exception/README.md b/examples/xtd.core.examples/format/format_exception/README.md index 99da7a216ecb..72398a83b1db 100644 --- a/examples/xtd.core.examples/format/format_exception/README.md +++ b/examples/xtd.core.examples/format/format_exception/README.md @@ -19,11 +19,15 @@ xtdc run # Output (with colors) ``` -exception: std::exception -exception: Invvalid argument -xtd::system_exception : System exception - at main [0x00005620] in /Users/gammasoft71/Projects/xtd/build/xtd.examples/xtd.core.examples/format/format_exception/Debug/format_exception:line 0 -xtd::argument_out_of_range_exception : Argument out of range exception - at main [0x00005620] in /Users/gammasoft71/Projects/xtd/build/xtd.examples/xtd.core.examples/format/format_exception/Debug/format_exception:line 0 +1 : Jean-Luc Picard (Captain) +2 : Jean-Luc Picard +xtd::format_exception : The "B" value is not valid format. + at character::to_string(xtd::basic_string, std::allocator> const&, std::locale const&) const in /Users/gammasoft/Projects/xtd/examples/xtd.core.examples/format/format_exception/src/format_exception.cpp:line 22 + at xtd::iformatable::__opague_internal_formatable__(long, long, long, long) const in iformatable.cpp:line 7 + at void __basic_string_extract_format_arg(std::basic_string, std::allocator>&, unsigned long&, std::vector<__format_information, std::allocator<__format_information>>&, character&) in basic_string_.hpp:line 365 + at void __basic_string_extract_format_arg(xtd::basic_string, std::allocator>&, std::vector<__format_information, std::allocator<__format_information>>&, character&) in basic_string_.hpp:line 387 + at xtd::basic_string, std::allocator> xtd::basic_string, std::allocator>::format(xtd::basic_string, std::allocator> const&, character&) in basic_string_.hpp:line 328 + at void xtd::println(char const*, character&) in println.hpp:line 34 + at main in format_exception.cpp:line 34 ``` diff --git a/examples/xtd.core.examples/format/format_exception/src/format_exception.cpp b/examples/xtd.core.examples/format/format_exception/src/format_exception.cpp index 969481395c22..1dbdb540ff60 100644 --- a/examples/xtd.core.examples/format/format_exception/src/format_exception.cpp +++ b/examples/xtd.core.examples/format/format_exception/src/format_exception.cpp @@ -1,23 +1,51 @@ -#include #include -#include -#include -#include +#include +#include using namespace xtd; +class character : public iformatable { +public: + character() = default; + character(const string& name, const string& rank) noexcept : name_(name), rank_(rank) {} + + const string& name() const noexcept {return name_;} + const string& rank() const noexcept {return rank_;} + + string to_string() const noexcept {return to_string("", std::locale {});} + string to_string(const string& format, const std::locale& loc) const override { + auto fmt = string::is_empty(format) ? "F" : format; + if (fmt == "F") return name_ + " (" + rank_ + ")"; + if (fmt == "N") return name_; + if (fmt == "R") return rank_; + throw format_exception {xtd::format("The \"{}\" value is not valid format.", fmt)}; + } + +private: + string name_; + string rank_; +}; + auto main() -> int { - console::out << string::format("{}", std::exception()) << environment::new_line; - console::out << string::format("{}", std::invalid_argument("Invalid argument")) << environment::new_line; - console::out << string::format("{}", system_exception("System exception")) << environment::new_line; - console::out << string::format("{}", argument_out_of_range_exception("Argument out of range exception")) << environment::new_line; + try { + auto char1 = character {"Jean-Luc Picard", "Captain"}; + println("1 : {}", char1); + println("2 : {:N}", char1); + println("2 : {:B}", char1); + } catch (const exception& e) { + println(e.to_string()); + } } -// This code produces the following output : +// This code can produce the following output : // -// exception: std::exception -// exception: Invalid argument -// xtd::system_exception : System exception -// at main [0x00005620] in /Users/gammasoft71/Projects/xtd/build/xtd.examples/xtd.core.examples/format/format_exception/Debug/format_exception:line 0 -// xtd::argument_out_of_range_exception : Argument out of range exception -// at main [0x00005620] in /Users/gammasoft71/Projects/xtd/build/xtd.examples/xtd.core.examples/format/format_exception/Debug/format_exception:line 0 +// 1 : Jean-Luc Picard (Captain) +// 2 : Jean-Luc Picard +// xtd::format_exception : The "B" value is not valid format. +// at character::to_string(xtd::basic_string, std::allocator> const&, std::locale const&) const in /Users/gammasoft/Projects/xtd/examples/xtd.core.examples/format/format_exception/src/format_exception.cpp:line 22 +// at xtd::iformatable::__opague_internal_formatable__(long, long, long, long) const in iformatable.cpp:line 7 +// at void __basic_string_extract_format_arg(std::basic_string, std::allocator>&, unsigned long&, std::vector<__format_information, std::allocator<__format_information>>&, character&) in basic_string_.hpp:line 365 +// at void __basic_string_extract_format_arg(xtd::basic_string, std::allocator>&, std::vector<__format_information, std::allocator<__format_information>>&, character&) in basic_string_.hpp:line 387 +// at xtd::basic_string, std::allocator> xtd::basic_string, std::allocator>::format(xtd::basic_string, std::allocator> const&, character&) in basic_string_.hpp:line 328 +// at void xtd::println(char const*, character&) in println.hpp:line 34 +// at main in format_exception.cpp:line 34