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.countGraphemeClusters, "count_grapheme_clusters");
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.strConcatC, "concat");
exportStrFn(str.strJoinWithC, "joinWith");

View File

@ -9,7 +9,7 @@ interface Str
split,
repeat,
countGraphemes,
startsWithCodePt,
startsWithScalar,
toUtf8,
fromUtf8,
fromUtf8Range,
@ -165,13 +165,13 @@ countGraphemes : Str -> Nat
##
## **Performance Note:** This runs slightly faster than [Str.startsWith], so
## 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 '鹏'`
## instead of `Str.startsWithCodePt "鹏"`. ('鹏' evaluates to the [U32]
## in a single code point, you can use (for example) `Str.startsWithScalar '鹏'`
## instead of `Str.startsWithScalar "鹏"`. ('鹏' evaluates to the [U32]
## 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
## single [U32]. You'd need to use `Str.startsWithCodePt "🕊"` instead.
startsWithCodePt : Str, U32 -> Bool
## single [U32]. You'd need to use `Str.startsWithScalar "🕊"` instead.
startsWithScalar : Str, U32 -> Bool
## Return a [List] of the [unicode scalar values](https://unicode.org/glossary/#unicode_scalar_value)
## 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_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_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_NUMBER_OF_BYTES: &str = "roc_builtins.str.number_of_bytes";
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())
);
// startsWithCodePt : Str, U32 -> Bool
// startsWithScalar : Str, U32 -> Bool
add_top_level_function_type!(
Symbol::STR_STARTS_WITH_CODE_PT,
Symbol::STR_STARTS_WITH_SCALAR,
vec![str_type(), u32_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_IS_EMPTY => str_is_empty,
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_COUNT_GRAPHEMES => str_count_graphemes,
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)
}
/// Str.startsWithCodePt : Str, U32 -> Bool
fn str_starts_with_code_point(symbol: Symbol, var_store: &mut VarStore) -> Def {
lowlevel_2(symbol, LowLevel::StrStartsWithCodePt, var_store)
/// Str.startsWithScalar : Str, U32 -> Bool
fn str_starts_with_scalar(symbol: Symbol, var_store: &mut VarStore) -> Def {
lowlevel_2(symbol, LowLevel::StrStartsWithScalar, var_store)
}
/// 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)
}
StrStartsWithCodePt => {
// Str.startsWithCodePt : Str, U32 -> Bool
StrStartsWithScalar => {
// Str.startsWithScalar : Str, U32 -> Bool
debug_assert_eq!(args.len(), 2);
let string = load_symbol(scope, &args[0]);
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 => {
// Str.startsWith : Str, Str -> Bool

View File

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

View File

@ -9,7 +9,7 @@ pub enum LowLevel {
StrJoinWith,
StrIsEmpty,
StrStartsWith,
StrStartsWithCodePt,
StrStartsWithScalar,
StrEndsWith,
StrSplit,
StrCountGraphemes,
@ -198,7 +198,7 @@ impl LowLevelWrapperType {
Symbol::STR_JOIN_WITH => CanBeReplacedBy(StrJoinWith),
Symbol::STR_IS_EMPTY => CanBeReplacedBy(StrIsEmpty),
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_SPLIT => CanBeReplacedBy(StrSplit),
Symbol::STR_COUNT_GRAPHEMES => CanBeReplacedBy(StrCountGraphemes),

View File

@ -1168,7 +1168,7 @@ define_builtins! {
10 STR_UT8_PROBLEM: "Utf8Problem" // the Utf8Problem type alias
11 STR_UT8_BYTE_PROBLEM: "Utf8ByteProblem" // the Utf8ByteProblem type alias
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
15 STR_FROM_UTF8_RANGE: "fromUtf8Range"
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]),
NumBytesToU32 => arena.alloc_slice_copy(&[borrowed, irrelevant]),
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]),
StrFromUtf8Range => arena.alloc_slice_copy(&[borrowed, irrelevant]),
StrToUtf8 => arena.alloc_slice_copy(&[owned]),

View File

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

View File

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

View File

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