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

Method format_str

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

Source from the content-addressed store, hash-verified

2003 }
2004
2005 fn format_str(&self, writer: &mut String, value: &str) -> Result<()> {
2006 // Take care of precision, putting the truncated string in `content`
2007 let precision: usize = match self.precision {
2008 NumericParam::Literal(p) => p,
2009 _ => i32::MAX,
2010 }
2011 .try_into()
2012 .unwrap_or_default();
2013 let content_len = {
2014 let mut content_len = precision.min(value.len());
2015 while !value.is_char_boundary(content_len) {
2016 content_len -= 1;
2017 }
2018 content_len
2019 };
2020 let content = &value[..content_len];
2021
2022 // Pad to width if needed, putting the padded string in `s`
2023
2024 if let NumericParam::Literal(width) = self.width {
2025 let start_len = writer.len();
2026 if self.left_adj {
2027 writer.push_str(content);
2028 while writer.len() - start_len < width as usize {
2029 writer.push(' ');
2030 }
2031 } else {
2032 while writer.len() - start_len + content.len() < width as usize {
2033 writer.push(' ');
2034 }
2035 writer.push_str(content);
2036 }
2037 } else {
2038 writer.push_str(content);
2039 }
2040 Ok(())
2041 }
2042
2043 fn format_string(&self, writer: &mut String, value: &str) -> Result<()> {
2044 if self.conversion_type.is_upper() {

Callers 2

format_booleanMethod · 0.80
format_stringMethod · 0.80

Calls 3

minMethod · 0.45
lenMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected