#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);
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);
}
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;
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);
}
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;
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);
}
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;
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);
}
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;
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);
}
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;
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);
}
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;
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);
}