mirror of
https://github.com/unicode-org/icu.git
synced 2025-04-21 12:40:02 +00:00
ICU-11383 Remove ScientificFormatHelper C++
X-SVN-Rev: 36826
This commit is contained in:
parent
21b7a7e13d
commit
59a03bbc9b
11 changed files with 3 additions and 461 deletions
|
@ -95,7 +95,7 @@ ztrans.o zrule.o vzone.o fphdlimp.o fpositer.o locdspnm.o \
|
|||
decNumber.o decContext.o alphaindex.o tznames.o tznames_impl.o tzgnames.o \
|
||||
tzfmt.o compactdecimalformat.o gender.o region.o scriptset.o identifier_info.o \
|
||||
uregion.o reldatefmt.o quantityformatter.o measunit.o filteredbrk.o \
|
||||
scientificformathelper.o sharedbreakiterator.o scientificnumberformatter.o
|
||||
sharedbreakiterator.o scientificnumberformatter.o
|
||||
|
||||
## Header files to install
|
||||
HEADERS = $(srcdir)/unicode/*.h
|
||||
|
|
|
@ -347,7 +347,6 @@
|
|||
<DisableLanguageExtensions>false</DisableLanguageExtensions>
|
||||
</ClCompile>
|
||||
<ClCompile Include="reldtfmt.cpp" />
|
||||
<ClCompile Include="scientificformathelper.cpp" />
|
||||
<ClCompile Include="scientificnumberformatter.cpp" />
|
||||
<ClCompile Include="sharedbreakiterator.cpp" />
|
||||
<ClCompile Include="selfmt.cpp" />
|
||||
|
@ -1200,20 +1199,6 @@
|
|||
<Outputs Condition="'$(Configuration)|$(Platform)'=='Release|x64'">..\..\include\unicode\%(Filename)%(Extension);%(Outputs)</Outputs>
|
||||
</CustomBuild>
|
||||
<ClInclude Include="reldtfmt.h" />
|
||||
<CustomBuild Include="unicode\scientificformathelper.h">
|
||||
<Command Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">copy "%(FullPath)" ..\..\include\unicode
|
||||
</Command>
|
||||
<Outputs Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">..\..\include\unicode\%(Filename)%(Extension);%(Outputs)</Outputs>
|
||||
<Command Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">copy "%(FullPath)" ..\..\include\unicode
|
||||
</Command>
|
||||
<Outputs Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">..\..\include\unicode\%(Filename)%(Extension);%(Outputs)</Outputs>
|
||||
<Command Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">copy "%(FullPath)" ..\..\include\unicode
|
||||
</Command>
|
||||
<Outputs Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">..\..\include\unicode\%(Filename)%(Extension);%(Outputs)</Outputs>
|
||||
<Command Condition="'$(Configuration)|$(Platform)'=='Release|x64'">copy "%(FullPath)" ..\..\include\unicode
|
||||
</Command>
|
||||
<Outputs Condition="'$(Configuration)|$(Platform)'=='Release|x64'">..\..\include\unicode\%(Filename)%(Extension);%(Outputs)</Outputs>
|
||||
</CustomBuild>
|
||||
<CustomBuild Include="unicode\scientificnumberformatter.h">
|
||||
<Command Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">copy "%(FullPath)" ..\..\include\unicode
|
||||
</Command>
|
||||
|
|
|
@ -228,9 +228,6 @@
|
|||
<ClCompile Include="reldtfmt.cpp">
|
||||
<Filter>formatting</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="scientificformathelper.cpp">
|
||||
<Filter>formatting</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="scientificnumberformatter.cpp">
|
||||
<Filter>formatting</Filter>
|
||||
</ClCompile>
|
||||
|
@ -1092,9 +1089,6 @@
|
|||
<CustomBuild Include="unicode\rbtz.h">
|
||||
<Filter>formatting</Filter>
|
||||
</CustomBuild>
|
||||
<CustomBuild Include="unicode\scientificformathelper.h">
|
||||
<Filter>formatting</Filter>
|
||||
</CustomBuild>
|
||||
<CustomBuild Include="unicode\scientificnumberformatter.h">
|
||||
<Filter>formatting</Filter>
|
||||
</CustomBuild>
|
||||
|
|
|
@ -1,86 +0,0 @@
|
|||
/*
|
||||
**********************************************************************
|
||||
* Copyright (c) 2014, International Business Machines
|
||||
* Corporation and others. All Rights Reserved.
|
||||
**********************************************************************
|
||||
*/
|
||||
#include "unicode/utypes.h"
|
||||
|
||||
#if !UCONFIG_NO_FORMATTING
|
||||
|
||||
#include "unicode/scientificformathelper.h"
|
||||
#include "unicode/scientificnumberformatter.h"
|
||||
#include "decfmtst.h"
|
||||
|
||||
U_NAMESPACE_BEGIN
|
||||
|
||||
ScientificFormatHelper::ScientificFormatHelper(
|
||||
const DecimalFormatSymbols &dfs, UErrorCode &status)
|
||||
: fPreExponent(), fStaticSets(NULL) {
|
||||
if (U_FAILURE(status)) {
|
||||
return;
|
||||
}
|
||||
ScientificNumberFormatter::getPreExponent(dfs, fPreExponent);
|
||||
fStaticSets = DecimalFormatStaticSets::getStaticSets(status);
|
||||
}
|
||||
|
||||
ScientificFormatHelper::ScientificFormatHelper(
|
||||
const ScientificFormatHelper &other)
|
||||
: UObject(other),
|
||||
fPreExponent(other.fPreExponent),
|
||||
fStaticSets(other.fStaticSets) {
|
||||
}
|
||||
|
||||
ScientificFormatHelper &ScientificFormatHelper::operator=(const ScientificFormatHelper &other) {
|
||||
if (this == &other) {
|
||||
return *this;
|
||||
}
|
||||
fPreExponent = other.fPreExponent;
|
||||
fStaticSets = other.fStaticSets;
|
||||
return *this;
|
||||
}
|
||||
|
||||
ScientificFormatHelper::~ScientificFormatHelper() {
|
||||
}
|
||||
|
||||
UnicodeString &ScientificFormatHelper::insertMarkup(
|
||||
const UnicodeString &s,
|
||||
FieldPositionIterator &fpi,
|
||||
const UnicodeString &beginMarkup,
|
||||
const UnicodeString &endMarkup,
|
||||
UnicodeString &result,
|
||||
UErrorCode &status) const {
|
||||
if (U_FAILURE(status)) {
|
||||
return result;
|
||||
}
|
||||
ScientificNumberFormatter::MarkupStyle style(beginMarkup, endMarkup);
|
||||
return style.format(
|
||||
s,
|
||||
fpi,
|
||||
fPreExponent,
|
||||
*fStaticSets,
|
||||
result,
|
||||
status);
|
||||
}
|
||||
|
||||
UnicodeString &ScientificFormatHelper::toSuperscriptExponentDigits(
|
||||
const UnicodeString &s,
|
||||
FieldPositionIterator &fpi,
|
||||
UnicodeString &result,
|
||||
UErrorCode &status) const {
|
||||
if (U_FAILURE(status)) {
|
||||
return result;
|
||||
}
|
||||
ScientificNumberFormatter::SuperscriptStyle style;
|
||||
return style.format(
|
||||
s,
|
||||
fpi,
|
||||
fPreExponent,
|
||||
*fStaticSets,
|
||||
result,
|
||||
status);
|
||||
}
|
||||
|
||||
U_NAMESPACE_END
|
||||
|
||||
#endif /* !UCONFIG_NO_FORMATTING */
|
|
@ -1,139 +0,0 @@
|
|||
/*
|
||||
**********************************************************************
|
||||
* Copyright (c) 2014, International Business Machines
|
||||
* Corporation and others. All Rights Reserved.
|
||||
**********************************************************************
|
||||
*/
|
||||
#ifndef SCIFORMATHELPER_H
|
||||
#define SCIFORMATHELPER_H
|
||||
|
||||
#include "unicode/utypes.h"
|
||||
|
||||
#if !UCONFIG_NO_FORMATTING
|
||||
|
||||
#ifndef U_HIDE_DRAFT_API
|
||||
|
||||
#include "unicode/unistr.h"
|
||||
|
||||
/**
|
||||
* \file
|
||||
* \brief C++ API: Formatter for measure objects.
|
||||
*/
|
||||
|
||||
U_NAMESPACE_BEGIN
|
||||
|
||||
class DecimalFormatSymbols;
|
||||
class FieldPositionIterator;
|
||||
class DecimalFormatStaticSets;
|
||||
|
||||
/**
|
||||
* A helper class for formatting numbers in standard scientific notation
|
||||
* instead of E notation.
|
||||
*
|
||||
* Sample code:
|
||||
* <pre>
|
||||
* UErrorCode status = U_ZERO_ERROR;
|
||||
* DecimalFormat *decfmt = (DecimalFormat *)
|
||||
* NumberFormat::createScientificInstance("en", status);
|
||||
* UnicodeString appendTo;
|
||||
* FieldPositionIterator fpositer;
|
||||
* decfmt->format(1.23456e-78, appendTo, &fpositer, status);
|
||||
* ScientificFormatHelper helper(*decfmt->getDecimalFormatSymbols(), status);
|
||||
* UnicodeString result;
|
||||
*
|
||||
* // result = "1.23456x10<sup>-78</sup>"
|
||||
* helper.insertMarkup(appendTo, fpositer, "<sup>", "</sup>", result, status));
|
||||
* </pre>
|
||||
*
|
||||
* @see NumberFormat
|
||||
* @draft ICU 54
|
||||
*/
|
||||
class U_I18N_API ScientificFormatHelper : public UObject {
|
||||
public:
|
||||
/**
|
||||
* Constructor.
|
||||
* @param symbols comes from DecimalFormat instance used for default
|
||||
* scientific notation.
|
||||
* @param status any error reported here.
|
||||
* @draft ICU 54
|
||||
*/
|
||||
ScientificFormatHelper(const DecimalFormatSymbols &symbols, UErrorCode& status);
|
||||
|
||||
/**
|
||||
* Copy constructor.
|
||||
* @draft ICU 54
|
||||
*/
|
||||
ScientificFormatHelper(const ScientificFormatHelper &other);
|
||||
|
||||
/**
|
||||
* Assignment operator.
|
||||
* @draft ICU 54
|
||||
*/
|
||||
ScientificFormatHelper &operator=(const ScientificFormatHelper &other);
|
||||
|
||||
/**
|
||||
* Destructor.
|
||||
* @draft ICU 54
|
||||
*/
|
||||
virtual ~ScientificFormatHelper();
|
||||
|
||||
/**
|
||||
* Formats standard scientific notation by surrounding exponent with
|
||||
* html to make it superscript.
|
||||
* @param s the original formatted scientific notation
|
||||
* e.g "6.02e23". s is output from
|
||||
* NumberFormat::createScientificInstance()->format().
|
||||
* @param fpi the FieldPositionIterator from the format call.
|
||||
* fpi is output from
|
||||
* NumberFormat::createScientificInstance()->format().
|
||||
* @param beginMarkup the start html for the exponent e.g "<sup>"
|
||||
* @param endMarkup the end html for the exponent e.g "</sup>"
|
||||
* @param result standard scientific notation appended here.
|
||||
* @param status any error returned here. When status is set to a
|
||||
* non-zero error, the value of result is unspecified,
|
||||
* and client should fallback to using s for scientific
|
||||
* notation.
|
||||
* @return the value stored in result.
|
||||
* @draft ICU 54
|
||||
*/
|
||||
UnicodeString &insertMarkup(
|
||||
const UnicodeString &s,
|
||||
FieldPositionIterator &fpi,
|
||||
const UnicodeString &beginMarkup,
|
||||
const UnicodeString &endMarkup,
|
||||
UnicodeString &result,
|
||||
UErrorCode &status) const;
|
||||
|
||||
/**
|
||||
* Formats standard scientific notation by using superscript unicode
|
||||
* points 0..9.
|
||||
* @param s the original formatted scientific notation
|
||||
* e.g "6.02e23". s is output from
|
||||
* NumberFormat::createScientificInstance()->format().
|
||||
* @param fpi the FieldPositionIterator from the format call.
|
||||
* fpi is output from
|
||||
* NumberFormat::createScientificInstance()->format().
|
||||
* @param result standard scientific notation appended here.
|
||||
* @param status any error returned here. When status is set to a
|
||||
* non-zero error, the value of result is unspecified,
|
||||
* and client should fallback to using s for scientific
|
||||
* notation.
|
||||
* @return the value stored in result.
|
||||
* @draft ICU 54
|
||||
*/
|
||||
UnicodeString &toSuperscriptExponentDigits(
|
||||
const UnicodeString &s,
|
||||
FieldPositionIterator &fpi,
|
||||
UnicodeString &result,
|
||||
UErrorCode &status) const;
|
||||
private:
|
||||
UnicodeString fPreExponent;
|
||||
const DecimalFormatStaticSets *fStaticSets;
|
||||
};
|
||||
|
||||
U_NAMESPACE_END
|
||||
|
||||
#endif /* U_HIDE_DRAFT_API */
|
||||
|
||||
#endif /* !UCONFIG_NO_FORMATTING */
|
||||
#endif
|
|
@ -167,8 +167,6 @@ public:
|
|||
const DecimalFormatStaticSets &decimalFormatSets,
|
||||
UnicodeString &appendTo,
|
||||
UErrorCode &status) const;
|
||||
private:
|
||||
friend class ScientificFormatHelper;
|
||||
};
|
||||
|
||||
class U_I18N_API MarkupStyle : public Style {
|
||||
|
@ -191,7 +189,6 @@ public:
|
|||
private:
|
||||
UnicodeString fBeginMarkup;
|
||||
UnicodeString fEndMarkup;
|
||||
friend class ScientificFormatHelper;
|
||||
};
|
||||
|
||||
ScientificNumberFormatter(
|
||||
|
@ -215,7 +212,6 @@ public:
|
|||
Style *fStyle;
|
||||
const DecimalFormatStaticSets *fStaticSets;
|
||||
|
||||
friend class ScientificFormatHelper;
|
||||
};
|
||||
|
||||
U_NAMESPACE_END
|
||||
|
|
|
@ -57,7 +57,7 @@ uobjtest.o idnaref.o idnaconf.o nptrans.o punyref.o testidn.o testidna.o uts46te
|
|||
incaltst.o calcasts.o v32test.o uvectest.o textfile.o tokiter.o utxttest.o \
|
||||
windttst.o winnmtst.o winutil.o csdetest.o tzrulets.o tzoffloc.o tzfmttst.o ssearch.o dtifmtts.o \
|
||||
tufmtts.o itspoof.o simplethread.o bidiconf.o locnmtst.o dcfmtest.o alphaindextst.o listformattertest.o genderinfotest.o compactdecimalformattest.o regiontst.o \
|
||||
reldatefmttest.o simplepatternformattertest.o measfmttest.o scientificformathelpertest.o numfmtspectest.o unifiedcachetest.o quantityformattertest.o \
|
||||
reldatefmttest.o simplepatternformattertest.o measfmttest.o numfmtspectest.o unifiedcachetest.o quantityformattertest.o \
|
||||
scientificnumberformattertest.o
|
||||
|
||||
DEPS = $(OBJECTS:.o=.d)
|
||||
|
|
|
@ -324,7 +324,6 @@
|
|||
<DisableLanguageExtensions>false</DisableLanguageExtensions>
|
||||
</ClCompile>
|
||||
<ClCompile Include="scientificformathelpertest.cpp" />
|
||||
<ClCompile Include="scientificnumberformattertest.cpp" />
|
||||
<ClCompile Include="sdtfmtts.cpp" />
|
||||
<ClCompile Include="selfmts.cpp" />
|
||||
<ClCompile Include="tchcfmt.cpp" />
|
||||
|
|
|
@ -271,9 +271,6 @@
|
|||
<ClCompile Include="reldatefmttest.cpp">
|
||||
<Filter>formatting</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="scientificformathelpertest.cpp">
|
||||
<Filter>formatting</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="scientificnumberformattertest.cpp">
|
||||
<Filter>formatting</Filter>
|
||||
</ClCompile>
|
||||
|
|
|
@ -65,7 +65,6 @@ extern IntlTest *createGenderInfoTest();
|
|||
extern IntlTest *createRelativeDateTimeFormatterTest();
|
||||
#endif
|
||||
extern IntlTest *createMeasureFormatTest();
|
||||
extern IntlTest *createScientificFormatHelperTest();
|
||||
extern IntlTest *createNumberFormatSpecificationTest();
|
||||
extern IntlTest *createScientificNumberFormatterTest();
|
||||
|
||||
|
@ -185,15 +184,6 @@ void IntlTestFormat::runIndexedTest( int32_t index, UBool exec, const char* &nam
|
|||
}
|
||||
break;
|
||||
case 48:
|
||||
name = "ScientificFormatHelperTest";
|
||||
if (exec) {
|
||||
logln("ScientificFormatHelperTest test---");
|
||||
logln((UnicodeString)"");
|
||||
LocalPointer<IntlTest> test(createScientificFormatHelperTest());
|
||||
callTest(*test, par);
|
||||
}
|
||||
break;
|
||||
case 49:
|
||||
name = "NumberFormatSpecificationTest";
|
||||
if (exec) {
|
||||
logln("NumberFormatSpecificationTest test---");
|
||||
|
@ -202,7 +192,7 @@ void IntlTestFormat::runIndexedTest( int32_t index, UBool exec, const char* &nam
|
|||
callTest(*test, par);
|
||||
}
|
||||
break;
|
||||
case 50:
|
||||
case 49:
|
||||
name = "ScientificNumberFormatterTest";
|
||||
if (exec) {
|
||||
logln("ScientificNumberFormatterTest test---");
|
||||
|
|
|
@ -1,194 +0,0 @@
|
|||
/*
|
||||
*******************************************************************************
|
||||
* Copyright (C) 2014, International Business Machines Corporation and *
|
||||
* others. All Rights Reserved. *
|
||||
*******************************************************************************
|
||||
*
|
||||
* File SCIFORMATHELPERTEST.CPP
|
||||
*
|
||||
*******************************************************************************
|
||||
*/
|
||||
#include "unicode/utypes.h"
|
||||
|
||||
#include "intltest.h"
|
||||
|
||||
#if !UCONFIG_NO_FORMATTING
|
||||
|
||||
#include "unicode/scientificformathelper.h"
|
||||
#include "unicode/numfmt.h"
|
||||
#include "unicode/decimfmt.h"
|
||||
#include "unicode/localpointer.h"
|
||||
|
||||
class ScientificFormatHelperTest : public IntlTest {
|
||||
public:
|
||||
void runIndexedTest(int32_t index, UBool exec, const char *&name, char *par=0);
|
||||
private:
|
||||
void TestBasic();
|
||||
void TestFarsi();
|
||||
void TestPlusSignInExponentMarkup();
|
||||
void TestPlusSignInExponentSuperscript();
|
||||
void TestFixedDecimalMarkup();
|
||||
void TestFixedDecimalSuperscript();
|
||||
};
|
||||
|
||||
void ScientificFormatHelperTest::runIndexedTest(
|
||||
int32_t index, UBool exec, const char *&name, char *) {
|
||||
if (exec) {
|
||||
logln("TestSuite ScientificFormatHelperTest: ");
|
||||
}
|
||||
TESTCASE_AUTO_BEGIN;
|
||||
TESTCASE_AUTO(TestBasic);
|
||||
TESTCASE_AUTO(TestFarsi);
|
||||
TESTCASE_AUTO(TestPlusSignInExponentMarkup);
|
||||
TESTCASE_AUTO(TestPlusSignInExponentSuperscript);
|
||||
TESTCASE_AUTO(TestFixedDecimalMarkup);
|
||||
TESTCASE_AUTO(TestFixedDecimalSuperscript);
|
||||
TESTCASE_AUTO_END;
|
||||
}
|
||||
|
||||
void ScientificFormatHelperTest::TestBasic() {
|
||||
UErrorCode status = U_ZERO_ERROR;
|
||||
LocalPointer<DecimalFormat> decfmt((DecimalFormat *) NumberFormat::createScientificInstance("en", status));
|
||||
if (U_FAILURE(status)) {
|
||||
dataerrln("Failed call NumberFormat::createScientificInstance(\"en\", status) - %s", u_errorName(status));
|
||||
return;
|
||||
}
|
||||
UnicodeString appendTo("String: ");
|
||||
FieldPositionIterator fpositer;
|
||||
decfmt->format(1.23456e-78, appendTo, &fpositer, status);
|
||||
FieldPositionIterator fpositer2(fpositer);
|
||||
FieldPositionIterator fpositer3(fpositer);
|
||||
ScientificFormatHelper helper(*decfmt->getDecimalFormatSymbols(), status);
|
||||
UnicodeString result;
|
||||
const char *expected = "String: 1.23456\\u00d710<sup>-78</sup>";
|
||||
assertEquals(
|
||||
"insertMarkup",
|
||||
UnicodeString(expected).unescape(),
|
||||
helper.insertMarkup(appendTo, fpositer, "<sup>", "</sup>", result, status));
|
||||
result.remove();
|
||||
expected = "String: 1.23456\\u00d710\\u207b\\u2077\\u2078";
|
||||
assertEquals(
|
||||
"toSuperscriptExponentDigits",
|
||||
UnicodeString(expected).unescape(),
|
||||
helper.toSuperscriptExponentDigits(appendTo, fpositer2, result, status));
|
||||
assertSuccess("", status);
|
||||
result.remove();
|
||||
|
||||
// The 'a' is an invalid exponent character.
|
||||
helper.toSuperscriptExponentDigits("String: 1.23456e-7a", fpositer3, result, status);
|
||||
if (status != U_INVALID_CHAR_FOUND) {
|
||||
errln("Expected U_INVALID_CHAR_FOUND");
|
||||
}
|
||||
}
|
||||
|
||||
void ScientificFormatHelperTest::TestFarsi() {
|
||||
UErrorCode status = U_ZERO_ERROR;
|
||||
LocalPointer<DecimalFormat> decfmt((DecimalFormat *) NumberFormat::createScientificInstance("fa", status));
|
||||
if (U_FAILURE(status)) {
|
||||
dataerrln("Failed call NumberFormat::createScientificInstance(\"fa\", status) - %s", u_errorName(status));
|
||||
return;
|
||||
}
|
||||
UnicodeString appendTo("String: ");
|
||||
FieldPositionIterator fpositer;
|
||||
decfmt->format(1.23456e-78, appendTo, &fpositer, status);
|
||||
ScientificFormatHelper helper(*decfmt->getDecimalFormatSymbols(), status);
|
||||
UnicodeString result;
|
||||
const char *expected = "String: \\u06F1\\u066B\\u06F2\\u06F3\\u06F4\\u06F5\\u06F6\\u00d7\\u06F1\\u06F0<sup>\\u200E\\u2212\\u06F7\\u06F8</sup>";
|
||||
assertEquals(
|
||||
"insertMarkup",
|
||||
UnicodeString(expected).unescape(),
|
||||
helper.insertMarkup(appendTo, fpositer, "<sup>", "</sup>", result, status));
|
||||
assertSuccess("", status);
|
||||
}
|
||||
|
||||
void ScientificFormatHelperTest::TestPlusSignInExponentMarkup() {
|
||||
UErrorCode status = U_ZERO_ERROR;
|
||||
LocalPointer<DecimalFormat> decfmt((DecimalFormat *) NumberFormat::createScientificInstance("en", status));
|
||||
if (U_FAILURE(status)) {
|
||||
dataerrln("Failed call NumberFormat::createScientificInstance(\"en\", status) - %s", u_errorName(status));
|
||||
return;
|
||||
}
|
||||
decfmt->applyPattern("0.00E+0", status);
|
||||
assertSuccess("", status);
|
||||
UnicodeString appendTo;
|
||||
FieldPositionIterator fpositer;
|
||||
decfmt->format(6.02e23, appendTo, &fpositer, status);
|
||||
ScientificFormatHelper helper(*decfmt->getDecimalFormatSymbols(), status);
|
||||
UnicodeString result;
|
||||
const char *expected = "6.02\\u00d710<sup>+23</sup>";
|
||||
assertEquals(
|
||||
"",
|
||||
UnicodeString(expected).unescape(),
|
||||
helper.insertMarkup(appendTo, fpositer, "<sup>", "</sup>", result, status));
|
||||
assertSuccess("", status);
|
||||
}
|
||||
|
||||
void ScientificFormatHelperTest::TestPlusSignInExponentSuperscript() {
|
||||
UErrorCode status = U_ZERO_ERROR;
|
||||
LocalPointer<DecimalFormat> decfmt((DecimalFormat *) NumberFormat::createScientificInstance("en", status));
|
||||
if (U_FAILURE(status)) {
|
||||
dataerrln("Failed call NumberFormat::createScientificInstance(\"en\", status) - %s", u_errorName(status));
|
||||
return;
|
||||
}
|
||||
decfmt->applyPattern("0.00E+0", status);
|
||||
assertSuccess("", status);
|
||||
UnicodeString appendTo;
|
||||
FieldPositionIterator fpositer;
|
||||
decfmt->format(6.02e23, appendTo, &fpositer, status);
|
||||
ScientificFormatHelper helper(*decfmt->getDecimalFormatSymbols(), status);
|
||||
UnicodeString result;
|
||||
const char *expected = "6.02\\u00d710\\u207a\\u00b2\\u00b3";
|
||||
assertEquals(
|
||||
"",
|
||||
UnicodeString(expected).unescape(),
|
||||
helper.toSuperscriptExponentDigits(appendTo, fpositer, result, status));
|
||||
assertSuccess("", status);
|
||||
}
|
||||
|
||||
void ScientificFormatHelperTest::TestFixedDecimalMarkup() {
|
||||
UErrorCode status = U_ZERO_ERROR;
|
||||
LocalPointer<DecimalFormat> decfmt((DecimalFormat *) NumberFormat::createInstance("en", status));
|
||||
if (assertSuccess("NumberFormat::createInstance", status, TRUE) == FALSE) {
|
||||
return;
|
||||
}
|
||||
UnicodeString appendTo;
|
||||
FieldPositionIterator fpositer;
|
||||
decfmt->format(123456.0, appendTo, &fpositer, status);
|
||||
ScientificFormatHelper helper(*decfmt->getDecimalFormatSymbols(), status);
|
||||
assertSuccess("", status);
|
||||
UnicodeString result;
|
||||
helper.insertMarkup(appendTo, fpositer, "<sup>", "</sup>", result, status);
|
||||
const char *expected = "123,456";
|
||||
assertEquals(
|
||||
"",
|
||||
UnicodeString(expected).unescape(),
|
||||
result);
|
||||
assertSuccess("", status);
|
||||
}
|
||||
|
||||
void ScientificFormatHelperTest::TestFixedDecimalSuperscript() {
|
||||
UErrorCode status = U_ZERO_ERROR;
|
||||
LocalPointer<DecimalFormat> decfmt((DecimalFormat *) NumberFormat::createInstance("en", status));
|
||||
if (assertSuccess("NumberFormat::createInstance", status, TRUE) == FALSE) {
|
||||
return;
|
||||
}
|
||||
UnicodeString appendTo;
|
||||
FieldPositionIterator fpositer;
|
||||
decfmt->format(123456.0, appendTo, &fpositer, status);
|
||||
ScientificFormatHelper helper(*decfmt->getDecimalFormatSymbols(), status);
|
||||
assertSuccess("", status);
|
||||
UnicodeString result;
|
||||
helper.toSuperscriptExponentDigits(appendTo, fpositer, result, status);
|
||||
const char *expected = "123,456";
|
||||
assertEquals(
|
||||
"",
|
||||
UnicodeString(expected).unescape(),
|
||||
result);
|
||||
assertSuccess("", status);
|
||||
}
|
||||
|
||||
extern IntlTest *createScientificFormatHelperTest() {
|
||||
return new ScientificFormatHelperTest();
|
||||
}
|
||||
|
||||
#endif /* !UCONFIG_NO_FORMATTING */
|
Loading…
Add table
Reference in a new issue