Imported StringForSize utility function from Haiku. To be removed when
WebPositive is integrated into the Haiku source tree. git-svn-id: http://svn.haiku-os.org/webpositive/webkit/trunk@351 94f232f2-1747-11df-bad5-a5bfde151594
This commit is contained in:
committed by
Alexandre Deckner
parent
7ac6b59c33
commit
7998882116
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* Copyright 2010 Haiku Inc. All rights reserved.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
|
||||
#include "StringForSize.h"
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
|
||||
namespace BPrivate {
|
||||
|
||||
|
||||
const char*
|
||||
string_for_size(double size, char* string, size_t stringSize)
|
||||
{
|
||||
double kib = size / 1024.0;
|
||||
if (kib < 1.0) {
|
||||
snprintf(string, stringSize, "%d bytes", (int)size);
|
||||
return string;
|
||||
}
|
||||
double mib = kib / 1024.0;
|
||||
if (mib < 1.0) {
|
||||
snprintf(string, stringSize, "%3.2f KiB", kib);
|
||||
return string;
|
||||
}
|
||||
double gib = mib / 1024.0;
|
||||
if (gib < 1.0) {
|
||||
snprintf(string, stringSize, "%3.2f MiB", mib);
|
||||
return string;
|
||||
}
|
||||
double tib = gib / 1024.0;
|
||||
if (tib < 1.0) {
|
||||
snprintf(string, stringSize, "%3.2f GiB", gib);
|
||||
return string;
|
||||
}
|
||||
snprintf(string, stringSize, "%.2f TiB", tib);
|
||||
return string;
|
||||
}
|
||||
|
||||
|
||||
} // namespace BPrivate
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
/*
|
||||
* Copyright 2010 Haiku Inc. All rights reserved.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
#ifndef STRING_FOR_SIZE_H
|
||||
#define STRING_FOR_SIZE_H
|
||||
|
||||
#include <SupportDefs.h>
|
||||
|
||||
|
||||
namespace BPrivate {
|
||||
|
||||
|
||||
const char* string_for_size(double size, char* string, size_t stringSize);
|
||||
|
||||
|
||||
} // namespace BPrivate
|
||||
|
||||
|
||||
using BPrivate::string_for_size;
|
||||
|
||||
|
||||
#endif // COLOR_QUANTIZER_H
|
||||
Reference in New Issue
Block a user