From 799888211608ea8a3bed35e72d4f24e4da25f6ca Mon Sep 17 00:00:00 2001 From: stippi Date: Wed, 24 Mar 2010 20:19:40 +0000 Subject: [PATCH] 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 --- .../webpositive/support/StringForSize.cpp | 43 +++++++++++++++++++ src/apps/webpositive/support/StringForSize.h | 23 ++++++++++ 2 files changed, 66 insertions(+) create mode 100644 src/apps/webpositive/support/StringForSize.cpp create mode 100644 src/apps/webpositive/support/StringForSize.h diff --git a/src/apps/webpositive/support/StringForSize.cpp b/src/apps/webpositive/support/StringForSize.cpp new file mode 100644 index 0000000000..ae7831e397 --- /dev/null +++ b/src/apps/webpositive/support/StringForSize.cpp @@ -0,0 +1,43 @@ +/* + * Copyright 2010 Haiku Inc. All rights reserved. + * Distributed under the terms of the MIT License. + */ + +#include "StringForSize.h" + +#include + + +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 + diff --git a/src/apps/webpositive/support/StringForSize.h b/src/apps/webpositive/support/StringForSize.h new file mode 100644 index 0000000000..fa3e13b115 --- /dev/null +++ b/src/apps/webpositive/support/StringForSize.h @@ -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 + + +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