mirror of
https://github.com/storytold/gridcraft.git
synced 2026-11-30 10:13:56 +01:00
Move cap_text above the test module
This commit is contained in:
1 parent
15661dc973
commit
0ddd8684ef
1 file changed
+13
-13
+13
-13
@@ -389,6 +389,19 @@ pub fn sci_text(n: f64, sig: usize) -> String {
|
||||
format!("{}E{}{:02}", mant, if e < 0 { '-' } else { '+' }, e.abs())
|
||||
}
|
||||
|
||||
/// Longest text a cell can hold, in characters.
|
||||
pub const MAX_TEXT_CHARS: usize = 32_767;
|
||||
|
||||
/// `s` cut to [`MAX_TEXT_CHARS`] characters, as Excel cuts typed text and `&` results.
|
||||
pub fn cap_text(mut s: String) -> String {
|
||||
if s.len() > MAX_TEXT_CHARS
|
||||
&& let Some((i, _)) = s.char_indices().nth(MAX_TEXT_CHARS)
|
||||
{
|
||||
s.truncate(i);
|
||||
}
|
||||
s
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
@@ -462,16 +475,3 @@ mod tests {
|
||||
assert_eq!(row.get_broadcast(5, 1), Value::Number(2.0));
|
||||
}
|
||||
}
|
||||
|
||||
/// Longest text a cell can hold, in characters.
|
||||
pub const MAX_TEXT_CHARS: usize = 32_767;
|
||||
|
||||
/// `s` cut to [`MAX_TEXT_CHARS`] characters, as Excel cuts typed text and `&` results.
|
||||
pub fn cap_text(mut s: String) -> String {
|
||||
if s.len() > MAX_TEXT_CHARS
|
||||
&& let Some((i, _)) = s.char_indices().nth(MAX_TEXT_CHARS)
|
||||
{
|
||||
s.truncate(i);
|
||||
}
|
||||
s
|
||||
}
|
||||
Reference in new issue
Block a user