improve names to fix errors

This commit is contained in:
Thomas Fussell 2016-07-03 11:34:44 -04:00
parent d92ad1ab9c
commit 54c08246ce
2 changed files with 54 additions and 53 deletions

View File

@ -141,7 +141,7 @@ const std::unordered_map<int, std::string> known_locales()
return *all; return *all;
} }
bool condition::satisfied_by(long double number) const bool format_condition::satisfied_by(long double number) const
{ {
switch (type) switch (type)
{ {
@ -199,9 +199,9 @@ void number_format_parser::parse()
throw std::runtime_error("bad format"); throw std::runtime_error("bad format");
case number_format_token::token_type::color: case number_format_token::token_type::color:
if (section.color != bracket_color::none if (section.color != format_color::none
|| section.condition.type != condition::condition_type::none || section.condition.type != format_condition::condition_type::none
|| section.locale != locale::none || section.locale != format_locale::none
|| !section.parts.empty()) || !section.parts.empty())
{ {
throw std::runtime_error("color should be the first part of a format"); throw std::runtime_error("color should be the first part of a format");
@ -212,7 +212,7 @@ void number_format_parser::parse()
case number_format_token::token_type::locale: case number_format_token::token_type::locale:
{ {
if (section.locale != locale::none) if (section.locale != format_locale::none)
{ {
throw std::runtime_error("multiple locales"); throw std::runtime_error("multiple locales");
} }
@ -233,7 +233,7 @@ void number_format_parser::parse()
case number_format_token::token_type::condition: case number_format_token::token_type::condition:
{ {
if (section.condition.type != condition::condition_type::none) if (section.condition.type != format_condition::condition_type::none)
{ {
throw std::runtime_error("multiple conditions"); throw std::runtime_error("multiple conditions");
} }
@ -244,17 +244,17 @@ void number_format_parser::parse()
{ {
if (token.string[1] == '=') if (token.string[1] == '=')
{ {
section.condition.type = condition::condition_type::less_or_equal; section.condition.type = format_condition::condition_type::less_or_equal;
value = token.string.substr(2); value = token.string.substr(2);
} }
else if (token.string[1] == '>') else if (token.string[1] == '>')
{ {
section.condition.type = condition::condition_type::not_equal; section.condition.type = format_condition::condition_type::not_equal;
value = token.string.substr(2); value = token.string.substr(2);
} }
else else
{ {
section.condition.type = condition::condition_type::less_than; section.condition.type = format_condition::condition_type::less_than;
value = token.string.substr(1); value = token.string.substr(1);
} }
} }
@ -262,18 +262,18 @@ void number_format_parser::parse()
{ {
if (token.string[1] == '=') if (token.string[1] == '=')
{ {
section.condition.type = condition::condition_type::greater_or_equal; section.condition.type = format_condition::condition_type::greater_or_equal;
value = token.string.substr(2); value = token.string.substr(2);
} }
else else
{ {
section.condition.type = condition::condition_type::greater_than; section.condition.type = format_condition::condition_type::greater_than;
value = token.string.substr(1); value = token.string.substr(1);
} }
} }
else if (token.string.front() == '=') else if (token.string.front() == '=')
{ {
section.condition.type = condition::condition_type::equal; section.condition.type = format_condition::condition_type::equal;
value = token.string.substr(1); value = token.string.substr(1);
} }
@ -706,32 +706,32 @@ void number_format_parser::validate()
if (codes_.size() > 2) if (codes_.size() > 2)
{ {
if (codes_[0].condition.type != condition::condition_type::none && if (codes_[0].condition.type != format_condition::condition_type::none &&
codes_[1].condition.type != condition::condition_type::none && codes_[1].condition.type != format_condition::condition_type::none &&
codes_[2].condition.type != condition::condition_type::none) codes_[2].condition.type != format_condition::condition_type::none)
{ {
throw std::runtime_error("format should have a maximum of two codes with conditions"); throw std::runtime_error("format should have a maximum of two codes with conditions");
} }
} }
} }
placeholders number_format_parser::parse_placeholders(const std::string &placeholders_string) format_placeholders number_format_parser::parse_placeholders(const std::string &placeholders_string)
{ {
placeholders p; format_placeholders p;
if (placeholders_string == "General") if (placeholders_string == "General")
{ {
p.type = placeholders::placeholders_type::general; p.type = format_placeholders::placeholders_type::general;
return p; return p;
} }
else if (placeholders_string == "@") else if (placeholders_string == "@")
{ {
p.type = placeholders::placeholders_type::text; p.type = format_placeholders::placeholders_type::text;
return p; return p;
} }
else if (placeholders_string.front() == '.') else if (placeholders_string.front() == '.')
{ {
p.type = placeholders::placeholders_type::fractional_part; p.type = format_placeholders::placeholders_type::fractional_part;
} }
std::vector<std::size_t> comma_indices; std::vector<std::size_t> comma_indices;
@ -775,14 +775,14 @@ placeholders number_format_parser::parse_placeholders(const std::string &placeho
return p; return p;
} }
bracket_color number_format_parser::color_from_string(const std::string &color) format_color number_format_parser::color_from_string(const std::string &color)
{ {
switch (color[0]) switch (color[0])
{ {
case 'C': case 'C':
if (color == "Cyan") if (color == "Cyan")
{ {
return bracket_color::cyan; return format_color::cyan;
} }
else if (color.substr(0, 5) == "Color") else if (color.substr(0, 5) == "Color")
{ {
@ -790,50 +790,50 @@ bracket_color number_format_parser::color_from_string(const std::string &color)
if (color_number >= 1 && color_number <= 56) if (color_number >= 1 && color_number <= 56)
{ {
return static_cast<bracket_color>(color_number); return static_cast<format_color>(color_number);
} }
} }
case 'B': case 'B':
if (color == "Black") if (color == "Black")
{ {
return bracket_color::black; return format_color::black;
} }
else if (color == "Blue") else if (color == "Blue")
{ {
return bracket_color::blue; return format_color::blue;
} }
case 'G': case 'G':
if (color == "Green") if (color == "Green")
{ {
return bracket_color::black; return format_color::black;
} }
case 'W': case 'W':
if (color == "White") if (color == "White")
{ {
return bracket_color::white; return format_color::white;
} }
case 'M': case 'M':
if (color == "Magenta") if (color == "Magenta")
{ {
return bracket_color::white; return format_color::white;
} }
return bracket_color::magenta; return format_color::magenta;
case 'Y': case 'Y':
if (color == "Yellow") if (color == "Yellow")
{ {
return bracket_color::white; return format_color::white;
} }
case 'R': case 'R':
if (color == "Red") if (color == "Red")
{ {
return bracket_color::white; return format_color::white;
} }
default: default:
throw std::runtime_error("bad color: " + color); throw std::runtime_error("bad color: " + color);
} }
} }
std::pair<locale, std::string> number_format_parser::locale_from_string(const std::string &locale_string) std::pair<format_locale, std::string> number_format_parser::locale_from_string(const std::string &locale_string)
{ {
auto hyphen_index = locale_string.find('-'); auto hyphen_index = locale_string.find('-');
@ -842,7 +842,7 @@ std::pair<locale, std::string> number_format_parser::locale_from_string(const st
throw std::runtime_error("bad locale: " + locale_string); throw std::runtime_error("bad locale: " + locale_string);
} }
std::pair<locale, std::string> result; std::pair<format_locale, std::string> result;
if (hyphen_index > 1) if (hyphen_index > 1)
{ {
@ -870,7 +870,7 @@ std::pair<locale, std::string> number_format_parser::locale_from_string(const st
{ {
if (known_locale.first == country_code) if (known_locale.first == country_code)
{ {
result.first = static_cast<locale>(country_code); result.first = static_cast<format_locale>(country_code);
return result; return result;
} }
} }
@ -888,7 +888,7 @@ number_formatter::number_formatter(const std::string &format_string, xlnt::calen
std::string number_formatter::format_number(long double number) std::string number_formatter::format_number(long double number)
{ {
if (format_[0].condition.type != condition::condition_type::none) if (format_[0].condition.type != format_condition::condition_type::none)
{ {
if (format_[0].condition.satisfied_by(number)) if (format_[0].condition.satisfied_by(number))
{ {
@ -900,7 +900,8 @@ std::string number_formatter::format_number(long double number)
return std::string(11, '#'); return std::string(11, '#');
} }
if (format_[1].condition.type == condition::condition_type::none || format_[1].condition.satisfied_by(number)) if (format_[1].condition.type == format_condition::condition_type::none
|| format_[1].condition.satisfied_by(number))
{ {
return format_number(format_[1], number); return format_number(format_[1], number);
} }
@ -960,9 +961,9 @@ std::string number_formatter::format_text(const std::string &text)
return format_text(format_[3], text); return format_text(format_[3], text);
} }
std::string number_formatter::fill_placeholders(const placeholders &p, long double number) std::string number_formatter::fill_placeholders(const format_placeholders &p, long double number)
{ {
if (p.type == placeholders::placeholders_type::general) if (p.type == format_placeholders::placeholders_type::general)
{ {
auto result = std::to_string(number); auto result = std::to_string(number);
@ -981,7 +982,7 @@ std::string number_formatter::fill_placeholders(const placeholders &p, long doub
auto integer_part = static_cast<int>(number); auto integer_part = static_cast<int>(number);
if (p.type != placeholders::placeholders_type::fractional_part) if (p.type != format_placeholders::placeholders_type::fractional_part)
{ {
auto result = std::to_string(integer_part); auto result = std::to_string(integer_part);
@ -1194,8 +1195,8 @@ std::string number_formatter::format_text(const format_code &format, const std::
break; break;
case template_part::template_type::general: case template_part::template_type::general:
if (part.placeholders.type == placeholders::placeholders_type::general if (part.placeholders.type == format_placeholders::placeholders_type::general
|| part.placeholders.type == placeholders::placeholders_type::text) || part.placeholders.type == format_placeholders::placeholders_type::text)
{ {
result.append(text); result.append(text);
} }

View File

@ -32,7 +32,7 @@
namespace xlnt { namespace xlnt {
namespace detail { namespace detail {
enum class bracket_color enum class format_color
{ {
none, none,
black, black,
@ -101,7 +101,7 @@ enum class bracket_color
color56 color56
}; };
enum class locale enum class format_locale
{ {
none = 0, none = 0,
arabic_saudi_arabia = 0x401, arabic_saudi_arabia = 0x401,
@ -211,7 +211,7 @@ enum class locale
arabic_qatar = 0x4001 arabic_qatar = 0x4001
}; };
struct condition struct format_condition
{ {
enum class condition_type enum class condition_type
{ {
@ -229,7 +229,7 @@ struct condition
bool satisfied_by(long double number) const; bool satisfied_by(long double number) const;
}; };
struct placeholders struct format_placeholders
{ {
enum class placeholders_type enum class placeholders_type
{ {
@ -308,14 +308,14 @@ struct template_part
} type = template_type::bad; } type = template_type::bad;
std::string string; std::string string;
placeholders placeholders; format_placeholders placeholders;
}; };
struct format_code struct format_code
{ {
bracket_color color = bracket_color::none; format_color color = format_color::none;
locale locale = locale::none; format_locale locale = format_locale::none;
condition condition; format_condition condition;
bool is_datetime = false; bool is_datetime = false;
bool is_timedelta = false; bool is_timedelta = false;
bool twelve_hour = false; bool twelve_hour = false;
@ -336,9 +336,9 @@ private:
number_format_token parse_next_token(); number_format_token parse_next_token();
placeholders parse_placeholders(const std::string &placeholders_string); format_placeholders parse_placeholders(const std::string &placeholders_string);
bracket_color color_from_string(const std::string &color); format_color color_from_string(const std::string &color);
std::pair<locale, std::string> locale_from_string(const std::string &locale_string); std::pair<format_locale, std::string> locale_from_string(const std::string &locale_string);
std::size_t position_ = 0; std::size_t position_ = 0;
std::string format_string_; std::string format_string_;
@ -353,7 +353,7 @@ public:
std::string format_text(const std::string &text); std::string format_text(const std::string &text);
private: private:
std::string fill_placeholders(const placeholders &p, long double number); std::string fill_placeholders(const format_placeholders &p, long double number);
std::string format_number(const format_code &format, long double number); std::string format_number(const format_code &format, long double number);
std::string format_text(const format_code &format, const std::string &text); std::string format_text(const format_code &format, const std::string &text);