1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
//! String case conversion operations.
//!
//! # Examples
//!
//! ```rust,no_run
//! use cudf::Column;
//!
//! let col = Column::from_strings(&["hello", "WORLD"]).unwrap();
//! let upper = col.str_to_upper().unwrap();
//! let lower = col.str_to_lower().unwrap();
//! ```
use crate::column::Column;
use crate::error::{CudfError, Result};
impl Column {
/// Convert all characters in each string to uppercase.
pub fn str_to_upper(&self) -> Result<Column> {
let result =
cudf_cxx::strings::case::ffi::str_to_upper(&self.inner).map_err(CudfError::from_cxx)?;
Ok(Column { inner: result })
}
/// Convert all characters in each string to lowercase.
pub fn str_to_lower(&self) -> Result<Column> {
let result =
cudf_cxx::strings::case::ffi::str_to_lower(&self.inner).map_err(CudfError::from_cxx)?;
Ok(Column { inner: result })
}
/// Swap the case of all characters in each string.
pub fn str_swapcase(&self) -> Result<Column> {
let result =
cudf_cxx::strings::case::ffi::str_swapcase(&self.inner).map_err(CudfError::from_cxx)?;
Ok(Column { inner: result })
}
/// Capitalize the first character of each string (or each word).
///
/// If `delimiters` is empty, only the first character of each string
/// is capitalized. Otherwise, a non-delimiter character is capitalized
/// after any delimiter character.
pub fn str_capitalize(&self, delimiters: &str) -> Result<Column> {
let result = cudf_cxx::strings::case::ffi::str_capitalize(&self.inner, delimiters)
.map_err(CudfError::from_cxx)?;
Ok(Column { inner: result })
}
/// Convert each string to title case.
///
/// The first character of each word is upper-cased, and the rest
/// are lower-cased. A word is a sequence of alpha characters.
pub fn str_title(&self) -> Result<Column> {
let result =
cudf_cxx::strings::case::ffi::str_title(&self.inner).map_err(CudfError::from_cxx)?;
Ok(Column { inner: result })
}
/// Check if each string is in title case.
///
/// Returns a BOOL8 column where `true` indicates the string
/// is in title format (first char of each word is upper-case,
/// rest are lower-case).
pub fn str_is_title(&self) -> Result<Column> {
let result =
cudf_cxx::strings::case::ffi::str_is_title(&self.inner).map_err(CudfError::from_cxx)?;
Ok(Column { inner: result })
}
}