Fix incorrect zero format specifier range.
This commit is contained in:
@@ -34,23 +34,25 @@ namespace System.Text.Formatting {
|
|||||||
}
|
}
|
||||||
// Iteration 1: Split by semicolon
|
// Iteration 1: Split by semicolon
|
||||||
int specifierPositiveEnd = IndexOfSectionSeparator(specifier);
|
int specifierPositiveEnd = IndexOfSectionSeparator(specifier);
|
||||||
int specifierNegativeStart = 0, specifierNegativeEnd, specifierZeroStart = 0;
|
int specifierNegativeStart = 0, specifierNegativeEnd, specifierZeroStart = 0, specifierZeroEnd;
|
||||||
if (specifierPositiveEnd == -1) {
|
if (specifierPositiveEnd == -1) {
|
||||||
specifierPositiveEnd = specifierNegativeEnd = specifier.Length;
|
specifierPositiveEnd = specifierNegativeEnd = specifierZeroEnd = specifier.Length;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
specifierNegativeStart = specifierPositiveEnd + 1;
|
specifierNegativeStart = specifierPositiveEnd + 1;
|
||||||
specifierNegativeEnd = IndexOfSectionSeparator(specifier, specifierNegativeStart);
|
specifierNegativeEnd = IndexOfSectionSeparator(specifier, specifierNegativeStart);
|
||||||
if (specifierNegativeEnd == -1) {
|
if (specifierNegativeEnd == -1) {
|
||||||
specifierNegativeEnd = specifier.Length;
|
specifierNegativeEnd = specifier.Length;
|
||||||
|
specifierZeroEnd = specifierPositiveEnd;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
specifierZeroStart = specifierNegativeEnd + 1;
|
specifierZeroStart = specifierNegativeEnd + 1;
|
||||||
|
specifierZeroEnd = specifier.Length;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Special: Handle zero
|
// Special: Handle zero
|
||||||
if (IsZero(ref number)) {
|
if (IsZero(ref number)) {
|
||||||
FormatCustomFormatString(formatter, ref number, null, specifier, specifierZeroStart, specifier.Length, culture);
|
FormatCustomFormatString(formatter, ref number, null, specifier, specifierZeroStart, specifierZeroEnd, culture);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// Iteration 2: Divide and round number
|
// Iteration 2: Divide and round number
|
||||||
@@ -58,7 +60,7 @@ namespace System.Text.Formatting {
|
|||||||
if (number.Sign == 0) ApplyDivisionAndPrecision(ref number, specifier, 0, specifierPositiveEnd);
|
if (number.Sign == 0) ApplyDivisionAndPrecision(ref number, specifier, 0, specifierPositiveEnd);
|
||||||
else ApplyDivisionAndPrecision(ref number, specifier, specifierNegativeStart, specifierNegativeEnd);
|
else ApplyDivisionAndPrecision(ref number, specifier, specifierNegativeStart, specifierNegativeEnd);
|
||||||
// Iteration 3: Count; Iteration 4: Format
|
// Iteration 3: Count; Iteration 4: Format
|
||||||
if (IsZero(ref number)) FormatCustomFormatString(formatter, ref number, null, specifier, specifierZeroStart, specifier.Length, culture);
|
if (IsZero(ref number)) FormatCustomFormatString(formatter, ref number, null, specifier, specifierZeroStart, specifierZeroEnd, culture);
|
||||||
else if (number.Sign == 0) FormatCustomFormatString(formatter, ref number, originalScale, specifier, 0, specifierPositiveEnd, culture);
|
else if (number.Sign == 0) FormatCustomFormatString(formatter, ref number, originalScale, specifier, 0, specifierPositiveEnd, culture);
|
||||||
else {
|
else {
|
||||||
if (specifierNegativeStart == 0) formatter.Append(culture.NegativeSign);
|
if (specifierNegativeStart == 0) formatter.Append(culture.NegativeSign);
|
||||||
|
|||||||
Reference in New Issue
Block a user