summaryrefslogtreecommitdiffstats
path: root/base
diff options
context:
space:
mode:
Diffstat (limited to 'base')
-rw-r--r--base/string_util.cc46
-rw-r--r--base/string_util.h6
-rw-r--r--base/string_util_unittest.cc44
3 files changed, 48 insertions, 48 deletions
diff --git a/base/string_util.cc b/base/string_util.cc
index 917d9a9..4dbcd7b 100644
--- a/base/string_util.cc
+++ b/base/string_util.cc
@@ -652,27 +652,27 @@ DataUnits GetByteDisplayUnits(int64 bytes) {
// TODO(mpcomplete): deal with locale
// Byte suffixes. This must match the DataUnits enum.
-static const wchar_t* const kByteStrings[] = {
- L"B",
- L"kB",
- L"MB",
- L"GB"
+static const char* const kByteStrings[] = {
+ "B",
+ "kB",
+ "MB",
+ "GB"
};
-static const wchar_t* const kSpeedStrings[] = {
- L"B/s",
- L"kB/s",
- L"MB/s",
- L"GB/s"
+static const char* const kSpeedStrings[] = {
+ "B/s",
+ "kB/s",
+ "MB/s",
+ "GB/s"
};
-std::wstring FormatBytesInternal(int64 bytes,
- DataUnits units,
- bool show_units,
- const wchar_t* const* suffix) {
+string16 FormatBytesInternal(int64 bytes,
+ DataUnits units,
+ bool show_units,
+ const char* const* suffix) {
if (bytes < 0) {
NOTREACHED() << "Negative bytes value";
- return std::wstring();
+ return string16();
}
DCHECK(units >= DATA_UNITS_BYTE && units <= DATA_UNITS_GIBIBYTE);
@@ -682,26 +682,26 @@ std::wstring FormatBytesInternal(int64 bytes,
for (int i = 0; i < units; ++i)
unit_amount /= 1024.0;
- wchar_t buf[64];
+ char buf[64];
if (bytes != 0 && units != DATA_UNITS_BYTE && unit_amount < 100)
- base::swprintf(buf, arraysize(buf), L"%.1lf", unit_amount);
+ base::snprintf(buf, arraysize(buf), "%.1lf", unit_amount);
else
- base::swprintf(buf, arraysize(buf), L"%.0lf", unit_amount);
+ base::snprintf(buf, arraysize(buf), "%.0lf", unit_amount);
- std::wstring ret(buf);
+ std::string ret(buf);
if (show_units) {
- ret += L" ";
+ ret += " ";
ret += suffix[units];
}
- return ret;
+ return ASCIIToUTF16(ret);
}
-std::wstring FormatBytes(int64 bytes, DataUnits units, bool show_units) {
+string16 FormatBytes(int64 bytes, DataUnits units, bool show_units) {
return FormatBytesInternal(bytes, units, show_units, kByteStrings);
}
-std::wstring FormatSpeed(int64 bytes, DataUnits units, bool show_units) {
+string16 FormatSpeed(int64 bytes, DataUnits units, bool show_units) {
return FormatBytesInternal(bytes, units, show_units, kSpeedStrings);
}
diff --git a/base/string_util.h b/base/string_util.h
index 1b657ad..ae8b93c 100644
--- a/base/string_util.h
+++ b/base/string_util.h
@@ -424,16 +424,16 @@ DataUnits GetByteDisplayUnits(int64 bytes);
// specified by 'units', with an optional unit suffix.
// Ex: FormatBytes(512, DATA_UNITS_KIBIBYTE, true) => "0.5 KB"
// Ex: FormatBytes(10*1024, DATA_UNITS_MEBIBYTE, false) => "0.1"
-std::wstring FormatBytes(int64 bytes, DataUnits units, bool show_units);
+string16 FormatBytes(int64 bytes, DataUnits units, bool show_units);
// As above, but with "/s" units.
// Ex: FormatSpeed(512, DATA_UNITS_KIBIBYTE, true) => "0.5 KB/s"
// Ex: FormatSpeed(10*1024, DATA_UNITS_MEBIBYTE, false) => "0.1"
-std::wstring FormatSpeed(int64 bytes, DataUnits units, bool show_units);
+string16 FormatSpeed(int64 bytes, DataUnits units, bool show_units);
// Return a number formated with separators in the user's locale way.
// Ex: FormatNumber(1234567) => 1,234,567
-std::wstring FormatNumber(int64 number);
+string16 FormatNumber(int64 number);
// Starting at |start_offset| (usually 0), replace the first instance of
// |find_this| with |replace_with|.
diff --git a/base/string_util_unittest.cc b/base/string_util_unittest.cc
index 9f72b1f..8a8fc39 100644
--- a/base/string_util_unittest.cc
+++ b/base/string_util_unittest.cc
@@ -530,8 +530,8 @@ TEST(StringUtilTest, FormatBytes) {
static const struct {
int64 bytes;
DataUnits units;
- const wchar_t* expected;
- const wchar_t* expected_with_units;
+ const char* expected;
+ const char* expected_with_units;
} cases[] = {
// Expected behavior: we show one post-decimal digit when we have
// under two pre-decimal digits, except in cases where it makes no
@@ -539,35 +539,35 @@ TEST(StringUtilTest, FormatBytes) {
// Since we switch units once we cross the 1000 mark, this keeps
// the display of file sizes or bytes consistently around three
// digits.
- {0, DATA_UNITS_BYTE, L"0", L"0 B"},
- {512, DATA_UNITS_BYTE, L"512", L"512 B"},
- {512, DATA_UNITS_KIBIBYTE, L"0.5", L"0.5 kB"},
- {1024*1024, DATA_UNITS_KIBIBYTE, L"1024", L"1024 kB"},
- {1024*1024, DATA_UNITS_MEBIBYTE, L"1.0", L"1.0 MB"},
- {1024*1024*1024, DATA_UNITS_GIBIBYTE, L"1.0", L"1.0 GB"},
- {10LL*1024*1024*1024, DATA_UNITS_GIBIBYTE, L"10.0", L"10.0 GB"},
- {99LL*1024*1024*1024, DATA_UNITS_GIBIBYTE, L"99.0", L"99.0 GB"},
- {105LL*1024*1024*1024, DATA_UNITS_GIBIBYTE, L"105", L"105 GB"},
+ {0, DATA_UNITS_BYTE, "0", "0 B"},
+ {512, DATA_UNITS_BYTE, "512", "512 B"},
+ {512, DATA_UNITS_KIBIBYTE, "0.5", "0.5 kB"},
+ {1024*1024, DATA_UNITS_KIBIBYTE, "1024", "1024 kB"},
+ {1024*1024, DATA_UNITS_MEBIBYTE, "1.0", "1.0 MB"},
+ {1024*1024*1024, DATA_UNITS_GIBIBYTE, "1.0", "1.0 GB"},
+ {10LL*1024*1024*1024, DATA_UNITS_GIBIBYTE, "10.0", "10.0 GB"},
+ {99LL*1024*1024*1024, DATA_UNITS_GIBIBYTE, "99.0", "99.0 GB"},
+ {105LL*1024*1024*1024, DATA_UNITS_GIBIBYTE, "105", "105 GB"},
{105LL*1024*1024*1024 + 500LL*1024*1024, DATA_UNITS_GIBIBYTE,
- L"105", L"105 GB"},
- {~(1LL<<63), DATA_UNITS_GIBIBYTE, L"8589934592", L"8589934592 GB"},
+ "105", "105 GB"},
+ {~(1LL<<63), DATA_UNITS_GIBIBYTE, "8589934592", "8589934592 GB"},
- {99*1024 + 103, DATA_UNITS_KIBIBYTE, L"99.1", L"99.1 kB"},
- {1024*1024 + 103, DATA_UNITS_KIBIBYTE, L"1024", L"1024 kB"},
- {1024*1024 + 205 * 1024, DATA_UNITS_MEBIBYTE, L"1.2", L"1.2 MB"},
+ {99*1024 + 103, DATA_UNITS_KIBIBYTE, "99.1", "99.1 kB"},
+ {1024*1024 + 103, DATA_UNITS_KIBIBYTE, "1024", "1024 kB"},
+ {1024*1024 + 205 * 1024, DATA_UNITS_MEBIBYTE, "1.2", "1.2 MB"},
{1024*1024*1024 + (927 * 1024*1024), DATA_UNITS_GIBIBYTE,
- L"1.9", L"1.9 GB"},
- {10LL*1024*1024*1024, DATA_UNITS_GIBIBYTE, L"10.0", L"10.0 GB"},
- {100LL*1024*1024*1024, DATA_UNITS_GIBIBYTE, L"100", L"100 GB"},
+ "1.9", "1.9 GB"},
+ {10LL*1024*1024*1024, DATA_UNITS_GIBIBYTE, "10.0", "10.0 GB"},
+ {100LL*1024*1024*1024, DATA_UNITS_GIBIBYTE, "100", "100 GB"},
#ifdef NDEBUG
- {-1, DATA_UNITS_BYTE, L"", L""},
+ {-1, DATA_UNITS_BYTE, "", ""},
#endif
};
for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); ++i) {
- EXPECT_EQ(cases[i].expected,
+ EXPECT_EQ(ASCIIToUTF16(cases[i].expected),
FormatBytes(cases[i].bytes, cases[i].units, false));
- EXPECT_EQ(cases[i].expected_with_units,
+ EXPECT_EQ(ASCIIToUTF16(cases[i].expected_with_units),
FormatBytes(cases[i].bytes, cases[i].units, true));
}
}