Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef UI_BASE_TEXT_BYTES_FORMATTING_H_ | |
| 6 #define UI_BASE_TEXT_BYTES_FORMATTING_H_ | |
| 7 #pragma once | |
| 8 | |
| 9 #include "base/basictypes.h" | |
| 10 #include "base/string16.h" | |
| 11 | |
| 12 namespace ui { | |
| 13 | |
| 14 enum DataUnits { | |
| 15 DATA_UNITS_NATURAL = -1, | |
| 16 DATA_UNITS_BYTE = 0, | |
| 17 DATA_UNITS_KIBIBYTE, | |
| 18 DATA_UNITS_MEBIBYTE, | |
| 19 DATA_UNITS_GIBIBYTE, | |
| 20 DATA_UNITS_TEBIBYTE, | |
| 21 DATA_UNITS_PEBIBYTE | |
| 22 }; | |
| 23 | |
| 24 // Return the unit type that is appropriate for displaying the amount of bytes | |
| 25 // passed in. Most of the time, an explicit call to this isn't necessary; just | |
| 26 // use the DATA_UNITS_NATURAL argument to FormatBytes()/FormatSpeed(). | |
| 27 DataUnits GetByteDisplayUnits(int64 bytes); | |
| 28 | |
| 29 // Return a byte string in human-readable format with an optional unit suffix. | |
| 30 // Specify a |units| argument to explictly request the units to be used, or pass | |
| 31 // in DATA_UNITS_NATURAL to have the units to match the scale of the |bytes| | |
| 32 // argument (the value that GetBytesDisplayUnits() would return). | |
| 33 // Ex: FormatBytes(512, DATA_UNITS_KIBIBYTE, true) => "0.5 KB" | |
| 34 // Ex: FormatBytes(10*1024, DATA_UNITS_MEBIBYTE, false) => "0.1" | |
| 35 string16 FormatBytes(int64 bytes, DataUnits units, bool show_units); | |
|
Evan Stade
2011/06/21 03:18:41
I think there should be a version of this function
Avi (use Gerrit)
2011/06/21 14:30:19
As a tweak later, perhaps; for now I think this is
Evan Stade
2011/06/21 22:10:57
I don't think this "tweak" will ever be more relev
Avi (use Gerrit)
2011/06/21 22:20:07
Working on it. Just a moment...
| |
| 36 | |
| 37 // As above, but with "/s" units. | |
| 38 // Ex: FormatSpeed(512, DATA_UNITS_KIBIBYTE, true) => "0.5 KB/s" | |
|
Evan Stade
2011/06/21 03:18:41
should the k be lower case?
Avi (use Gerrit)
2011/06/21 14:30:19
Done.
| |
| 39 // Ex: FormatSpeed(10*1024, DATA_UNITS_MEBIBYTE, false) => "0.1" | |
| 40 string16 FormatSpeed(int64 bytes, DataUnits units, bool show_units); | |
| 41 | |
| 42 } // namespace ui | |
| 43 | |
| 44 #endif // UI_BASE_TEXT_BYTES_FORMATTING_H_ | |
| OLD | NEW |