#include <xtd/console>
#include <xtd/environment>
#include <xtd/format>
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_;
}
private:
string name_;
string rank_;
};
enum class cap {title, middle, end};
auto print_character(const string& text, const character& value, cap c) {
if (c == cap::title)
console::out
<< "┌───────────────────────────────────────────────┬────────────┬──────────────────────────────────────────┐" << environment::new_line
<< "│ character │ format │ representation │" << environment::new_line
<< "├───────────────────────────────────────────────┼────────────┼──────────────────────────────────────────┤" << environment::new_line;
console::out <<
"│ " <<
text.pad_right(45) <<
" │ {} │ " <<
format(
"{}", value).
pad_right(40) <<
" │" << environment::new_line;
console::out <<
"│ " <<
text.pad_right(45) <<
" │ {:F} │ " <<
format(
"{:F}", value).
pad_right(40) <<
" │" << environment::new_line;
console::out <<
"│ " <<
text.pad_right(45) <<
" │ {:N} │ " <<
format(
"{:N}", value).
pad_right(40) <<
" │" << environment::new_line;
console::out <<
"│ " <<
text.pad_right(45) <<
" │ {:R} │ " <<
format(
"{:R}", value).
pad_right(40) <<
" │" << environment::new_line;
if (c != cap::end)
console::out << "├───────────────────────────────────────────────┼────────────┼──────────────────────────────────────────┤" << environment::new_line;
else
console::out << "└───────────────────────────────────────────────┴────────────┴──────────────────────────────────────────┘" << environment::new_line;
}
auto main() -> int {
print_character("{}", character {}, cap::title);
print_character("{\"Jean-Luc Picard\", \"Captain\"}", character {"Jean-Luc Picard", "Captain"}, cap::middle);
print_character("{\"William Riker\", \"Commander\"}", character {"William Riker", "Commander"}, cap::middle);
print_character("{\"Data\", \"Commander\"}", character {"Data", "Commander"}, cap::middle);
print_character("{\"Beverly Crusher\", \"Commander\"}", character {"Beverly Crusher", "Commander"}, cap::middle);
print_character("{\"Geordi La Forge\", \"Lieutenant Commander\"}", character {"Geordi La Forge", "Lieutenant Commander"}, cap::middle);
print_character("{\"Worf\", \"Lieutenant Commander\"}", character {"Worf", "Lieutenant Commander"}, cap::middle);
print_character("{\"Tasha Yar\", \"Lieutenant\"}", character {"Tasha Yar", "Lieutenant"}, cap::end);
}
basic_string pad_right(xtd::size total_width) const noexcept
Left-aligns the characters in this basic_string, padding with spaces on the right for a specified tot...
Definition basic_string.hpp:1597
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition xtd_about_box.hpp:10