diff options
Diffstat (limited to 'azalea-chat/src')
| -rw-r--r-- | azalea-chat/src/component.rs | 40 | ||||
| -rw-r--r-- | azalea-chat/src/style.rs | 11 | ||||
| -rw-r--r-- | azalea-chat/src/text_component.rs | 14 | ||||
| -rw-r--r-- | azalea-chat/src/translatable_component.rs | 76 |
4 files changed, 68 insertions, 73 deletions
diff --git a/azalea-chat/src/component.rs b/azalea-chat/src/component.rs index c3cc5224..637aafc7 100644 --- a/azalea-chat/src/component.rs +++ b/azalea-chat/src/component.rs @@ -100,13 +100,13 @@ impl FormattedText { /// })).unwrap(); /// /// let ansi = component.to_custom_format( - /// |running, new| (running.compare_ansi(new), "".to_string()), + /// |running, new| (running.compare_ansi(new), "".to_owned()), /// |text| text.to_string(), /// |style| { /// if !style.is_empty() { - /// "\u{1b}[m".to_string() + /// "\u{1b}[m".to_owned() /// } else { - /// "".to_string() + /// "".to_owned() /// } /// }, /// &DEFAULT_STYLE, @@ -207,8 +207,8 @@ impl FormattedText { pub fn to_ansi_with_custom_style(&self, default_style: &Style) -> String { self.to_custom_format( |running, new| (running.compare_ansi(new), "".to_owned()), - |text| text.to_string(), - |style| if !style.is_empty() { "\u{1b}[m" } else { "" }.to_string(), + |text| text.to_owned(), + |style| if !style.is_empty() { "\u{1b}[m" } else { "" }.to_owned(), default_style, ) } @@ -260,7 +260,7 @@ impl FormattedText { .replace(">", ">") .replace("\n", "<br>") }, - |_| "".to_string(), + |_| "".to_owned(), &DEFAULT_STYLE, ) } @@ -297,13 +297,13 @@ impl<'de> Deserialize<'de> for FormattedText { // if it's primitive, make it a text component if !json.is_array() && !json.is_object() { return Ok(FormattedText::Text(TextComponent::new( - json.as_str().unwrap_or("").to_string(), + json.as_str().unwrap_or("").to_owned(), ))); } // if it's an object, do things with { text } and stuff else if json.is_object() { if let Some(text) = json.get("text") { - let text = text.as_str().unwrap_or("").to_string(); + let text = text.as_str().unwrap_or("").to_owned(); component = FormattedText::Text(TextComponent::new(text)); } else if let Some(translate) = json.get("translate") { let translate = translate @@ -315,7 +315,7 @@ impl<'de> Deserialize<'de> for FormattedText { fallback .as_str() .ok_or_else(|| de::Error::custom("\"fallback\" must be a string"))? - .to_string(), + .to_owned(), ) } else { None @@ -530,7 +530,7 @@ impl FormattedText { warn!( "couldn't parse {item:?} as FormattedText because it has a disallowed primitive" ); - with_array.push(PrimitiveOrComponent::String("?".to_string())); + with_array.push(PrimitiveOrComponent::String("?".to_owned())); } } else if let Some(c) = FormattedText::from_nbt_compound(item) { if let FormattedText::Text(text_component) = c @@ -545,7 +545,7 @@ impl FormattedText { )); } else { warn!("couldn't parse {item:?} as FormattedText"); - with_array.push(PrimitiveOrComponent::String("?".to_string())); + with_array.push(PrimitiveOrComponent::String("?".to_owned())); } } } else { @@ -672,7 +672,7 @@ impl From<String> for FormattedText { } impl From<&str> for FormattedText { fn from(s: &str) -> Self { - Self::from(s.to_string()) + Self::from(s.to_owned()) } } impl From<TranslatableComponent> for FormattedText { @@ -721,10 +721,10 @@ mod tests { assert_eq!( component, FormattedText::Translatable(TranslatableComponent::new( - "translation.test.args".to_string(), + "translation.test.args".to_owned(), vec![ - PrimitiveOrComponent::String("a".to_string()), - PrimitiveOrComponent::String("b".to_string()) + PrimitiveOrComponent::String("a".to_owned()), + PrimitiveOrComponent::String("b".to_owned()) ] )) ); @@ -744,9 +744,9 @@ mod tests { assert_eq!( component, FormattedText::Translatable(TranslatableComponent::with_fallback( - "translation.test.undefined".to_string(), - Some("fallback: %s".to_string()), - vec![PrimitiveOrComponent::String("a".to_string())] + "translation.test.undefined".to_owned(), + Some("fallback: %s".to_owned()), + vec![PrimitiveOrComponent::String("a".to_owned())] )) ); } @@ -768,11 +768,11 @@ mod tests { assert_eq!( FormattedText::deserialize(&j).unwrap(), FormattedText::Translatable(TranslatableComponent::new( - "commands.list.players".to_string(), + "commands.list.players".to_owned(), vec![ PrimitiveOrComponent::Short(1), PrimitiveOrComponent::Integer(65536), - PrimitiveOrComponent::String("<players>".to_string()), + PrimitiveOrComponent::String("<players>".to_owned()), PrimitiveOrComponent::FormattedText(FormattedText::Text( TextComponent::new("unused") .with_style(Style::new().color(Some(TextColor::parse("red").unwrap()))) diff --git a/azalea-chat/src/style.rs b/azalea-chat/src/style.rs index 4982a915..7792f812 100644 --- a/azalea-chat/src/style.rs +++ b/azalea-chat/src/style.rs @@ -62,7 +62,7 @@ static LEGACY_FORMAT_TO_COLOR: LazyLock<HashMap<&'static ChatFormatting, TextCol formatter, TextColor { value: formatter.color().unwrap(), - name: Some(formatter.name().to_string()), + name: Some(formatter.name().to_owned()), }, ); } @@ -300,7 +300,7 @@ impl TryFrom<ChatFormatting> for TextColor { return Err(format!("{} is not a color", formatter.name())); } let color = formatter.color().unwrap_or(0); - Ok(Self::new(color, Some(formatter.name().to_string()))) + Ok(Self::new(color, Some(formatter.name().to_owned()))) } } @@ -412,11 +412,8 @@ impl Style { insertion: j .get("insertion") .and_then(|v| v.as_str()) - .map(|s| s.to_string()), - font: j - .get("font") - .and_then(|v| v.as_str()) - .map(|s| s.to_string()), + .map(|s| s.to_owned()), + font: j.get("font").and_then(|v| v.as_str()).map(|s| s.to_owned()), } } diff --git a/azalea-chat/src/text_component.rs b/azalea-chat/src/text_component.rs index c21e2d46..ec89a7c9 100644 --- a/azalea-chat/src/text_component.rs +++ b/azalea-chat/src/text_component.rs @@ -95,7 +95,7 @@ pub fn legacy_color_code_to_text_component(legacy_color_code: &str) -> TextCompo if !cur_component.text.is_empty() { // we need to split this into a new component components.push(cur_component.clone()); - cur_component.text = "".to_string(); + cur_component.text = "".to_owned(); }; cur_component.base.style.color = TextColor::parse(&color); @@ -104,7 +104,7 @@ pub fn legacy_color_code_to_text_component(legacy_color_code: &str) -> TextCompo if !cur_component.text.is_empty() || formatter == ChatFormatting::Reset { // we need to split this into a new component components.push(cur_component.clone()); - cur_component.text = "".to_string(); + cur_component.text = "".to_owned(); }; cur_component.base.style.apply_formatting(&formatter); } @@ -175,7 +175,7 @@ mod tests { #[test] fn test_hypixel_motd_ansi() { let component = - TextComponent::new("§aHypixel Network §c[1.8-1.18]\n§b§lHAPPY HOLIDAYS".to_string()) + TextComponent::new("§aHypixel Network §c[1.8-1.18]\n§b§lHAPPY HOLIDAYS".to_owned()) .get(); assert_eq!( component.to_ansi(), @@ -193,7 +193,7 @@ mod tests { #[test] fn test_hypixel_motd_html() { let component = - TextComponent::new("§aHypixel Network §c[1.8-1.18]\n§b§lHAPPY HOLIDAYS".to_string()) + TextComponent::new("§aHypixel Network §c[1.8-1.18]\n§b§lHAPPY HOLIDAYS".to_owned()) .get(); assert_eq!( @@ -210,7 +210,7 @@ mod tests { #[test] fn test_xss_html() { - let component = TextComponent::new("§a<b>&\n§b</b>".to_string()).get(); + let component = TextComponent::new("§a<b>&\n§b</b>".to_owned()).get(); assert_eq!( component.to_html(), @@ -225,7 +225,7 @@ mod tests { #[test] fn test_legacy_color_code_to_component() { - let component = TextComponent::new("§lHello §r§1w§2o§3r§4l§5d".to_string()).get(); + let component = TextComponent::new("§lHello §r§1w§2o§3r§4l§5d".to_owned()).get(); assert_eq!( component.to_ansi(), format!( @@ -244,7 +244,7 @@ mod tests { #[test] fn test_legacy_color_code_with_rgb() { - let component = TextComponent::new("§#Ff0000This is a test message".to_string()).get(); + let component = TextComponent::new("§#Ff0000This is a test message".to_owned()).get(); assert_eq!( component.to_ansi(), format!( diff --git a/azalea-chat/src/translatable_component.rs b/azalea-chat/src/translatable_component.rs index ae1d80bc..f6be2aa5 100644 --- a/azalea-chat/src/translatable_component.rs +++ b/azalea-chat/src/translatable_component.rs @@ -130,7 +130,7 @@ impl TranslatableComponent { .args .get(matched) .cloned() - .unwrap_or_else(|| PrimitiveOrComponent::String("".to_string())); + .unwrap_or_else(|| PrimitiveOrComponent::String("".to_owned())); components.push(TextComponent::new(built_text.clone())); built_text.clear(); @@ -148,9 +148,7 @@ impl TranslatableComponent { &self .args .get((d - 1) as usize) - .unwrap_or(&PrimitiveOrComponent::String( - "".to_string(), - )) + .unwrap_or(&PrimitiveOrComponent::String("".to_owned())) .to_string(), ); } else { @@ -183,7 +181,7 @@ impl TranslatableComponent { siblings: components.into_iter().map(FormattedText::Text).collect(), style: Default::default(), }, - text: "".to_string(), + text: "".to_owned(), }) } } @@ -238,7 +236,7 @@ impl From<PrimitiveOrComponent> for TextComponent { } impl From<&str> for TranslatableComponent { fn from(s: &str) -> Self { - TranslatableComponent::new(s.to_string(), vec![]) + TranslatableComponent::new(s.to_owned(), vec![]) } } @@ -248,88 +246,88 @@ mod tests { #[test] fn test_none() { - let c = TranslatableComponent::new("translation.test.none".to_string(), vec![]); - assert_eq!(c.read().unwrap().to_string(), "Hello, world!".to_string()); + let c = TranslatableComponent::new("translation.test.none".to_owned(), vec![]); + assert_eq!(c.read().unwrap().to_string(), "Hello, world!".to_owned()); } #[test] fn test_complex() { let c = TranslatableComponent::new( - "translation.test.complex".to_string(), + "translation.test.complex".to_owned(), vec![ - PrimitiveOrComponent::String("a".to_string()), - PrimitiveOrComponent::String("b".to_string()), - PrimitiveOrComponent::String("c".to_string()), - PrimitiveOrComponent::String("d".to_string()), + PrimitiveOrComponent::String("a".to_owned()), + PrimitiveOrComponent::String("b".to_owned()), + PrimitiveOrComponent::String("c".to_owned()), + PrimitiveOrComponent::String("d".to_owned()), ], ); // so true mojang assert_eq!( c.read().unwrap().to_string(), - "Prefix, ab again b and a lastly c and also a again!".to_string() + "Prefix, ab again b and a lastly c and also a again!".to_owned() ); } #[test] fn test_escape() { let c = TranslatableComponent::new( - "translation.test.escape".to_string(), + "translation.test.escape".to_owned(), vec![ - PrimitiveOrComponent::String("a".to_string()), - PrimitiveOrComponent::String("b".to_string()), - PrimitiveOrComponent::String("c".to_string()), - PrimitiveOrComponent::String("d".to_string()), + PrimitiveOrComponent::String("a".to_owned()), + PrimitiveOrComponent::String("b".to_owned()), + PrimitiveOrComponent::String("c".to_owned()), + PrimitiveOrComponent::String("d".to_owned()), ], ); - assert_eq!(c.read().unwrap().to_string(), "%s %a %%s %%b".to_string()); + assert_eq!(c.read().unwrap().to_string(), "%s %a %%s %%b".to_owned()); } #[test] fn test_invalid() { let c = TranslatableComponent::new( - "translation.test.invalid".to_string(), + "translation.test.invalid".to_owned(), vec![ - PrimitiveOrComponent::String("a".to_string()), - PrimitiveOrComponent::String("b".to_string()), - PrimitiveOrComponent::String("c".to_string()), - PrimitiveOrComponent::String("d".to_string()), + PrimitiveOrComponent::String("a".to_owned()), + PrimitiveOrComponent::String("b".to_owned()), + PrimitiveOrComponent::String("c".to_owned()), + PrimitiveOrComponent::String("d".to_owned()), ], ); - assert_eq!(c.read().unwrap().to_string(), "hi %".to_string()); + assert_eq!(c.read().unwrap().to_string(), "hi %".to_owned()); } #[test] fn test_invalid2() { let c = TranslatableComponent::new( - "translation.test.invalid2".to_string(), + "translation.test.invalid2".to_owned(), vec![ - PrimitiveOrComponent::String("a".to_string()), - PrimitiveOrComponent::String("b".to_string()), - PrimitiveOrComponent::String("c".to_string()), - PrimitiveOrComponent::String("d".to_string()), + PrimitiveOrComponent::String("a".to_owned()), + PrimitiveOrComponent::String("b".to_owned()), + PrimitiveOrComponent::String("c".to_owned()), + PrimitiveOrComponent::String("d".to_owned()), ], ); - assert_eq!(c.read().unwrap().to_string(), "hi % s".to_string()); + assert_eq!(c.read().unwrap().to_string(), "hi % s".to_owned()); } #[test] fn test_undefined() { let c = TranslatableComponent::new( - "translation.test.undefined".to_string(), - vec![PrimitiveOrComponent::String("a".to_string())], + "translation.test.undefined".to_owned(), + vec![PrimitiveOrComponent::String("a".to_owned())], ); assert_eq!( c.read().unwrap().to_string(), - "translation.test.undefined".to_string() + "translation.test.undefined".to_owned() ); } #[test] fn test_undefined_with_fallback() { let c = TranslatableComponent::with_fallback( - "translation.test.undefined".to_string(), - Some("translation fallback: %s".to_string()), - vec![PrimitiveOrComponent::String("a".to_string())], + "translation.test.undefined".to_owned(), + Some("translation fallback: %s".to_owned()), + vec![PrimitiveOrComponent::String("a".to_owned())], ); assert_eq!( c.read().unwrap().to_string(), - "translation fallback: a".to_string() + "translation fallback: a".to_owned() ); } } |
