1#ifndef _B_GENERIC_NUMBER_FORMAT_H_ 2#define _B_GENERIC_NUMBER_FORMAT_H_ 3 4#include <FloatFormatParameters.h> 5#include <IntegerFormatParameters.h> 6 7class BString; 8struct format_field_position; 9 10class BGenericNumberFormat { 11 public: 12 BGenericNumberFormat(); 13 ~BGenericNumberFormat(); 14 15 status_t FormatInteger(const BIntegerFormatParameters *parameters, 16 int64 number, BString *buffer, 17 format_field_position *positions = NULL, 18 int32 positionCount = 1, 19 int32 *fieldCount = NULL, 20 bool allFieldPositions = false) const; 21 22 status_t FormatInteger(const BIntegerFormatParameters *parameters, 23 int64 number, char *buffer, size_t bufferSize, 24 format_field_position *positions = NULL, 25 int32 positionCount = 1, 26 int32 *fieldCount = NULL, 27 bool allFieldPositions = false) const; 28 29 status_t FormatInteger(const BIntegerFormatParameters *parameters, 30 uint64 number, BString *buffer, 31 format_field_position *positions = NULL, 32 int32 positionCount = 1, 33 int32 *fieldCount = NULL, 34 bool allFieldPositions = false) const; 35 36 status_t FormatInteger(const BIntegerFormatParameters *parameters, 37 uint64 number, char *buffer, size_t bufferSize, 38 format_field_position *positions = NULL, 39 int32 positionCount = 1, 40 int32 *fieldCount = NULL, 41 bool allFieldPositions = false) const; 42 43 status_t FormatFloat(const BFloatFormatParameters *parameters, 44 double number, BString *buffer, 45 format_field_position *positions = NULL, 46 int32 positionCount = 1, 47 int32 *fieldCount = NULL, 48 bool allFieldPositions = false) const; 49 50 status_t FormatFloat(const BFloatFormatParameters *parameters, 51 double number, char *buffer, size_t bufferSize, 52 format_field_position *positions = NULL, 53 int32 positionCount = 1, 54 int32 *fieldCount = NULL, 55 bool allFieldPositions = false) const; 56 57 // default number format parameters 58 59 status_t SetDefaultIntegerFormatParameters( 60 const BIntegerFormatParameters *parameters); 61 BIntegerFormatParameters *DefaultIntegerFormatParameters(); 62 const BIntegerFormatParameters *DefaultIntegerFormatParameters() const; 63 64 status_t SetDefaultFloatFormatParameters( 65 const BFloatFormatParameters *parameters); 66 BFloatFormatParameters *DefaultFloatFormatParameters(); 67 const BFloatFormatParameters *DefaultFloatFormatParameters() const; 68 69 // other parameters configuring the formatter 70 71 status_t SetDigitSymbols(const char **digits); 72 status_t SetFractionSeparator(const char *decimalSeparator); 73 status_t SetGroupingInfo(const char **groupingSeparators, 74 size_t separatorCount, size_t *groupSizes, size_t sizeCount); 75 status_t SetExponentSymbol(const char *exponentSymbol, 76 const char *upperCaseExponentSymbol = NULL); 77 status_t SetSpecialNumberSymbols(const char *nan, 78 const char *infinity, const char *negativeInfinity = NULL, 79 const char *upperCaseNaN = NULL, 80 const char *upperCaseInfinity = NULL, 81 const char *upperCaseNegativeInfinity = NULL); 82 status_t SetSignSymbols(const char *plusPrefix, 83 const char *minusPrefix, const char *padPlusPrefix, 84 const char *noForcePlusPrefix = NULL, const char *plusSuffix = NULL, 85 const char *minusSuffix = NULL, const char *padPlusSuffix = NULL, 86 const char *noForcePlusSuffix = NULL); 87 status_t SetMantissaSignSymbols(const char *plusPrefix, 88 const char *minusPrefix, const char *padPlusPrefix, 89 const char *noForcePlusPrefix = NULL, const char *plusSuffix = NULL, 90 const char *minusSuffix = NULL, const char *padPlusSuffix = NULL, 91 const char *noForcePlusSuffix = NULL); 92 status_t SetExponentSignSymbols(const char *plusPrefix, 93 const char *minusPrefix, const char *plusSuffix = NULL, 94 const char *minusSuffix = NULL); 95// TODO: Support engineering representation of scientific format (exponent 96// is a multiple of 3), i.e. allow setting the number of which the exponent 97// must be a multiple of. 98 99 private: 100 class BufferWriter; 101 class Float; 102 class GroupingInfo; 103 class Integer; 104 class SignSymbols; 105 struct SpecialNumberSymbols; 106 107 struct Symbol { 108 char *symbol; 109 int length; 110 int char_count; 111 112 Symbol(const char *symbol = NULL); 113 ~Symbol(); 114 115 status_t SetTo(const char *symbol); 116 void Unset() { SetTo(NULL); } 117 }; 118 119 static const Symbol kDefaultDigitSymbols[]; 120 static const Symbol kDefaultFractionSeparator; 121 static const Symbol kDefaultExponentSymbol; 122 static const Symbol kDefaultUpperCaseExponentSymbol; 123 static const Symbol kDefaultNaNSymbol; 124 static const Symbol kDefaultUpperCaseNaNSymbol; 125 static const Symbol kDefaultInfinitySymbol; 126 static const Symbol kDefaultUpperCaseInfinitySymbol; 127 static const Symbol kDefaultNegativeInfinitySymbol; 128 static const Symbol kDefaultUpperCaseNegativeInfinitySymbol; 129 130 static const GroupingInfo kDefaultGroupingInfo; 131 static const GroupingInfo kNoGroupingInfo; 132 133 static const SignSymbols kDefaultSignSymbols; 134 static const SignSymbols kDefaultMantissaSignSymbols; 135 static const SignSymbols kDefaultExponentSignSymbols; 136 137 status_t FormatInteger(const BIntegerFormatParameters *parameters, 138 const Integer &integer, char *buffer, 139 size_t bufferSize, 140 format_field_position *positions = NULL, 141 int32 positionCount = 1, 142 int32 *fieldCount = NULL, 143 bool allFieldPositions = false) const; 144 145 const Symbol *DigitSymbols() const; 146 const Symbol *FractionSeparator() const; 147 const GroupingInfo *GetGroupingInfo() const; 148 const Symbol *ExponentSymbol(bool upperCase = false) const; 149 const Symbol *NaNSymbol(bool upperCase = false) const; 150 const Symbol *InfinitySymbol(bool upperCase = false) const; 151 const Symbol *NegativeInfinitySymbol(bool upperCase = false) const; 152 void GetSpecialNumberSymbols(bool upperCase, 153 SpecialNumberSymbols *symbols) const; 154 const SignSymbols *GetSignSymbols() const; 155 const SignSymbols *MantissaSignSymbols() const; 156 const SignSymbols *ExponentSignSymbols() const; 157 158 static status_t _SetSymbol(Symbol **symbol, const char *str); 159 160 BIntegerFormatParameters fIntegerParameters; 161 BFloatFormatParameters fFloatParameters; 162 Symbol *fDigitSymbols; 163 Symbol *fFractionSeparator; 164 GroupingInfo *fGroupingInfo; 165 Symbol *fExponentSymbol; 166 Symbol *fUpperCaseExponentSymbol; 167 Symbol *fNaNSymbol; 168 Symbol *fUpperCaseNaNSymbol; 169 Symbol *fInfinitySymbol; 170 Symbol *fUpperCaseInfinitySymbol; 171 Symbol *fNegativeInfinitySymbol; 172 Symbol *fUpperCaseNegativeInfinitySymbol; 173 SignSymbols *fSignSymbols; 174 SignSymbols *fMantissaSignSymbols; 175 SignSymbols *fExponentSignSymbols; 176}; 177 178#endif // _B_GENERIC_NUMBER_FORMAT_H_ 179