RemoteDrawingEngine: Reduce RP_READ_BITMAP result timeout.
[haiku.git] / src / kits / shared / StringForSize.cpp
blob3a308ef23942b8b7855321958c347b7d727e6713
1 /*
2 * Copyright 2010 Haiku Inc. All rights reserved.
3 * Distributed under the terms of the MIT License.
4 */
6 #include "StringForSize.h"
8 #include <stdio.h>
10 #include <MessageFormat.h>
11 #include <SystemCatalog.h>
13 using BPrivate::gSystemCatalog;
16 #undef B_TRANSLATION_CONTEXT
17 #define B_TRANSLATION_CONTEXT "StringForSize"
20 namespace BPrivate {
23 const char*
24 string_for_size(double size, char* string, size_t stringSize)
26 double kib = size / 1024.0;
27 if (kib < 1.0) {
28 const char* trKey = B_TRANSLATE_MARK(
29 "{0, plural, one{# byte} other{# bytes}}");
31 BString tmp;
32 BMessageFormat format(
33 gSystemCatalog.GetString(trKey, B_TRANSLATION_CONTEXT));
34 format.Format(tmp, (int)size);
36 strlcpy(string, tmp.String(), stringSize);
37 return string;
39 double mib = kib / 1024.0;
40 if (mib < 1.0) {
41 const char* trKey = B_TRANSLATE_MARK("%3.2f KiB");
42 snprintf(string, stringSize, gSystemCatalog.GetString(trKey,
43 B_TRANSLATION_CONTEXT), kib);
44 return string;
46 double gib = mib / 1024.0;
47 if (gib < 1.0) {
48 const char* trKey = B_TRANSLATE_MARK("%3.2f MiB");
49 snprintf(string, stringSize, gSystemCatalog.GetString(trKey,
50 B_TRANSLATION_CONTEXT), mib);
51 return string;
53 double tib = gib / 1024.0;
54 if (tib < 1.0) {
55 const char* trKey = B_TRANSLATE_MARK("%3.2f GiB");
56 snprintf(string, stringSize, gSystemCatalog.GetString(trKey,
57 B_TRANSLATION_CONTEXT), gib);
58 return string;
60 const char* trKey = B_TRANSLATE_MARK("%.2f TiB");
61 snprintf(string, stringSize, gSystemCatalog.GetString(trKey,
62 B_TRANSLATION_CONTEXT), tib);
63 return string;
67 } // namespace BPrivate