Author: stippi Date: Wed Mar 24 20:19:40 2010 New Revision: 351 URL: http://mmlr.dyndns.org/changeset/351 Log: Imported StringForSize utility function from Haiku. To be removed when WebPositive is integrated into the Haiku source tree. Added: webkit/trunk/WebKit/haiku/WebPositive/support/StringForSize.cpp webkit/trunk/WebKit/haiku/WebPositive/support/StringForSize.h Added: webkit/trunk/WebKit/haiku/WebPositive/support/StringForSize.cpp ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ webkit/trunk/WebKit/haiku/WebPositive/support/StringForSize.cpp Wed Mar 24 20:19:40 2010 (r351) @@ -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 + Added: webkit/trunk/WebKit/haiku/WebPositive/support/StringForSize.h ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ webkit/trunk/WebKit/haiku/WebPositive/support/StringForSize.h Wed Mar 24 20:19:40 2010 (r351) @@ -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