diff --git a/core/src/avm2/globals/avmplus.rs b/core/src/avm2/globals/avmplus.rs index 68e249eba6c1..780eb66bdae2 100644 --- a/core/src/avm2/globals/avmplus.rs +++ b/core/src/avm2/globals/avmplus.rs @@ -541,7 +541,7 @@ fn display_name<'gc>( if let Some(name) = name { name.to_qualified_name_or_star(context) } else { - context.get_ascii_char('*') + context.ascii_char(b'*') } } diff --git a/core/src/avm2/globals/string.rs b/core/src/avm2/globals/string.rs index 8bcff3ca04d0..a9ca47948338 100644 --- a/core/src/avm2/globals/string.rs +++ b/core/src/avm2/globals/string.rs @@ -130,7 +130,7 @@ fn char_at<'gc>( let index = if !n.is_nan() { n as usize } else { 0 }; let ret = if let Some(c) = s.get(index) { - activation.strings().get_char(c) + activation.strings().make_char(c) } else { activation.strings().empty() }; @@ -449,7 +449,7 @@ fn slice<'gc>( if start_index < end_index { Ok(activation .strings() - .substring(this, start_index, end_index) + .substring(this, start_index..end_index) .into()) } else { Ok("".into()) @@ -486,7 +486,7 @@ fn split<'gc>( // Special case this to match Flash's behavior. this.iter() .take(limit) - .map(|c| Value::from(activation.strings().get_char(c))) + .map(|c| Value::from(activation.strings().make_char(c))) .collect() } else { this.split(&delimiter) @@ -551,7 +551,7 @@ fn substr<'gc>( Ok(activation .strings() - .substring(this, start_index, end_index) + .substring(this, start_index..end_index) .into()) } @@ -588,7 +588,7 @@ fn substring<'gc>( Ok(activation .strings() - .substring(this, start_index, end_index) + .substring(this, start_index..end_index) .into()) } diff --git a/core/src/avm2/multiname.rs b/core/src/avm2/multiname.rs index 2cf0962c9015..b9ca0161fc00 100644 --- a/core/src/avm2/multiname.rs +++ b/core/src/avm2/multiname.rs @@ -477,7 +477,7 @@ impl<'gc> Multiname<'gc> { /// This is used by `describeType` pub fn to_qualified_name_or_star(&self, context: &mut StringContext<'gc>) -> AvmString<'gc> { if self.is_any_name() { - context.get_ascii_char('*') + context.ascii_char(b'*') } else { self.to_qualified_name(context.gc_context) } diff --git a/core/src/avm2/property.rs b/core/src/avm2/property.rs index f5acf97c4129..ea5c2cddc9fd 100644 --- a/core/src/avm2/property.rs +++ b/core/src/avm2/property.rs @@ -116,7 +116,7 @@ impl<'gc> PropertyClass<'gc> { match self { PropertyClass::Class(class) => class.name().to_qualified_name(context.gc_context), PropertyClass::Name(name, _) => name.to_qualified_name_or_star(context), - PropertyClass::Any => context.get_ascii_char('*'), + PropertyClass::Any => context.ascii_char(b'*'), } } } diff --git a/core/src/avm2/value.rs b/core/src/avm2/value.rs index 88bc80b0cad8..eb0d2ccd59b7 100644 --- a/core/src/avm2/value.rs +++ b/core/src/avm2/value.rs @@ -839,7 +839,7 @@ impl<'gc> Value<'gc> { } Value::Integer(i) => { if *i >= 0 && *i < 10 { - activation.strings().get_char('0' as u16 + *i as u16) + activation.strings().make_char('0' as u16 + *i as u16) } else { AvmString::new_utf8(activation.context.gc_context, i.to_string()) } diff --git a/core/src/string/context.rs b/core/src/string/context.rs index b6a0d90688cb..a589746a9ee5 100644 --- a/core/src/string/context.rs +++ b/core/src/string/context.rs @@ -1,4 +1,4 @@ -use std::borrow::Cow; +use std::{borrow::Cow, ops::Range}; use gc_arena::{Gc, Mutation}; @@ -76,7 +76,7 @@ impl<'gc> StringContext<'gc> { } #[must_use] - pub fn get_char(&self, c: u16) -> AvmString<'gc> { + pub fn make_char(&self, c: u16) -> AvmString<'gc> { if let Some(s) = self.interner.chars.get(c as usize) { (*s).into() } else { @@ -84,20 +84,15 @@ impl<'gc> StringContext<'gc> { } } - // Like get_char, but panics if the passed char is not ASCII. + /// Like `make_char`, but panics if the passed char is not ASCII. #[must_use] - pub fn get_ascii_char(&self, c: char) -> AvmString<'gc> { + pub fn ascii_char(&self, c: u8) -> AvmString<'gc> { self.interner.chars[c as usize].into() } #[must_use] - pub fn substring( - &self, - s: AvmString<'gc>, - start_index: usize, - end_index: usize, - ) -> AvmString<'gc> { + pub fn substring(&self, s: AvmString<'gc>, range: Range) -> AvmString<'gc> { self.interner - .substring(self.gc(), s, start_index, end_index) + .substring(self.gc(), s, range.start, range.end) } }