Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches

◆ AppendFormatHelper()

StringBuilder System.Text.StringBuilder.AppendFormatHelper ( IFormatProvider provider,
string format,
ParamsArray args )
inlinepackage

Definition at line 1553 of file StringBuilder.cs.

1554 {
1555 if (format == null)
1556 {
1557 throw new ArgumentNullException("format");
1558 }
1559 int num = 0;
1560 int length = format.Length;
1561 char c = '\0';
1562 ICustomFormatter customFormatter = null;
1563 if (provider != null)
1564 {
1565 customFormatter = (ICustomFormatter)provider.GetFormat(typeof(ICustomFormatter));
1566 }
1567 while (true)
1568 {
1569 if (num < length)
1570 {
1571 c = format[num];
1572 num++;
1573 if (c == '}')
1574 {
1575 if (num < length && format[num] == '}')
1576 {
1577 num++;
1578 }
1579 else
1580 {
1581 FormatError();
1582 }
1583 }
1584 else if (c == '{')
1585 {
1586 if (num >= length || format[num] != '{')
1587 {
1588 num--;
1589 goto IL_008f;
1590 }
1591 num++;
1592 }
1593 Append(c);
1594 continue;
1595 }
1596 goto IL_008f;
1597 IL_008f:
1598 if (num == length)
1599 {
1600 break;
1601 }
1602 num++;
1603 if (num == length || (c = format[num]) < '0' || c > '9')
1604 {
1605 FormatError();
1606 }
1607 int num2 = 0;
1608 do
1609 {
1610 num2 = num2 * 10 + c - 48;
1611 num++;
1612 if (num == length)
1613 {
1614 FormatError();
1615 }
1616 c = format[num];
1617 }
1618 while (c >= '0' && c <= '9' && num2 < 1000000);
1619 if (num2 >= args.Length)
1620 {
1621 throw new FormatException(SR.Format_IndexOutOfRange);
1622 }
1623 for (; num < length; num++)
1624 {
1625 if ((c = format[num]) != ' ')
1626 {
1627 break;
1628 }
1629 }
1630 bool flag = false;
1631 int num3 = 0;
1632 if (c == ',')
1633 {
1634 for (num++; num < length && format[num] == ' '; num++)
1635 {
1636 }
1637 if (num == length)
1638 {
1639 FormatError();
1640 }
1641 c = format[num];
1642 if (c == '-')
1643 {
1644 flag = true;
1645 num++;
1646 if (num == length)
1647 {
1648 FormatError();
1649 }
1650 c = format[num];
1651 }
1652 if (c < '0' || c > '9')
1653 {
1654 FormatError();
1655 }
1656 do
1657 {
1658 num3 = num3 * 10 + c - 48;
1659 num++;
1660 if (num == length)
1661 {
1662 FormatError();
1663 }
1664 c = format[num];
1665 }
1666 while (c >= '0' && c <= '9' && num3 < 1000000);
1667 }
1668 for (; num < length; num++)
1669 {
1670 if ((c = format[num]) != ' ')
1671 {
1672 break;
1673 }
1674 }
1675 object obj = args[num2];
1677 switch (c)
1678 {
1679 case ':':
1680 {
1681 num++;
1682 int num4 = num;
1683 while (true)
1684 {
1685 if (num == length)
1686 {
1687 FormatError();
1688 }
1689 c = format[num];
1690 switch (c)
1691 {
1692 case '{':
1693 FormatError();
1694 goto IL_0205;
1695 default:
1696 goto IL_0205;
1697 case '}':
1698 break;
1699 }
1700 break;
1701 IL_0205:
1702 num++;
1703 }
1704 if (num > num4)
1705 {
1706 readOnlySpan = format.AsSpan(num4, num - num4);
1707 }
1708 break;
1709 }
1710 default:
1711 FormatError();
1712 break;
1713 case '}':
1714 break;
1715 }
1716 num++;
1717 string text = null;
1718 string text2 = null;
1719 if (customFormatter != null)
1720 {
1721 if (readOnlySpan.Length != 0)
1722 {
1723 text2 = new string(readOnlySpan);
1724 }
1726 }
1727 if (text == null)
1728 {
1729 if (obj is ISpanFormattable spanFormattable && (flag || num3 == 0) && spanFormattable.TryFormat(RemainingCurrentChunk, out var charsWritten, readOnlySpan, provider))
1730 {
1731 if ((uint)charsWritten > (uint)RemainingCurrentChunk.Length)
1732 {
1733 FormatError();
1734 }
1736 int num5 = num3 - charsWritten;
1737 if (flag && num5 > 0)
1738 {
1739 Append(' ', num5);
1740 }
1741 continue;
1742 }
1743 if (obj is IFormattable formattable)
1744 {
1745 if (readOnlySpan.Length != 0 && text2 == null)
1746 {
1747 text2 = new string(readOnlySpan);
1748 }
1749 text = formattable.ToString(text2, provider);
1750 }
1751 else if (obj != null)
1752 {
1753 text = obj.ToString();
1754 }
1755 }
1756 if (text == null)
1757 {
1758 text = string.Empty;
1759 }
1760 int num6 = num3 - text.Length;
1761 if (!flag && num6 > 0)
1762 {
1763 Append(' ', num6);
1764 }
1765 Append(text);
1766 if (flag && num6 > 0)
1767 {
1768 Append(' ', num6);
1769 }
1770 }
1771 return this;
1772 }
Span< char > RemainingCurrentChunk
StringBuilder Append(char value, int repeatCount)
int Length
Definition Span.cs:70

References System.Text.StringBuilder.Append(), System.Runtime.Serialization.Dictionary, System.format, System.SR.Format_IndexOutOfRange, System.Text.StringBuilder.FormatError(), System.length, System.Span< T >.Length, System.Text.StringBuilder.m_ChunkLength, System.obj, System.Text.StringBuilder.RemainingCurrentChunk, and System.text.

Referenced by System.Text.StringBuilder.AppendFormat(), System.Text.StringBuilder.AppendFormat(), System.Text.StringBuilder.AppendFormat(), System.Text.StringBuilder.AppendFormat(), System.Text.StringBuilder.AppendFormat(), System.Text.StringBuilder.AppendFormat(), System.Text.StringBuilder.AppendFormat(), and System.Text.StringBuilder.AppendFormat().