From 8f296924d35887bfaa0a894b94cb5082a9329648 Mon Sep 17 00:00:00 2001 From: Guilherme Maciel Ferreira Date: Tue, 1 Feb 2011 15:15:01 +0100 Subject: [PATCH] Renamed enumeration items to improve readability --- src/stringfunc.cpp | 9 ++++----- src/stringfunc.hxx | 16 ++++++++-------- test/stringfunc.cpp | 26 +++++++++++++------------- 3 files changed, 25 insertions(+), 26 deletions(-) diff --git a/src/stringfunc.cpp b/src/stringfunc.cpp index def77a7..fc5ae60 100644 --- a/src/stringfunc.cpp +++ b/src/stringfunc.cpp @@ -919,16 +919,15 @@ const string symbolFormatLong[MAX_SYMBOL_FORMATS] = { " YBytes" }; - string nice_unit_format( const int64_t input, - const UnitSystem system, - const UnitSymbolFormat symbolformat + const UnitBase system, + const UnitFormat symbolformat ) { // select the system of units (decimal or binary) int multiple = 0; - if (system == US_SI) + if (system == UnitBase1000) { multiple = 1000; } @@ -958,7 +957,7 @@ string nice_unit_format( // format the input number, placing the appropriate symbol ostringstream out; out.setf (ios::fixed); - if (symbolformat == USF_SHORT) + if (symbolformat == ShortUnitFormat) { out.precision(1); out << size << i18n( symbolFormatShort[sizecount].c_str() ); diff --git a/src/stringfunc.hxx b/src/stringfunc.hxx index 4c544ca..ca45bd4 100644 --- a/src/stringfunc.hxx +++ b/src/stringfunc.hxx @@ -192,20 +192,20 @@ using I2n::to_upper; #endif -enum UnitSystem { - US_SI, // SI decimal, composed by multiples of 1000 (KB, MB, etc.) - US_IEC // IEC binary, composed by multiples of 1024 (KiB, MiB, etc. ) +enum UnitBase { + UnitBase1000, // SI decimal, composed by multiples of 1000 (KB, MB, etc.) + UnitBase1024 // IEC binary, composed by multiples of 1024 (KiB, MiB, etc. ) }; -enum UnitSymbolFormat { - USF_SHORT, // B, KB, MB, ... - USF_LONG // Byte, KByte, MByte, ... +enum UnitFormat { + ShortUnitFormat, // B, KB, MB, ... + LongUnitFormat // Byte, KByte, MByte, ... }; std::string nice_unit_format( const int64_t input, - const UnitSystem system = US_SI, - const UnitSymbolFormat symbolformat = USF_LONG + const UnitBase system = UnitBase1000, + const UnitFormat symbolformat = LongUnitFormat ); bool replace_all(std::string &base, const std::string *ist, const std::string *soll); diff --git a/test/stringfunc.cpp b/test/stringfunc.cpp index 3fcbeab..e379bc1 100644 --- a/test/stringfunc.cpp +++ b/test/stringfunc.cpp @@ -114,7 +114,7 @@ BOOST_AUTO_TEST_CASE(nice_unit_format1) string output = nice_unit_format(two_bytes); BOOST_CHECK_EQUAL(string("2.00 Bytes"), output); - output = nice_unit_format(two_bytes, US_IEC, USF_SHORT); + output = nice_unit_format(two_bytes, UnitBase1024, ShortUnitFormat); BOOST_CHECK_EQUAL(string("2.0 B"), output); } @@ -125,7 +125,7 @@ BOOST_AUTO_TEST_CASE(nice_unit_format2) string output = nice_unit_format(two_kilobytes); BOOST_CHECK_EQUAL(string("2.00 KBytes"), output); - output = nice_unit_format(two_kilobytes, US_IEC, USF_SHORT); + output = nice_unit_format(two_kilobytes, UnitBase1024, ShortUnitFormat); BOOST_CHECK_EQUAL(string("2.0 KB"), output); const int64_t two_and_half_kilobytes = 2500; @@ -133,7 +133,7 @@ BOOST_AUTO_TEST_CASE(nice_unit_format2) output = nice_unit_format(two_and_half_kilobytes); BOOST_CHECK_EQUAL(string("2.50 KBytes"), output); - output = nice_unit_format(two_and_half_kilobytes, US_IEC, USF_SHORT); + output = nice_unit_format(two_and_half_kilobytes, UnitBase1024, ShortUnitFormat); BOOST_CHECK_EQUAL(string("2.4 KB"), output); } @@ -144,7 +144,7 @@ BOOST_AUTO_TEST_CASE(nice_unit_format3) string output = nice_unit_format(two_megabytes); BOOST_CHECK_EQUAL(string("2.00 MBytes"), output); - output = nice_unit_format(two_megabytes, US_IEC, USF_SHORT); + output = nice_unit_format(two_megabytes, UnitBase1024, ShortUnitFormat); BOOST_CHECK_EQUAL(string("1.9 MB"), output); const int64_t two_and_half_megabytes = 2500000; @@ -152,7 +152,7 @@ BOOST_AUTO_TEST_CASE(nice_unit_format3) output = nice_unit_format(two_and_half_megabytes); BOOST_CHECK_EQUAL(string("2.50 MBytes"), output); - output = nice_unit_format(two_and_half_megabytes, US_IEC, USF_SHORT); + output = nice_unit_format(two_and_half_megabytes, UnitBase1024, ShortUnitFormat); BOOST_CHECK_EQUAL(string("2.4 MB"), output); } @@ -164,7 +164,7 @@ BOOST_AUTO_TEST_CASE(nice_unit_format4) string output = nice_unit_format(two_gigabytes); BOOST_CHECK_EQUAL(string("2.00 GBytes"), output); - output = nice_unit_format(two_gigabytes, US_IEC, USF_SHORT); + output = nice_unit_format(two_gigabytes, UnitBase1024, ShortUnitFormat); BOOST_CHECK_EQUAL(string("1.9 GB"), output); const int64_t two_and_half_gigabytes = 2500000000LL; @@ -172,7 +172,7 @@ BOOST_AUTO_TEST_CASE(nice_unit_format4) output = nice_unit_format(two_and_half_gigabytes); BOOST_CHECK_EQUAL(string("2.50 GBytes"), output); - output = nice_unit_format(two_and_half_gigabytes, US_IEC, USF_SHORT); + output = nice_unit_format(two_and_half_gigabytes, UnitBase1024, ShortUnitFormat); BOOST_CHECK_EQUAL(string("2.3 GB"), output); } @@ -183,7 +183,7 @@ BOOST_AUTO_TEST_CASE(nice_unit_format5) string output = nice_unit_format(two_terabytes); BOOST_CHECK_EQUAL(string("2.00 TBytes"), output); - output = nice_unit_format(two_terabytes, US_IEC, USF_SHORT); + output = nice_unit_format(two_terabytes, UnitBase1024, ShortUnitFormat); BOOST_CHECK_EQUAL(string("1.8 TB"), output); const int64_t two_and_half_terabytes = 2500000000000LL; @@ -191,7 +191,7 @@ BOOST_AUTO_TEST_CASE(nice_unit_format5) output = nice_unit_format(two_and_half_terabytes); BOOST_CHECK_EQUAL(string("2.50 TBytes"), output); - output = nice_unit_format(two_and_half_terabytes, US_IEC, USF_SHORT); + output = nice_unit_format(two_and_half_terabytes, UnitBase1024, ShortUnitFormat); BOOST_CHECK_EQUAL(string("2.3 TB"), output); } @@ -202,7 +202,7 @@ BOOST_AUTO_TEST_CASE(nice_unit_format6) string output = nice_unit_format(two_petabytes); BOOST_CHECK_EQUAL(string("2.00 PBytes"), output); - output = nice_unit_format(two_petabytes, US_IEC, USF_SHORT); + output = nice_unit_format(two_petabytes, UnitBase1024, ShortUnitFormat); BOOST_CHECK_EQUAL(string("1.8 PB"), output); const int64_t two_and_half_petabytes = 2500000000000000LL; @@ -210,7 +210,7 @@ BOOST_AUTO_TEST_CASE(nice_unit_format6) output = nice_unit_format(two_and_half_petabytes); BOOST_CHECK_EQUAL(string("2.50 PBytes"), output); - output = nice_unit_format(two_and_half_petabytes, US_IEC, USF_SHORT); + output = nice_unit_format(two_and_half_petabytes, UnitBase1024, ShortUnitFormat); BOOST_CHECK_EQUAL(string("2.2 PB"), output); } @@ -221,7 +221,7 @@ BOOST_AUTO_TEST_CASE(nice_unit_format7) string output = nice_unit_format(two_exabytes); BOOST_CHECK_EQUAL(string("2.00 EBytes"), output); - output = nice_unit_format(two_exabytes, US_IEC, USF_SHORT); + output = nice_unit_format(two_exabytes, UnitBase1024, ShortUnitFormat); BOOST_CHECK_EQUAL(string("1.7 EB"), output); const int64_t two_and_half_exabytes = 2500000000000000000LL; @@ -229,7 +229,7 @@ BOOST_AUTO_TEST_CASE(nice_unit_format7) output = nice_unit_format(two_and_half_exabytes); BOOST_CHECK_EQUAL(string("2.50 EBytes"), output); - output = nice_unit_format(two_and_half_exabytes, US_IEC, USF_SHORT); + output = nice_unit_format(two_and_half_exabytes, UnitBase1024, ShortUnitFormat); BOOST_CHECK_EQUAL(string("2.2 EB"), output); } -- 1.7.1