MCPcopy Create free account
hub / github.com/apache/datafusion / format_char

Method format_char

datafusion/spark/src/function/string/format_string.rs:1676–1716  ·  view source on GitHub ↗
(&self, writer: &mut String, value: char)

Source from the content-addressed store, hash-verified

1674 }
1675
1676 fn format_char(&self, writer: &mut String, value: char) -> Result<()> {
1677 let upper = self.conversion_type.is_upper();
1678 match self.conversion_type {
1679 ConversionType::CharLower | ConversionType::CharUpper => {
1680 let NumericParam::Literal(width) = self.width else {
1681 if upper {
1682 writer.push(value.to_ascii_uppercase());
1683 } else {
1684 writer.push(value);
1685 }
1686 return Ok(());
1687 };
1688
1689 let start_len = writer.len();
1690 if self.left_adj {
1691 if upper {
1692 writer.push(value.to_ascii_uppercase());
1693 } else {
1694 writer.push(value);
1695 }
1696 while writer.len() - start_len < width as usize {
1697 writer.push(' ');
1698 }
1699 } else {
1700 while writer.len() - start_len + value.len_utf8() < width as usize {
1701 writer.push(' ');
1702 }
1703 if upper {
1704 writer.push(value.to_ascii_uppercase());
1705 } else {
1706 writer.push(value);
1707 }
1708 }
1709 Ok(())
1710 }
1711 _ => exec_err!(
1712 "Invalid conversion type: {:?} for char",
1713 self.conversion_type
1714 ),
1715 }
1716 }
1717
1718 fn format_boolean(&self, writer: &mut String, value: &Option<bool>) -> Result<()> {
1719 let value = value.unwrap_or(false);

Callers 1

formatMethod · 0.80

Calls 3

is_upperMethod · 0.80
pushMethod · 0.45
lenMethod · 0.45

Tested by

no test coverage detected