Tracker: search for the localized decimal separator
Now that string_for_size return localized numbers, we can't assume the decimal separator is a dot. Fixes: #18900 Change-Id: I872d75b0e9e4eb5d085e04bfd4e8c26101a5b1b3 Reviewed-on: https://review.haiku-os.org/c/haiku/+/7671 Reviewed-by: waddlesplash <[email protected]> Reviewed-by: Adrien Destugues <[email protected]> Tested-by: Commit checker robot <[email protected]>
This commit is contained in:
committed by
Adrien Destugues
parent
c110a061f1
commit
446ff222af
@@ -50,6 +50,7 @@ All rights reserved.
|
|||||||
#include <Debug.h>
|
#include <Debug.h>
|
||||||
#include <Locale.h>
|
#include <Locale.h>
|
||||||
#include <NodeInfo.h>
|
#include <NodeInfo.h>
|
||||||
|
#include <NumberFormat.h>
|
||||||
#include <Path.h>
|
#include <Path.h>
|
||||||
#include <StringFormat.h>
|
#include <StringFormat.h>
|
||||||
#include <StringForSize.h>
|
#include <StringForSize.h>
|
||||||
@@ -102,15 +103,12 @@ TruncFileSizeBase(BString* outString, int64 value, const View* view,
|
|||||||
} else {
|
} else {
|
||||||
// strip off an insignificant zero so we don't get readings
|
// strip off an insignificant zero so we don't get readings
|
||||||
// such as 1.00
|
// such as 1.00
|
||||||
char* period = 0;
|
BNumberFormat numberFormat;
|
||||||
for (char* tmp = const_cast<char*>(buffer.String()); *tmp != '\0'; tmp++) {
|
BString separator(numberFormat.GetSeparator(B_DECIMAL_SEPARATOR));
|
||||||
if (*tmp == '.')
|
if (!separator.IsEmpty()) {
|
||||||
period = tmp;
|
int32 position = buffer.FindFirst(separator);
|
||||||
}
|
if (position != B_ERROR && buffer.ByteAt(position + 2) == '0')
|
||||||
if (period && period[1] && period[2] == '0') {
|
buffer.Remove(position + 2, 1);
|
||||||
// move the rest of the string over the insignificant zero
|
|
||||||
for (char* tmp = &period[2]; *tmp; tmp++)
|
|
||||||
*tmp = tmp[1];
|
|
||||||
}
|
}
|
||||||
float resultWidth = view->StringWidth(buffer);
|
float resultWidth = view->StringWidth(buffer);
|
||||||
if (resultWidth <= width) {
|
if (resultWidth <= width) {
|
||||||
|
|||||||
Reference in New Issue
Block a user