Rename startsWithCodePt to startsWithScalar

This commit is contained in:
Richard Feldman 2022-07-02 15:19:04 -04:00
parent c9e52b8311
commit af05723d35
No known key found for this signature in database
GPG key ID: 7E4127D1E4241798
13 changed files with 30 additions and 30 deletions

View file

@ -160,7 +160,7 @@ comptime {
exportStrFn(str.countSegments, "count_segments"); exportStrFn(str.countSegments, "count_segments");
exportStrFn(str.countGraphemeClusters, "count_grapheme_clusters"); exportStrFn(str.countGraphemeClusters, "count_grapheme_clusters");
exportStrFn(str.startsWith, "starts_with"); exportStrFn(str.startsWith, "starts_with");
exportStrFn(str.startsWithCodePt, "starts_with_code_point"); exportStrFn(str.startsWithScalar, "starts_with_scalar");
exportStrFn(str.endsWith, "ends_with"); exportStrFn(str.endsWith, "ends_with");
exportStrFn(str.strConcatC, "concat"); exportStrFn(str.strConcatC, "concat");
exportStrFn(str.strJoinWithC, "joinWith"); exportStrFn(str.strJoinWithC, "joinWith");

View file

@ -9,7 +9,7 @@ interface Str
split, split,
repeat, repeat,
countGraphemes, countGraphemes,
startsWithCodePt, startsWithScalar,
toUtf8, toUtf8,
fromUtf8, fromUtf8,
fromUtf8Range, fromUtf8Range,
@ -165,13 +165,13 @@ countGraphemes : Str -> Nat
## ##
## **Performance Note:** This runs slightly faster than [Str.startsWith], so ## **Performance Note:** This runs slightly faster than [Str.startsWith], so
## if you want to check whether a string begins with something that's representable ## if you want to check whether a string begins with something that's representable
## in a single code point, you can use (for example) `Str.startsWithCodePt '鹏'` ## in a single code point, you can use (for example) `Str.startsWithScalar '鹏'`
## instead of `Str.startsWithCodePt "鹏"`. ('鹏' evaluates to the [U32] ## instead of `Str.startsWithScalar "鹏"`. ('鹏' evaluates to the [U32]
## value `40527`.) This will not work for graphemes which take up multiple code ## value `40527`.) This will not work for graphemes which take up multiple code
## points, however; `Str.startsWithCodePt '👩‍👩‍👦‍👦'` would be a compiler error ## points, however; `Str.startsWithScalar '👩‍👩‍👦‍👦'` would be a compiler error
## because 👩‍👩‍👦‍👦 takes up multiple code points and cannot be represented as a ## because 👩‍👩‍👦‍👦 takes up multiple code points and cannot be represented as a
## single [U32]. You'd need to use `Str.startsWithCodePt "🕊"` instead. ## single [U32]. You'd need to use `Str.startsWithScalar "🕊"` instead.
startsWithCodePt : Str, U32 -> Bool startsWithScalar : Str, U32 -> Bool
## Return a [List] of the [unicode scalar values](https://unicode.org/glossary/#unicode_scalar_value) ## Return a [List] of the [unicode scalar values](https://unicode.org/glossary/#unicode_scalar_value)
## in the given string. ## in the given string.

View file

@ -314,7 +314,7 @@ pub const STR_STR_SPLIT_IN_PLACE: &str = "roc_builtins.str.str_split_in_place";
pub const STR_TO_SCALARS: &str = "roc_builtins.str.to_scalars"; pub const STR_TO_SCALARS: &str = "roc_builtins.str.to_scalars";
pub const STR_COUNT_GRAPEHEME_CLUSTERS: &str = "roc_builtins.str.count_grapheme_clusters"; pub const STR_COUNT_GRAPEHEME_CLUSTERS: &str = "roc_builtins.str.count_grapheme_clusters";
pub const STR_STARTS_WITH: &str = "roc_builtins.str.starts_with"; pub const STR_STARTS_WITH: &str = "roc_builtins.str.starts_with";
pub const STR_STARTS_WITH_CODE_PT: &str = "roc_builtins.str.starts_with_code_point"; pub const STR_STARTS_WITH_SCALAR: &str = "roc_builtins.str.starts_with_scalar";
pub const STR_ENDS_WITH: &str = "roc_builtins.str.ends_with"; pub const STR_ENDS_WITH: &str = "roc_builtins.str.ends_with";
pub const STR_NUMBER_OF_BYTES: &str = "roc_builtins.str.number_of_bytes"; pub const STR_NUMBER_OF_BYTES: &str = "roc_builtins.str.number_of_bytes";
pub const STR_FROM_INT: IntrinsicName = int_intrinsic!("roc_builtins.str.from_int"); pub const STR_FROM_INT: IntrinsicName = int_intrinsic!("roc_builtins.str.from_int");

View file

@ -894,9 +894,9 @@ pub fn types() -> MutMap<Symbol, (SolvedType, Region)> {
Box::new(bool_type()) Box::new(bool_type())
); );
// startsWithCodePt : Str, U32 -> Bool // startsWithScalar : Str, U32 -> Bool
add_top_level_function_type!( add_top_level_function_type!(
Symbol::STR_STARTS_WITH_CODE_PT, Symbol::STR_STARTS_WITH_SCALAR,
vec![str_type(), u32_type()], vec![str_type(), u32_type()],
Box::new(bool_type()) Box::new(bool_type())
); );

View file

@ -77,7 +77,7 @@ pub fn builtin_defs_map(symbol: Symbol, var_store: &mut VarStore) -> Option<Def>
STR_SPLIT => str_split, STR_SPLIT => str_split,
STR_IS_EMPTY => str_is_empty, STR_IS_EMPTY => str_is_empty,
STR_STARTS_WITH => str_starts_with, STR_STARTS_WITH => str_starts_with,
STR_STARTS_WITH_CODE_PT => str_starts_with_code_point, STR_STARTS_WITH_SCALAR => str_starts_with_scalar,
STR_ENDS_WITH => str_ends_with, STR_ENDS_WITH => str_ends_with,
STR_COUNT_GRAPHEMES => str_count_graphemes, STR_COUNT_GRAPHEMES => str_count_graphemes,
STR_FROM_UTF8 => str_from_utf8, STR_FROM_UTF8 => str_from_utf8,
@ -1746,9 +1746,9 @@ fn str_starts_with(symbol: Symbol, var_store: &mut VarStore) -> Def {
lowlevel_2(symbol, LowLevel::StrStartsWith, var_store) lowlevel_2(symbol, LowLevel::StrStartsWith, var_store)
} }
/// Str.startsWithCodePt : Str, U32 -> Bool /// Str.startsWithScalar : Str, U32 -> Bool
fn str_starts_with_code_point(symbol: Symbol, var_store: &mut VarStore) -> Def { fn str_starts_with_scalar(symbol: Symbol, var_store: &mut VarStore) -> Def {
lowlevel_2(symbol, LowLevel::StrStartsWithCodePt, var_store) lowlevel_2(symbol, LowLevel::StrStartsWithScalar, var_store)
} }
/// Str.endsWith : Str, Str -> Bool /// Str.endsWith : Str, Str -> Bool

View file

@ -5432,14 +5432,14 @@ fn run_low_level<'a, 'ctx, 'env>(
call_bitcode_fn(env, &[string, prefix], bitcode::STR_STARTS_WITH) call_bitcode_fn(env, &[string, prefix], bitcode::STR_STARTS_WITH)
} }
StrStartsWithCodePt => { StrStartsWithScalar => {
// Str.startsWithCodePt : Str, U32 -> Bool // Str.startsWithScalar : Str, U32 -> Bool
debug_assert_eq!(args.len(), 2); debug_assert_eq!(args.len(), 2);
let string = load_symbol(scope, &args[0]); let string = load_symbol(scope, &args[0]);
let prefix = load_symbol(scope, &args[1]); let prefix = load_symbol(scope, &args[1]);
call_bitcode_fn(env, &[string, prefix], bitcode::STR_STARTS_WITH_CODE_PT) call_bitcode_fn(env, &[string, prefix], bitcode::STR_STARTS_WITH_SCALAR)
} }
StrEndsWith => { StrEndsWith => {
// Str.startsWith : Str, Str -> Bool // Str.startsWith : Str, Str -> Bool

View file

@ -231,8 +231,8 @@ impl<'a> LowLevelCall<'a> {
_ => internal_error!("invalid storage for Str"), _ => internal_error!("invalid storage for Str"),
}, },
StrStartsWith => self.load_args_and_call_zig(backend, bitcode::STR_STARTS_WITH), StrStartsWith => self.load_args_and_call_zig(backend, bitcode::STR_STARTS_WITH),
StrStartsWithCodePt => { StrStartsWithScalar => {
self.load_args_and_call_zig(backend, bitcode::STR_STARTS_WITH_CODE_PT) self.load_args_and_call_zig(backend, bitcode::STR_STARTS_WITH_SCALAR)
} }
StrEndsWith => self.load_args_and_call_zig(backend, bitcode::STR_ENDS_WITH), StrEndsWith => self.load_args_and_call_zig(backend, bitcode::STR_ENDS_WITH),
StrSplit => { StrSplit => {

View file

@ -9,7 +9,7 @@ pub enum LowLevel {
StrJoinWith, StrJoinWith,
StrIsEmpty, StrIsEmpty,
StrStartsWith, StrStartsWith,
StrStartsWithCodePt, StrStartsWithScalar,
StrEndsWith, StrEndsWith,
StrSplit, StrSplit,
StrCountGraphemes, StrCountGraphemes,
@ -198,7 +198,7 @@ impl LowLevelWrapperType {
Symbol::STR_JOIN_WITH => CanBeReplacedBy(StrJoinWith), Symbol::STR_JOIN_WITH => CanBeReplacedBy(StrJoinWith),
Symbol::STR_IS_EMPTY => CanBeReplacedBy(StrIsEmpty), Symbol::STR_IS_EMPTY => CanBeReplacedBy(StrIsEmpty),
Symbol::STR_STARTS_WITH => CanBeReplacedBy(StrStartsWith), Symbol::STR_STARTS_WITH => CanBeReplacedBy(StrStartsWith),
Symbol::STR_STARTS_WITH_CODE_PT => CanBeReplacedBy(StrStartsWithCodePt), Symbol::STR_STARTS_WITH_SCALAR => CanBeReplacedBy(StrStartsWithScalar),
Symbol::STR_ENDS_WITH => CanBeReplacedBy(StrEndsWith), Symbol::STR_ENDS_WITH => CanBeReplacedBy(StrEndsWith),
Symbol::STR_SPLIT => CanBeReplacedBy(StrSplit), Symbol::STR_SPLIT => CanBeReplacedBy(StrSplit),
Symbol::STR_COUNT_GRAPHEMES => CanBeReplacedBy(StrCountGraphemes), Symbol::STR_COUNT_GRAPHEMES => CanBeReplacedBy(StrCountGraphemes),

View file

@ -1168,7 +1168,7 @@ define_builtins! {
10 STR_UT8_PROBLEM: "Utf8Problem" // the Utf8Problem type alias 10 STR_UT8_PROBLEM: "Utf8Problem" // the Utf8Problem type alias
11 STR_UT8_BYTE_PROBLEM: "Utf8ByteProblem" // the Utf8ByteProblem type alias 11 STR_UT8_BYTE_PROBLEM: "Utf8ByteProblem" // the Utf8ByteProblem type alias
12 STR_TO_UTF8: "toUtf8" 12 STR_TO_UTF8: "toUtf8"
13 STR_STARTS_WITH_CODE_PT: "startsWithCodePt" 13 STR_STARTS_WITH_SCALAR: "startsWithScalar"
14 STR_ALIAS_ANALYSIS_STATIC: "#aliasAnalysisStatic" // string with the static lifetime 14 STR_ALIAS_ANALYSIS_STATIC: "#aliasAnalysisStatic" // string with the static lifetime
15 STR_FROM_UTF8_RANGE: "fromUtf8Range" 15 STR_FROM_UTF8_RANGE: "fromUtf8Range"
16 STR_REPEAT: "repeat" 16 STR_REPEAT: "repeat"

View file

@ -948,7 +948,7 @@ pub fn lowlevel_borrow_signature(arena: &Bump, op: LowLevel) -> &[bool] {
NumBytesToU16 => arena.alloc_slice_copy(&[borrowed, irrelevant]), NumBytesToU16 => arena.alloc_slice_copy(&[borrowed, irrelevant]),
NumBytesToU32 => arena.alloc_slice_copy(&[borrowed, irrelevant]), NumBytesToU32 => arena.alloc_slice_copy(&[borrowed, irrelevant]),
StrStartsWith | StrEndsWith => arena.alloc_slice_copy(&[owned, borrowed]), StrStartsWith | StrEndsWith => arena.alloc_slice_copy(&[owned, borrowed]),
StrStartsWithCodePt => arena.alloc_slice_copy(&[borrowed, irrelevant]), StrStartsWithScalar => arena.alloc_slice_copy(&[borrowed, irrelevant]),
StrFromUtf8 => arena.alloc_slice_copy(&[owned]), StrFromUtf8 => arena.alloc_slice_copy(&[owned]),
StrFromUtf8Range => arena.alloc_slice_copy(&[borrowed, irrelevant]), StrFromUtf8Range => arena.alloc_slice_copy(&[borrowed, irrelevant]),
StrToUtf8 => arena.alloc_slice_copy(&[owned]), StrToUtf8 => arena.alloc_slice_copy(&[owned]),

View file

@ -120,7 +120,7 @@ enum FirstOrder {
StrJoinWith, StrJoinWith,
StrIsEmpty, StrIsEmpty,
StrStartsWith, StrStartsWith,
StrStartsWithCodePt, StrStartsWithScalar,
StrEndsWith, StrEndsWith,
StrSplit, StrSplit,
StrCountGraphemes, StrCountGraphemes,

View file

@ -496,14 +496,14 @@ fn str_starts_with() {
#[test] #[test]
#[cfg(any(feature = "gen-llvm"))] #[cfg(any(feature = "gen-llvm"))]
fn str_starts_with_code_point() { fn str_starts_with_scalar() {
assert_evals_to!( assert_evals_to!(
&format!(r#"Str.startsWithCodePt "foobar" {}"#, 'f' as u32), &format!(r#"Str.startsWithScalar "foobar" {}"#, 'f' as u32),
true, true,
bool bool
); );
assert_evals_to!( assert_evals_to!(
&format!(r#"Str.startsWithCodePt "zoobar" {}"#, 'f' as u32), &format!(r#"Str.startsWithScalar "zoobar" {}"#, 'f' as u32),
false, false,
bool bool
); );

View file

@ -417,14 +417,14 @@ fn str_starts_with() {
} }
#[test] #[test]
fn str_starts_with_code_point() { fn str_starts_with_scalar() {
assert_evals_to!( assert_evals_to!(
&format!(r#"Str.startsWithCodePt "foobar" {}"#, 'f' as u32), &format!(r#"Str.startsWithScalar "foobar" {}"#, 'f' as u32),
true, true,
bool bool
); );
assert_evals_to!( assert_evals_to!(
&format!(r#"Str.startsWithCodePt "zoobar" {}"#, 'f' as u32), &format!(r#"Str.startsWithScalar "zoobar" {}"#, 'f' as u32),
false, false,
bool bool
); );