mirror of
https://github.com/godotengine/godot.git
synced 2024-12-15 10:12:40 +08:00
Merge pull request #32546 from Xrayez/bind-string-humanize-size
Bind the `String::humanize_size` method
This commit is contained in:
commit
11bbe152a9
@ -3298,7 +3298,7 @@ static int _humanize_digits(int p_num) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
String String::humanize_size(size_t p_size) {
|
||||
String String::humanize_size(uint64_t p_size) {
|
||||
|
||||
uint64_t _div = 1;
|
||||
Vector<String> prefixes;
|
||||
|
@ -322,7 +322,7 @@ public:
|
||||
String path_to_file(const String &p_path) const;
|
||||
String get_base_dir() const;
|
||||
String get_file() const;
|
||||
static String humanize_size(size_t p_size);
|
||||
static String humanize_size(uint64_t p_size);
|
||||
String simplify_path() const;
|
||||
|
||||
String xml_escape(bool p_escape_quotes = false) const;
|
||||
|
@ -284,6 +284,7 @@ struct _VariantCall {
|
||||
VCALL_LOCALMEM0R(String, sha1_buffer);
|
||||
VCALL_LOCALMEM0R(String, sha256_buffer);
|
||||
VCALL_LOCALMEM0R(String, empty);
|
||||
VCALL_LOCALMEM1R(String, humanize_size);
|
||||
VCALL_LOCALMEM0R(String, is_abs_path);
|
||||
VCALL_LOCALMEM0R(String, is_rel_path);
|
||||
VCALL_LOCALMEM0R(String, get_base_dir);
|
||||
@ -1561,6 +1562,7 @@ void register_variant_methods() {
|
||||
ADDFUNC0R(STRING, POOL_BYTE_ARRAY, String, sha1_buffer, varray());
|
||||
ADDFUNC0R(STRING, POOL_BYTE_ARRAY, String, sha256_buffer, varray());
|
||||
ADDFUNC0R(STRING, BOOL, String, empty, varray());
|
||||
ADDFUNC1R(STRING, STRING, String, humanize_size, INT, "size", varray());
|
||||
ADDFUNC0R(STRING, BOOL, String, is_abs_path, varray());
|
||||
ADDFUNC0R(STRING, BOOL, String, is_rel_path, varray());
|
||||
ADDFUNC0R(STRING, STRING, String, get_base_dir, varray());
|
||||
|
@ -437,6 +437,20 @@
|
||||
[/codeblock]
|
||||
</description>
|
||||
</method>
|
||||
<method name="humanize_size">
|
||||
<return type="String">
|
||||
</return>
|
||||
<argument index="0" name="size" type="int">
|
||||
</argument>
|
||||
<description>
|
||||
Converts [code]size[/code] represented as number of bytes to human-readable format using internationalized set of data size units, namely: B, KiB, MiB, GiB, TiB, PiB, EiB. Note that the next smallest unit is picked automatically to hold at most 1024 units.
|
||||
[codeblock]
|
||||
var bytes = 133790307
|
||||
var size = String.humanize_size(bytes)
|
||||
print(size) # prints "127.5 MiB"
|
||||
[/codeblock]
|
||||
</description>
|
||||
</method>
|
||||
<method name="insert">
|
||||
<return type="String">
|
||||
</return>
|
||||
|
Loading…
Reference in New Issue
Block a user