Refactor.

This commit is contained in:
Stephen Chung
2022-10-10 16:46:35 +08:00
parent 796206f293
commit d6b0f99781
15 changed files with 161 additions and 166 deletions

View File

@@ -239,10 +239,9 @@ mod string_functions {
/// Clear the string, making it empty.
pub fn clear(string: &mut ImmutableString) {
if !string.is_empty() {
if let Some(s) = string.get_mut() {
s.clear();
} else {
*string = ImmutableString::new();
match string.get_mut() {
Some(s) => s.clear(),
_ => *string = ImmutableString::new(),
}
}
}
@@ -287,17 +286,20 @@ mod string_functions {
/// print(text); // prints "hello"
/// ```
pub fn trim(string: &mut ImmutableString) {
if let Some(s) = string.get_mut() {
let trimmed = s.trim();
match string.get_mut() {
Some(s) => {
let trimmed = s.trim();
if trimmed != s {
*s = trimmed.into();
if trimmed != s {
*s = trimmed.into();
}
}
} else {
let trimmed = string.trim();
None => {
let trimmed = string.trim();
if trimmed != string {
*string = trimmed.into();
if trimmed != string {
*string = trimmed.into();
}
}
}
}