Remove more Locale Kit cruft.
BNumberFormat is the way to go for all of this. This code was not even compiled in.
This commit is contained in:
@@ -10,7 +10,6 @@
|
|||||||
#include <FormatImpl.h>
|
#include <FormatImpl.h>
|
||||||
#include <FormatParameters.h>
|
#include <FormatParameters.h>
|
||||||
#include <FormattingConventions.h>
|
#include <FormattingConventions.h>
|
||||||
#include <GenericNumberFormat.h>
|
|
||||||
#include <Language.h>
|
#include <Language.h>
|
||||||
#include <Locale.h>
|
#include <Locale.h>
|
||||||
#include <NumberFormat.h>
|
#include <NumberFormat.h>
|
||||||
|
|||||||
@@ -1,157 +0,0 @@
|
|||||||
#ifndef _B_GENERIC_NUMBER_FORMAT_H_
|
|
||||||
#define _B_GENERIC_NUMBER_FORMAT_H_
|
|
||||||
|
|
||||||
#include <IntegerFormatParameters.h>
|
|
||||||
|
|
||||||
class BString;
|
|
||||||
struct format_field_position;
|
|
||||||
|
|
||||||
class BGenericNumberFormat {
|
|
||||||
public:
|
|
||||||
BGenericNumberFormat();
|
|
||||||
~BGenericNumberFormat();
|
|
||||||
|
|
||||||
status_t FormatInteger(const BIntegerFormatParameters *parameters,
|
|
||||||
int64 number, BString *buffer,
|
|
||||||
format_field_position *positions = NULL,
|
|
||||||
int32 positionCount = 1,
|
|
||||||
int32 *fieldCount = NULL,
|
|
||||||
bool allFieldPositions = false) const;
|
|
||||||
|
|
||||||
status_t FormatInteger(const BIntegerFormatParameters *parameters,
|
|
||||||
int64 number, char *buffer, size_t bufferSize,
|
|
||||||
format_field_position *positions = NULL,
|
|
||||||
int32 positionCount = 1,
|
|
||||||
int32 *fieldCount = NULL,
|
|
||||||
bool allFieldPositions = false) const;
|
|
||||||
|
|
||||||
status_t FormatInteger(const BIntegerFormatParameters *parameters,
|
|
||||||
uint64 number, BString *buffer,
|
|
||||||
format_field_position *positions = NULL,
|
|
||||||
int32 positionCount = 1,
|
|
||||||
int32 *fieldCount = NULL,
|
|
||||||
bool allFieldPositions = false) const;
|
|
||||||
|
|
||||||
status_t FormatInteger(const BIntegerFormatParameters *parameters,
|
|
||||||
uint64 number, char *buffer, size_t bufferSize,
|
|
||||||
format_field_position *positions = NULL,
|
|
||||||
int32 positionCount = 1,
|
|
||||||
int32 *fieldCount = NULL,
|
|
||||||
bool allFieldPositions = false) const;
|
|
||||||
|
|
||||||
// default number format parameters
|
|
||||||
|
|
||||||
status_t SetDefaultIntegerFormatParameters(
|
|
||||||
const BIntegerFormatParameters *parameters);
|
|
||||||
BIntegerFormatParameters *DefaultIntegerFormatParameters();
|
|
||||||
const BIntegerFormatParameters *DefaultIntegerFormatParameters() const;
|
|
||||||
|
|
||||||
// other parameters configuring the formatter
|
|
||||||
|
|
||||||
status_t SetDigitSymbols(const char **digits);
|
|
||||||
status_t SetFractionSeparator(const char *decimalSeparator);
|
|
||||||
status_t SetGroupingInfo(const char **groupingSeparators,
|
|
||||||
size_t separatorCount, size_t *groupSizes, size_t sizeCount);
|
|
||||||
status_t SetExponentSymbol(const char *exponentSymbol,
|
|
||||||
const char *upperCaseExponentSymbol = NULL);
|
|
||||||
status_t SetSpecialNumberSymbols(const char *nan,
|
|
||||||
const char *infinity, const char *negativeInfinity = NULL,
|
|
||||||
const char *upperCaseNaN = NULL,
|
|
||||||
const char *upperCaseInfinity = NULL,
|
|
||||||
const char *upperCaseNegativeInfinity = NULL);
|
|
||||||
status_t SetSignSymbols(const char *plusPrefix,
|
|
||||||
const char *minusPrefix, const char *padPlusPrefix,
|
|
||||||
const char *noForcePlusPrefix = NULL, const char *plusSuffix = NULL,
|
|
||||||
const char *minusSuffix = NULL, const char *padPlusSuffix = NULL,
|
|
||||||
const char *noForcePlusSuffix = NULL);
|
|
||||||
status_t SetMantissaSignSymbols(const char *plusPrefix,
|
|
||||||
const char *minusPrefix, const char *padPlusPrefix,
|
|
||||||
const char *noForcePlusPrefix = NULL, const char *plusSuffix = NULL,
|
|
||||||
const char *minusSuffix = NULL, const char *padPlusSuffix = NULL,
|
|
||||||
const char *noForcePlusSuffix = NULL);
|
|
||||||
status_t SetExponentSignSymbols(const char *plusPrefix,
|
|
||||||
const char *minusPrefix, const char *plusSuffix = NULL,
|
|
||||||
const char *minusSuffix = NULL);
|
|
||||||
// TODO: Support engineering representation of scientific format (exponent
|
|
||||||
// is a multiple of 3), i.e. allow setting the number of which the exponent
|
|
||||||
// must be a multiple of.
|
|
||||||
|
|
||||||
private:
|
|
||||||
class BufferWriter;
|
|
||||||
class Float;
|
|
||||||
class GroupingInfo;
|
|
||||||
class Integer;
|
|
||||||
class SignSymbols;
|
|
||||||
struct SpecialNumberSymbols;
|
|
||||||
|
|
||||||
struct Symbol {
|
|
||||||
char *symbol;
|
|
||||||
int length;
|
|
||||||
int char_count;
|
|
||||||
|
|
||||||
Symbol(const char *symbol = NULL);
|
|
||||||
~Symbol();
|
|
||||||
|
|
||||||
status_t SetTo(const char *symbol);
|
|
||||||
void Unset() { SetTo(NULL); }
|
|
||||||
};
|
|
||||||
|
|
||||||
static const Symbol kDefaultDigitSymbols[];
|
|
||||||
static const Symbol kDefaultFractionSeparator;
|
|
||||||
static const Symbol kDefaultExponentSymbol;
|
|
||||||
static const Symbol kDefaultUpperCaseExponentSymbol;
|
|
||||||
static const Symbol kDefaultNaNSymbol;
|
|
||||||
static const Symbol kDefaultUpperCaseNaNSymbol;
|
|
||||||
static const Symbol kDefaultInfinitySymbol;
|
|
||||||
static const Symbol kDefaultUpperCaseInfinitySymbol;
|
|
||||||
static const Symbol kDefaultNegativeInfinitySymbol;
|
|
||||||
static const Symbol kDefaultUpperCaseNegativeInfinitySymbol;
|
|
||||||
|
|
||||||
static const GroupingInfo kDefaultGroupingInfo;
|
|
||||||
static const GroupingInfo kNoGroupingInfo;
|
|
||||||
|
|
||||||
static const SignSymbols kDefaultSignSymbols;
|
|
||||||
static const SignSymbols kDefaultMantissaSignSymbols;
|
|
||||||
static const SignSymbols kDefaultExponentSignSymbols;
|
|
||||||
|
|
||||||
status_t FormatInteger(const BIntegerFormatParameters *parameters,
|
|
||||||
const Integer &integer, char *buffer,
|
|
||||||
size_t bufferSize,
|
|
||||||
format_field_position *positions = NULL,
|
|
||||||
int32 positionCount = 1,
|
|
||||||
int32 *fieldCount = NULL,
|
|
||||||
bool allFieldPositions = false) const;
|
|
||||||
|
|
||||||
const Symbol *DigitSymbols() const;
|
|
||||||
const Symbol *FractionSeparator() const;
|
|
||||||
const GroupingInfo *GetGroupingInfo() const;
|
|
||||||
const Symbol *ExponentSymbol(bool upperCase = false) const;
|
|
||||||
const Symbol *NaNSymbol(bool upperCase = false) const;
|
|
||||||
const Symbol *InfinitySymbol(bool upperCase = false) const;
|
|
||||||
const Symbol *NegativeInfinitySymbol(bool upperCase = false) const;
|
|
||||||
void GetSpecialNumberSymbols(bool upperCase,
|
|
||||||
SpecialNumberSymbols *symbols) const;
|
|
||||||
const SignSymbols *GetSignSymbols() const;
|
|
||||||
const SignSymbols *MantissaSignSymbols() const;
|
|
||||||
const SignSymbols *ExponentSignSymbols() const;
|
|
||||||
|
|
||||||
static status_t _SetSymbol(Symbol **symbol, const char *str);
|
|
||||||
|
|
||||||
BIntegerFormatParameters fIntegerParameters;
|
|
||||||
Symbol *fDigitSymbols;
|
|
||||||
Symbol *fFractionSeparator;
|
|
||||||
GroupingInfo *fGroupingInfo;
|
|
||||||
Symbol *fExponentSymbol;
|
|
||||||
Symbol *fUpperCaseExponentSymbol;
|
|
||||||
Symbol *fNaNSymbol;
|
|
||||||
Symbol *fUpperCaseNaNSymbol;
|
|
||||||
Symbol *fInfinitySymbol;
|
|
||||||
Symbol *fUpperCaseInfinitySymbol;
|
|
||||||
Symbol *fNegativeInfinitySymbol;
|
|
||||||
Symbol *fUpperCaseNegativeInfinitySymbol;
|
|
||||||
SignSymbols *fSignSymbols;
|
|
||||||
SignSymbols *fMantissaSignSymbols;
|
|
||||||
SignSymbols *fExponentSignSymbols;
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif // _B_GENERIC_NUMBER_FORMAT_H_
|
|
||||||
File diff suppressed because it is too large
Load Diff
@@ -38,7 +38,6 @@ local sources =
|
|||||||
# old, needs investigation
|
# old, needs investigation
|
||||||
# FormatImpl.cpp
|
# FormatImpl.cpp
|
||||||
# FormatParameters.cpp
|
# FormatParameters.cpp
|
||||||
# GenericNumberFormat.cpp
|
|
||||||
# NumberFormatParameters.cpp
|
# NumberFormatParameters.cpp
|
||||||
;
|
;
|
||||||
|
|
||||||
|
|||||||
@@ -14,7 +14,6 @@ Depends LocaleKitTests
|
|||||||
collatorSpeed
|
collatorSpeed
|
||||||
collatorTest
|
collatorTest
|
||||||
ICUTest
|
ICUTest
|
||||||
# libNumberFormatTests.so
|
|
||||||
localekittest.so
|
localekittest.so
|
||||||
;
|
;
|
||||||
|
|
||||||
@@ -30,7 +29,6 @@ LocaleTest catalogSpeed.cpp ;
|
|||||||
LocaleTest catalogTest.cpp ;
|
LocaleTest catalogTest.cpp ;
|
||||||
LocaleTest collatorSpeed.cpp ;
|
LocaleTest collatorSpeed.cpp ;
|
||||||
LocaleTest collatorTest.cpp ;
|
LocaleTest collatorTest.cpp ;
|
||||||
LocaleTest genericNumberFormatTest.cpp ;
|
|
||||||
|
|
||||||
Includes [ FGristFiles ICUTest.cpp ] : [ BuildFeatureAttribute icu : headers ] ;
|
Includes [ FGristFiles ICUTest.cpp ] : [ BuildFeatureAttribute icu : headers ] ;
|
||||||
# Dependency needed to trigger downloading/unzipping the package before
|
# Dependency needed to trigger downloading/unzipping the package before
|
||||||
|
|||||||
@@ -1,106 +0,0 @@
|
|||||||
/*
|
|
||||||
** Copyright 2004, Ingo Weinhold, [email protected]. All rights reserved.
|
|
||||||
** Distributed under the terms of the MIT License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <string.h>
|
|
||||||
|
|
||||||
#include <GenericNumberFormat.h>
|
|
||||||
#include <IntegerFormatParameters.h>
|
|
||||||
|
|
||||||
void
|
|
||||||
format_integer(const char *test, const BGenericNumberFormat &format,
|
|
||||||
const BIntegerFormatParameters *parameters, int64 number)
|
|
||||||
{
|
|
||||||
const int bufferSize = 1024;
|
|
||||||
char buffer[bufferSize];
|
|
||||||
status_t error = format.FormatInteger(parameters, number, buffer,
|
|
||||||
bufferSize);
|
|
||||||
if (error == B_OK)
|
|
||||||
printf("%-20s `%s'\n", test, buffer);
|
|
||||||
else
|
|
||||||
printf("%-20s Failed to format number: %s\n", test, strerror(error));
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
format_integer(BGenericNumberFormat &format, int64 number)
|
|
||||||
{
|
|
||||||
printf("number: %lld\n", number);
|
|
||||||
BIntegerFormatParameters parameters(
|
|
||||||
format.DefaultIntegerFormatParameters());
|
|
||||||
format_integer(" default:", format, ¶meters, number);
|
|
||||||
parameters.SetFormatWidth(25);
|
|
||||||
format_integer(" right aligned:", format, ¶meters, number);
|
|
||||||
parameters.SetAlignment(B_ALIGN_FORMAT_LEFT);
|
|
||||||
format_integer(" left aligned:", format, ¶meters, number);
|
|
||||||
parameters.SetFormatWidth(1);
|
|
||||||
parameters.SetAlignment(B_ALIGN_FORMAT_RIGHT);
|
|
||||||
parameters.SetSignPolicy(B_USE_POSITIVE_SIGN);
|
|
||||||
format_integer(" use plus:", format, ¶meters, number);
|
|
||||||
parameters.SetSignPolicy(B_USE_SPACE_FOR_POSITIVE_SIGN);
|
|
||||||
format_integer(" space for plus:", format, ¶meters, number);
|
|
||||||
parameters.SetSignPolicy(B_USE_NEGATIVE_SIGN_ONLY);
|
|
||||||
parameters.SetMinimalIntegerDigits(0);
|
|
||||||
format_integer(" min digits 0:", format, ¶meters, number);
|
|
||||||
parameters.SetMinimalIntegerDigits(5);
|
|
||||||
format_integer(" min digits 5:", format, ¶meters, number);
|
|
||||||
parameters.SetMinimalIntegerDigits(20);
|
|
||||||
format_integer(" min digits 20:", format, ¶meters, number);
|
|
||||||
parameters.SetMinimalIntegerDigits(30);
|
|
||||||
format_integer(" min digits 30:", format, ¶meters, number);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
format_float(const char *test, const BGenericNumberFormat &format,
|
|
||||||
const BFloatFormatParameters *parameters, double number)
|
|
||||||
{
|
|
||||||
const int bufferSize = 1024;
|
|
||||||
char buffer[bufferSize];
|
|
||||||
status_t error = format.FormatFloat(parameters, number, buffer, bufferSize);
|
|
||||||
if (error == B_OK)
|
|
||||||
printf("%-20s `%s'\n", test, buffer);
|
|
||||||
else
|
|
||||||
printf("%-20s Failed to format number: %s\n", test, strerror(error));
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
format_float(BGenericNumberFormat &format, double number)
|
|
||||||
{
|
|
||||||
printf("number: %g\n", number);
|
|
||||||
BFloatFormatParameters parameters( format.DefaultFloatFormatParameters());
|
|
||||||
format_float(" default:", format, ¶meters, number);
|
|
||||||
}
|
|
||||||
|
|
||||||
int
|
|
||||||
main()
|
|
||||||
{
|
|
||||||
BGenericNumberFormat format;
|
|
||||||
printf("Integer\n");
|
|
||||||
printf("=======\n\n");
|
|
||||||
format_integer(format, 0);
|
|
||||||
format_integer(format, 1234567890LL);
|
|
||||||
format_integer(format, -1234567890LL);
|
|
||||||
format.DefaultIntegerFormatParameters()->SetUseGrouping(true);
|
|
||||||
format_integer(format, 0);
|
|
||||||
format_integer(format, 1234567890LL);
|
|
||||||
format_integer(format, -1234567890LL);
|
|
||||||
|
|
||||||
printf("\n\nFloat\n");
|
|
||||||
printf("=====\n\n");
|
|
||||||
format_float(format, 0.0);
|
|
||||||
format_float(format, -0.0);
|
|
||||||
format_float(format, 1234567890.0);
|
|
||||||
format_float(format, -1234567890.0);
|
|
||||||
format_float(format, 1234.56789);
|
|
||||||
format_float(format, -1234.56789);
|
|
||||||
format.DefaultFloatFormatParameters()->SetUseGrouping(true);
|
|
||||||
format_float(format, 0.0);
|
|
||||||
format_float(format, -0.0);
|
|
||||||
format_float(format, 1234567890.0);
|
|
||||||
format_float(format, -1234567890.0);
|
|
||||||
format_float(format, 1234.56789);
|
|
||||||
format_float(format, -1234.56789);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
@@ -1,15 +0,0 @@
|
|||||||
SubDir HAIKU_TOP src tests kits locale number_format ;
|
|
||||||
|
|
||||||
UsePublicHeaders locale ;
|
|
||||||
|
|
||||||
SEARCH_SOURCE += [ FDirName $(SUBDIR) generic_number_format ] ;
|
|
||||||
|
|
||||||
UnitTestLib libNumberFormatTests.so
|
|
||||||
: NumberFormatTestAddOn.cpp
|
|
||||||
|
|
||||||
# BGenericNumberFormat
|
|
||||||
GenericNumberFormatTests.cpp
|
|
||||||
GenericNumberFormatConstructorTest.cpp
|
|
||||||
|
|
||||||
: be [ TargetLibstdc++ ]
|
|
||||||
;
|
|
||||||
@@ -1,15 +0,0 @@
|
|||||||
#include <TestSuite.h>
|
|
||||||
#include <TestSuiteAddon.h>
|
|
||||||
|
|
||||||
#include "generic_number_format/GenericNumberFormatTests.h"
|
|
||||||
|
|
||||||
// getTestSuite
|
|
||||||
BTestSuite*
|
|
||||||
getTestSuite()
|
|
||||||
{
|
|
||||||
BTestSuite *suite = new BTestSuite("NumberFormat");
|
|
||||||
|
|
||||||
suite->addTest("BGenericNumberFormat", GenericNumberFormatTestSuite());
|
|
||||||
|
|
||||||
return suite;
|
|
||||||
}
|
|
||||||
-33
@@ -1,33 +0,0 @@
|
|||||||
#include <stdio.h>
|
|
||||||
|
|
||||||
#include <GenericNumberFormat.h>
|
|
||||||
|
|
||||||
#include <TestShell.h>
|
|
||||||
#include <TestUtils.h>
|
|
||||||
#include <cppunit/TestAssert.h>
|
|
||||||
#include <cppunit/TestCaller.h>
|
|
||||||
#include <cppunit/TestSuite.h>
|
|
||||||
|
|
||||||
#include "GenericNumberFormatConstructorTest.h"
|
|
||||||
|
|
||||||
using namespace CppUnit;
|
|
||||||
|
|
||||||
// Suite
|
|
||||||
Test *
|
|
||||||
GenericNumberFormatConstructorTest::Suite()
|
|
||||||
{
|
|
||||||
CppUnit::TestSuite *suite = new CppUnit::TestSuite();
|
|
||||||
typedef CppUnit::TestCaller<GenericNumberFormatConstructorTest> TC;
|
|
||||||
|
|
||||||
suite->addTest(new TC("BGenericNumberFormat::Constructor Test1",
|
|
||||||
&GenericNumberFormatConstructorTest::ConstructorTest1));
|
|
||||||
|
|
||||||
return suite;
|
|
||||||
}
|
|
||||||
|
|
||||||
// ConstructorTest1
|
|
||||||
void GenericNumberFormatConstructorTest::ConstructorTest1()
|
|
||||||
{
|
|
||||||
BGenericNumberFormat format;
|
|
||||||
}
|
|
||||||
|
|
||||||
-17
@@ -1,17 +0,0 @@
|
|||||||
#ifndef _GENERIC_NUMBER_FORMAT_CONSTRUCTOR_TEST_
|
|
||||||
#define _GENERIC_NUMBER_FORMAT_CONSTRUCTOR_TEST_
|
|
||||||
|
|
||||||
#include <cppunit/TestCase.h>
|
|
||||||
|
|
||||||
class GenericNumberFormatConstructorTest : public CppUnit::TestCase {
|
|
||||||
public:
|
|
||||||
GenericNumberFormatConstructorTest() {}
|
|
||||||
GenericNumberFormatConstructorTest(string name)
|
|
||||||
: TestCase(name) {}
|
|
||||||
|
|
||||||
void ConstructorTest1();
|
|
||||||
|
|
||||||
static Test* Suite();
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif // _GENERIC_NUMBER_FORMAT_CONSTRUCTOR_TEST_
|
|
||||||
-16
@@ -1,16 +0,0 @@
|
|||||||
#include <cppunit/TestSuite.h>
|
|
||||||
|
|
||||||
#include "GenericNumberFormatTests.h"
|
|
||||||
|
|
||||||
#include "GenericNumberFormatConstructorTest.h"
|
|
||||||
|
|
||||||
// getTestSuite
|
|
||||||
CppUnit::Test*
|
|
||||||
GenericNumberFormatTestSuite()
|
|
||||||
{
|
|
||||||
CppUnit::TestSuite *testSuite = new CppUnit::TestSuite();
|
|
||||||
|
|
||||||
testSuite->addTest(GenericNumberFormatConstructorTest::Suite());
|
|
||||||
|
|
||||||
return testSuite;
|
|
||||||
}
|
|
||||||
@@ -1,10 +0,0 @@
|
|||||||
#ifndef _GENERIC_NUMBER_FORMAT_TESTS_H
|
|
||||||
#define _GENERIC_NUMBER_FORMAT_TESTS_H
|
|
||||||
|
|
||||||
namespace CppUnit {
|
|
||||||
class Test;
|
|
||||||
}
|
|
||||||
|
|
||||||
CppUnit::Test *GenericNumberFormatTestSuite();
|
|
||||||
|
|
||||||
#endif // _GENERIC_NUMBER_FORMAT_TESTS_H
|
|
||||||
Reference in New Issue
Block a user