The formatting routines account for a considerable part of the SysUtils unit. Some of them are nested and consist in about 1000 lines of code. Nevertheless their translation with Delphi2Cpp 2.x is nearly perfect. Examples to the formatting routines from
DelphiBasicsFormat
were modified slightly to be able to use them for test purposes. The code translated with Delphi2Cpp 2.x compiles and works without additional manual processing without faults.
bool FormatTest1() { bool result = false; result = true; // Just 1 data item result = result && (Format(L"%s", OpenArray(String(L"Hello"))) == L"Hello");
// A mix of literal text and a data item result = result && (Format(L"String = %s", OpenArray(String(L"Hello"))) == L"String = Hello"); //ShowMessage('');
// Examples of each of the data types result = result && (Format(L"Decimal = %d", OpenArray(-123)) == L"Decimal = -123"); result = result && (Format(L"Exponent = %e", OpenArray (12345.678L)) == L"Exponent = 1,23456780000000E+004"); result = result && (Format(L"Fixed = %f", OpenArray (12345.678L)) == L"Fixed = 12345,68"); result = result && (Format(L"General = %g", OpenArray (12345.678L)) == L"General = 12345,678"); result = result && (Format(L"Number = %n", OpenArray (12345.678L)) == L"Number = 12.345,68"); result = result && (Format(L"Money = %m", OpenArray (12345.678L)) == L"Money = 12.345,68 €"); // makes no sense under C# // result := result and (Format('Pointer = %p', [addr(text)]) = 'Pointer = 0069FC90'); result = result && (Format(L"String = %s", OpenArray (String(L"Hello"))) == L"String = Hello"); result = result && (Format(L"Unsigned decimal = %u", OpenArray (123)) == L"Unsigned decimal = 123"); result = result && (Format(L"Hexadecimal = %x", OpenArray (140)) == L"Hexadecimal = 8C"); return result; }
bool FormatTest2() { bool result = false; result = true; // The width value dictates the output size // with blank padding to the left // Note the <> characters are added to show formatting result = result && (Format(L"Padded decimal = <%7d>", OpenArray(1234)) == L"Padded decimal = < 1234>");
// With the '-' operator, the data is left justified result = result && (Format(L"Justified decimal = <%-7d>", OpenArray(1234)) == L"Justified decimal = <1234 >");
// The precision value forces 0 padding to the desired size result = result && (Format(L"0 padded decimal = <%.6d>", OpenArray(1234)) == L"0 padded decimal = <001234>");
// A combination of width and precision // Note that width value precedes the precision value result = result && (Format(L"Width + precision = <%8.6d>", OpenArray(1234)) == L"Width + precision = < 001234>");
// The index value allows the next value in the data array // to be changed result = result && (Format(L"Reposition after 3 strings = %s %s %s %1:s %s", OpenArray(String(L"Zero"), String(L"One"), String(L"Two"), String(L"Three"))) == L"Reposition after 3 strings = Zero One Two One Two");
// One or more of the values may be provided by the // data array itself. Note that testing has shown that an * // for the width parameter can yield EConvertError. result = result && (Format(L"In line = <%10.4d>", OpenArray(1234)) == L"In line = < 1234>"); result = result && (Format(L"Part data driven = <%*.4d>", OpenArray (10, 1234)) == L"Part data driven = < 1234>"); result = result && (Format(L"Data driven = <%*.*d>", OpenArray (10, 4, 1234)) == L"Data driven = < 1234>"); return result; }
bool FloatToStrTest1() { bool result = false; long double amount1 = 0.0L; long double amount2 = 0.0L; long double amount3 = 0.0L; result = true; amount1 = 1234567890.123456789L; // High precision number amount2 = 1234567890123456.123L; // High mantissa digits amount3 = 1E100L; // High value number result = result && (FloatToStr(amount1) == L"1234567890,12346"); result = result && (FloatToStr(amount2) == L"1,23456789012346E15"); result = result && (FloatToStr(amount3) == L"1E100"); return result; }
bool FormatFloatTest1() { bool result = false; long double flt = 0.0L; result = true; // Set up our floating point number flt = 1234.567L;
// Display a sample value using all of the format options
// Round out the decimal value result = result && (FormatFloat(L"#####", flt) == L"1235"); result = result && (FormatFloat(L"00000", flt) == L"01235"); result = result && (FormatFloat(L"0", flt) == L"1235"); result = result && (FormatFloat(L"#,##0", flt) == L"1.235"); result = result && (FormatFloat(L",0", flt) == L"1.235");
// Include the decimal value result = result && (FormatFloat(L"0.####", flt) == L"1234,567"); result = result && (FormatFloat(L"0.0000", flt) == L"1234,5670");
// Scientific format result = result && (FormatFloat(L"0.0000000E+00", flt) == L"1,2345670E+03"); result = result && (FormatFloat(L"0.0000000E-00", flt) == L"1,2345670E03"); result = result && (FormatFloat(L"#.#######E-##", flt) == L"1,234567E3");
// Include freeform text result = result && (FormatFloat(L"\"Value = \"0.0", flt) == L"Value = 1234,6");
// Different formatting for negative numbers result = result && (FormatFloat(L"0.0", -1234.567) == L"-1234,6"); result = result && (FormatFloat(L"0.0 \"CR\";0.0 \"DB\"", -1234.567) == L"1234,6 DB"); result = result && (FormatFloat(L"0.0 \"CR\";0.0 \"DB\"", 1234.567L) == L"1234,6 CR");
// Different format for zero value result = result && (FormatFloat(L"0.0", 0.0L) == L"0,0"); result = result && (FormatFloat(L"0.0;-0.0;\"Nothing\"", 0.0L) == L"Nothing"); return result; }
bool FormatTest() { bool result = false; result = true; result = result && FormatTest1(); result = result && FormatTest2(); result = result && FloatToStrTest1(); result = result && FormatFloatTest1(); return result; }
Deutsch
Latest News |
10/28/24
Delphi2Cpp 2.5: Symbol names matching declaration case [more...] |
08/26/24
Delphi2Cpp 2.4: Updated to RAD Studio 12.1 Athens [more...] |
"Thanks for your great work, really appreciate the work you have done on zlib and compiling ... test case." Mattewada, Udayabhaskar
Nokia India
02/01/2021
|
[from case study...] "A masterpiece -- Delphi2Cpp has exceeded all my expectations by far." Tony Hürlimann
virtual-optima
08/20/2011
|
"First off, I have to say WOW! Delphi2Cpp is doing a *fantastic* job!" Daniel Flower
linkrealms
01/15/2011
|
This website is generated from plain text with [Minimal Website ]
|
Minimal Website
is made with TextTransformer
|
TextTransformer is made with Borland
CBuilder
|