mirror of
https://github.com/roc-lang/roc.git
synced 2025-10-03 08:34:33 +00:00
s/CodePoint/CodePt/g
This commit is contained in:
parent
69b1497907
commit
267836226c
25 changed files with 69 additions and 69 deletions
|
@ -88,7 +88,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.startsWithCodePoint, "starts_with_code_point");
|
exportStrFn(str.startsWithCodePt, "starts_with_code_point");
|
||||||
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");
|
||||||
|
|
|
@ -865,8 +865,8 @@ pub fn startsWith(string: RocStr, prefix: RocStr) callconv(.C) bool {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Str.startsWithCodePoint
|
// Str.startsWithCodePt
|
||||||
pub fn startsWithCodePoint(string: RocStr, prefix: u32) callconv(.C) bool {
|
pub fn startsWithCodePt(string: RocStr, prefix: u32) callconv(.C) bool {
|
||||||
const bytes_len = string.len();
|
const bytes_len = string.len();
|
||||||
const bytes_ptr = string.asU8ptr();
|
const bytes_ptr = string.asU8ptr();
|
||||||
|
|
||||||
|
@ -886,18 +886,18 @@ pub fn startsWithCodePoint(string: RocStr, prefix: u32) callconv(.C) bool {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
test "startsWithCodePoint: ascii char" {
|
test "startsWithCodePt: ascii char" {
|
||||||
const whole = RocStr.init("foobar", 6);
|
const whole = RocStr.init("foobar", 6);
|
||||||
const prefix = 'f';
|
const prefix = 'f';
|
||||||
try expect(startsWithCodePoint(whole, prefix));
|
try expect(startsWithCodePt(whole, prefix));
|
||||||
}
|
}
|
||||||
|
|
||||||
test "startsWithCodePoint: emoji" {
|
test "startsWithCodePt: emoji" {
|
||||||
const yes = RocStr.init("💖foobar", 10);
|
const yes = RocStr.init("💖foobar", 10);
|
||||||
const no = RocStr.init("foobar", 6);
|
const no = RocStr.init("foobar", 6);
|
||||||
const prefix = '💖';
|
const prefix = '💖';
|
||||||
try expect(startsWithCodePoint(yes, prefix));
|
try expect(startsWithCodePt(yes, prefix));
|
||||||
try expect(!startsWithCodePoint(no, prefix));
|
try expect(!startsWithCodePt(no, prefix));
|
||||||
}
|
}
|
||||||
|
|
||||||
test "startsWith: foo starts with fo" {
|
test "startsWith: foo starts with fo" {
|
||||||
|
|
|
@ -194,13 +194,13 @@ startsWith : Str, Str -> Bool
|
||||||
##
|
##
|
||||||
## **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.startsWithCodePoint '鹏'`
|
## in a single code point, you can use (for example) `Str.startsWithCodePt '鹏'`
|
||||||
## instead of `Str.startsWithCodePoint "鹏"`. ('鹏' evaluates to the [U32]
|
## instead of `Str.startsWithCodePt "鹏"`. ('鹏' 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.startsWithCodePoint '👩👩👦👦'` would be a compiler error
|
## points, however; `Str.startsWithCodePt '👩👩👦👦'` 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.startsWithCodePoint "🕊"` instead.
|
## single [U32]. You'd need to use `Str.startsWithCodePt "🕊"` instead.
|
||||||
startsWithCodePoint : Str, U32 -> Bool
|
startsWithCodePt : Str, U32 -> Bool
|
||||||
|
|
||||||
endsWith : Str, Str -> Bool
|
endsWith : Str, Str -> Bool
|
||||||
|
|
||||||
|
@ -360,7 +360,7 @@ trim : Str -> Str
|
||||||
## If the given [U32] is a valid [Unicode Scalar Value](http://www.unicode.org/glossary/#unicode_scalar_value),
|
## If the given [U32] is a valid [Unicode Scalar Value](http://www.unicode.org/glossary/#unicode_scalar_value),
|
||||||
## return a [Str] containing only that scalar.
|
## return a [Str] containing only that scalar.
|
||||||
fromScalar : U32 -> Result Str [ BadScalar ]*
|
fromScalar : U32 -> Result Str [ BadScalar ]*
|
||||||
fromCodePoints : List U32 -> Result Str [ BadCodePoint U32 ]*
|
fromCodePts : List U32 -> Result Str [ BadCodePt U32 ]*
|
||||||
fromUtf8 : List U8 -> Result Str [ BadUtf8 ]*
|
fromUtf8 : List U8 -> Result Str [ BadUtf8 ]*
|
||||||
|
|
||||||
## Create a [Str] from bytes encoded as [UTF-16LE](https://en.wikipedia.org/wiki/UTF-16#Byte-order_encoding_schemes).
|
## Create a [Str] from bytes encoded as [UTF-16LE](https://en.wikipedia.org/wiki/UTF-16#Byte-order_encoding_schemes).
|
||||||
|
@ -423,7 +423,7 @@ parseGrapheme : Str -> Result { val : Str, rest : Str } [ Expected [ Grapheme ]*
|
||||||
##
|
##
|
||||||
## If the string does not begin with a valid code point, for example because it was
|
## If the string does not begin with a valid code point, for example because it was
|
||||||
## empty, return `Err`.
|
## empty, return `Err`.
|
||||||
parseCodePoint : Str -> Result { val : U32, rest : Str } [ Expected [ CodePoint ]* Str ]*
|
parseCodePt : Str -> Result { val : U32, rest : Str } [ Expected [ CodePt ]* Str ]*
|
||||||
|
|
||||||
## If the first string begins with the second, return whatever comes
|
## If the first string begins with the second, return whatever comes
|
||||||
## after the second.
|
## after the second.
|
||||||
|
@ -431,7 +431,7 @@ chomp : Str, Str -> Result Str [ Expected [ ExactStr Str ]* Str ]*
|
||||||
|
|
||||||
## If the string begins with a [Unicode code point](http://www.unicode.org/glossary/#code_point)
|
## If the string begins with a [Unicode code point](http://www.unicode.org/glossary/#code_point)
|
||||||
## equal to the given [U32], return whatever comes after that code point.
|
## equal to the given [U32], return whatever comes after that code point.
|
||||||
chompCodePoint : Str, U32 -> Result Str [ Expected [ ExactCodePoint U32 ]* Str ]*
|
chompCodePt : Str, U32 -> Result Str [ Expected [ ExactCodePt U32 ]* Str ]*
|
||||||
|
|
||||||
## If the string represents a valid #U8 number, return that number.
|
## If the string represents a valid #U8 number, return that number.
|
||||||
##
|
##
|
||||||
|
|
|
@ -16,7 +16,7 @@ pub const STR_JOIN_WITH: &str = "roc_builtins.str.joinWith";
|
||||||
pub const STR_STR_SPLIT_IN_PLACE: &str = "roc_builtins.str.str_split_in_place";
|
pub const STR_STR_SPLIT_IN_PLACE: &str = "roc_builtins.str.str_split_in_place";
|
||||||
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_POINT: &str = "roc_builtins.str.starts_with_code_point";
|
pub const STR_STARTS_WITH_CODE_PT: &str = "roc_builtins.str.starts_with_code_point";
|
||||||
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: &str = "roc_builtins.str.from_int";
|
pub const STR_FROM_INT: &str = "roc_builtins.str.from_int";
|
||||||
|
|
|
@ -563,9 +563,9 @@ pub fn types() -> MutMap<Symbol, (SolvedType, Region)> {
|
||||||
Box::new(bool_type())
|
Box::new(bool_type())
|
||||||
);
|
);
|
||||||
|
|
||||||
// startsWithCodePoint : Str, U32 -> Bool
|
// startsWithCodePt : Str, U32 -> Bool
|
||||||
add_top_level_function_type!(
|
add_top_level_function_type!(
|
||||||
Symbol::STR_STARTS_WITH_CODE_POINT,
|
Symbol::STR_STARTS_WITH_CODE_PT,
|
||||||
vec![str_type(), u32_type()],
|
vec![str_type(), u32_type()],
|
||||||
Box::new(bool_type())
|
Box::new(bool_type())
|
||||||
);
|
);
|
||||||
|
|
|
@ -58,7 +58,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_POINT => str_starts_with_code_point,
|
STR_STARTS_WITH_CODE_PT => str_starts_with_code_point,
|
||||||
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_INT => str_from_int,
|
STR_FROM_INT => str_from_int,
|
||||||
|
@ -1287,9 +1287,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.startsWithCodePoint : Str, U32 -> Bool
|
/// Str.startsWithCodePt : Str, U32 -> Bool
|
||||||
fn str_starts_with_code_point(symbol: Symbol, var_store: &mut VarStore) -> Def {
|
fn str_starts_with_code_point(symbol: Symbol, var_store: &mut VarStore) -> Def {
|
||||||
lowlevel_2(symbol, LowLevel::StrStartsWithCodePoint, var_store)
|
lowlevel_2(symbol, LowLevel::StrStartsWithCodePt, var_store)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Str.endsWith : Str, Str -> Bool
|
/// Str.endsWith : Str, Str -> Bool
|
||||||
|
|
|
@ -1600,10 +1600,10 @@ fn flatten_str_lines<'a>(
|
||||||
buf.push(ch);
|
buf.push(ch);
|
||||||
}
|
}
|
||||||
None => {
|
None => {
|
||||||
env.problem(Problem::InvalidUnicodeCodePoint(loc_hex_digits.region));
|
env.problem(Problem::InvalidUnicodeCodePt(loc_hex_digits.region));
|
||||||
|
|
||||||
return (
|
return (
|
||||||
Expr::RuntimeError(RuntimeError::InvalidUnicodeCodePoint(
|
Expr::RuntimeError(RuntimeError::InvalidUnicodeCodePt(
|
||||||
loc_hex_digits.region,
|
loc_hex_digits.region,
|
||||||
)),
|
)),
|
||||||
output,
|
output,
|
||||||
|
|
|
@ -313,7 +313,7 @@ pub fn canonical_string_literal<'a>(_arena: &Bump, _raw: &'a str, _region: Regio
|
||||||
|
|
||||||
// problems.push(Loc {
|
// problems.push(Loc {
|
||||||
// region,
|
// region,
|
||||||
// value: Problem::UnicodeCodePointTooLarge,
|
// value: Problem::UnicodeCodePtTooLarge,
|
||||||
// });
|
// });
|
||||||
// } else {
|
// } else {
|
||||||
// // If it all checked out, add it to
|
// // If it all checked out, add it to
|
||||||
|
@ -322,7 +322,7 @@ pub fn canonical_string_literal<'a>(_arena: &Bump, _raw: &'a str, _region: Regio
|
||||||
// Some(ch) => buf.push(ch),
|
// Some(ch) => buf.push(ch),
|
||||||
// None => {
|
// None => {
|
||||||
// problems.push(loc_escaped_unicode(
|
// problems.push(loc_escaped_unicode(
|
||||||
// Problem::InvalidUnicodeCodePoint,
|
// Problem::InvalidUnicodeCodePt,
|
||||||
// &state,
|
// &state,
|
||||||
// start_of_unicode,
|
// start_of_unicode,
|
||||||
// hex_str.len(),
|
// hex_str.len(),
|
||||||
|
@ -335,7 +335,7 @@ pub fn canonical_string_literal<'a>(_arena: &Bump, _raw: &'a str, _region: Regio
|
||||||
// let problem = if hex_str.is_empty() {
|
// let problem = if hex_str.is_empty() {
|
||||||
// Problem::NoUnicodeDigits
|
// Problem::NoUnicodeDigits
|
||||||
// } else {
|
// } else {
|
||||||
// Problem::NonHexCharsInUnicodeCodePoint
|
// Problem::NonHexCharsInUnicodeCodePt
|
||||||
// };
|
// };
|
||||||
|
|
||||||
// problems.push(loc_escaped_unicode(
|
// problems.push(loc_escaped_unicode(
|
||||||
|
|
|
@ -1590,7 +1590,7 @@ mod test_can {
|
||||||
// // (Rust has this restriction. I assume it's a good idea.)
|
// // (Rust has this restriction. I assume it's a good idea.)
|
||||||
// assert_malformed_str(
|
// assert_malformed_str(
|
||||||
// r#""abc\u{110000}def""#,
|
// r#""abc\u{110000}def""#,
|
||||||
// vec![Located::new(0, 7, 0, 12, Problem::UnicodeCodePointTooLarge)],
|
// vec![Located::new(0, 7, 0, 12, Problem::UnicodeCodePtTooLarge)],
|
||||||
// );
|
// );
|
||||||
// }
|
// }
|
||||||
|
|
||||||
|
|
|
@ -4412,8 +4412,8 @@ fn run_low_level<'a, 'ctx, 'env>(
|
||||||
|
|
||||||
str_starts_with(env, scope, args[0], args[1])
|
str_starts_with(env, scope, args[0], args[1])
|
||||||
}
|
}
|
||||||
StrStartsWithCodePoint => {
|
StrStartsWithCodePt => {
|
||||||
// Str.startsWithCodePoint : Str, U32 -> Bool
|
// Str.startsWithCodePt : Str, U32 -> Bool
|
||||||
debug_assert_eq!(args.len(), 2);
|
debug_assert_eq!(args.len(), 2);
|
||||||
|
|
||||||
str_starts_with_code_point(env, scope, args[0], args[1])
|
str_starts_with_code_point(env, scope, args[0], args[1])
|
||||||
|
|
|
@ -175,7 +175,7 @@ pub fn str_starts_with<'a, 'ctx, 'env>(
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Str.startsWithCodePoint : Str, U32 -> Bool
|
/// Str.startsWithCodePt : Str, U32 -> Bool
|
||||||
pub fn str_starts_with_code_point<'a, 'ctx, 'env>(
|
pub fn str_starts_with_code_point<'a, 'ctx, 'env>(
|
||||||
env: &Env<'a, 'ctx, 'env>,
|
env: &Env<'a, 'ctx, 'env>,
|
||||||
scope: &Scope<'a, 'ctx>,
|
scope: &Scope<'a, 'ctx>,
|
||||||
|
@ -188,7 +188,7 @@ pub fn str_starts_with_code_point<'a, 'ctx, 'env>(
|
||||||
call_bitcode_fn(
|
call_bitcode_fn(
|
||||||
env,
|
env,
|
||||||
&[str_i128.into(), prefix],
|
&[str_i128.into(), prefix],
|
||||||
bitcode::STR_STARTS_WITH_CODE_POINT,
|
bitcode::STR_STARTS_WITH_CODE_PT,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,7 @@ pub enum LowLevel {
|
||||||
StrJoinWith,
|
StrJoinWith,
|
||||||
StrIsEmpty,
|
StrIsEmpty,
|
||||||
StrStartsWith,
|
StrStartsWith,
|
||||||
StrStartsWithCodePoint,
|
StrStartsWithCodePt,
|
||||||
StrEndsWith,
|
StrEndsWith,
|
||||||
StrSplit,
|
StrSplit,
|
||||||
StrCountGraphemes,
|
StrCountGraphemes,
|
||||||
|
@ -113,7 +113,7 @@ impl LowLevel {
|
||||||
| StrJoinWith
|
| StrJoinWith
|
||||||
| StrIsEmpty
|
| StrIsEmpty
|
||||||
| StrStartsWith
|
| StrStartsWith
|
||||||
| StrStartsWithCodePoint
|
| StrStartsWithCodePt
|
||||||
| StrEndsWith
|
| StrEndsWith
|
||||||
| StrSplit
|
| StrSplit
|
||||||
| StrCountGraphemes
|
| StrCountGraphemes
|
||||||
|
|
|
@ -919,7 +919,7 @@ define_builtins! {
|
||||||
13 STR_UT8_PROBLEM: "Utf8Problem" // the Utf8Problem type alias
|
13 STR_UT8_PROBLEM: "Utf8Problem" // the Utf8Problem type alias
|
||||||
14 STR_UT8_BYTE_PROBLEM: "Utf8ByteProblem" // the Utf8ByteProblem type alias
|
14 STR_UT8_BYTE_PROBLEM: "Utf8ByteProblem" // the Utf8ByteProblem type alias
|
||||||
15 STR_TO_BYTES: "toBytes"
|
15 STR_TO_BYTES: "toBytes"
|
||||||
16 STR_STARTS_WITH_CODE_POINT: "startsWithCodePoint"
|
16 STR_STARTS_WITH_CODE_PT: "startsWithCodePt"
|
||||||
17 STR_ALIAS_ANALYSIS_STATIC: "#aliasAnalysisStatic" // string with the static lifetime
|
17 STR_ALIAS_ANALYSIS_STATIC: "#aliasAnalysisStatic" // string with the static lifetime
|
||||||
}
|
}
|
||||||
4 LIST: "List" => {
|
4 LIST: "List" => {
|
||||||
|
|
|
@ -1013,7 +1013,7 @@ pub fn lowlevel_borrow_signature(arena: &Bump, op: LowLevel) -> &[bool] {
|
||||||
| NumCeiling | NumFloor | NumToFloat | Not | NumIsFinite | NumAtan | NumAcos | NumAsin
|
| NumCeiling | NumFloor | NumToFloat | Not | NumIsFinite | NumAtan | NumAcos | NumAsin
|
||||||
| NumIntCast => arena.alloc_slice_copy(&[irrelevant]),
|
| NumIntCast => arena.alloc_slice_copy(&[irrelevant]),
|
||||||
StrStartsWith | StrEndsWith => arena.alloc_slice_copy(&[owned, borrowed]),
|
StrStartsWith | StrEndsWith => arena.alloc_slice_copy(&[owned, borrowed]),
|
||||||
StrStartsWithCodePoint => arena.alloc_slice_copy(&[borrowed, irrelevant]),
|
StrStartsWithCodePt => arena.alloc_slice_copy(&[borrowed, irrelevant]),
|
||||||
StrFromUtf8 => arena.alloc_slice_copy(&[owned]),
|
StrFromUtf8 => arena.alloc_slice_copy(&[owned]),
|
||||||
StrToBytes => arena.alloc_slice_copy(&[owned]),
|
StrToBytes => arena.alloc_slice_copy(&[owned]),
|
||||||
StrFromInt | StrFromFloat => arena.alloc_slice_copy(&[irrelevant]),
|
StrFromInt | StrFromFloat => arena.alloc_slice_copy(&[irrelevant]),
|
||||||
|
|
|
@ -436,8 +436,8 @@ pub enum Number {
|
||||||
pub enum EString<'a> {
|
pub enum EString<'a> {
|
||||||
Open(Row, Col),
|
Open(Row, Col),
|
||||||
|
|
||||||
CodePointOpen(Row, Col),
|
CodePtOpen(Row, Col),
|
||||||
CodePointEnd(Row, Col),
|
CodePtEnd(Row, Col),
|
||||||
|
|
||||||
Space(BadInputError, Row, Col),
|
Space(BadInputError, Row, Col),
|
||||||
EndlessSingle(Row, Col),
|
EndlessSingle(Row, Col),
|
||||||
|
|
|
@ -6,10 +6,10 @@ pub type Problems = Vec<Loc<Problem>>;
|
||||||
pub enum Problem {
|
pub enum Problem {
|
||||||
// UNICODE CODE POINT
|
// UNICODE CODE POINT
|
||||||
/// TODO Invalid hex code - Unicode code points must be specified using hexadecimal characters (the numbers 0-9 and letters A-F)
|
/// TODO Invalid hex code - Unicode code points must be specified using hexadecimal characters (the numbers 0-9 and letters A-F)
|
||||||
NonHexCharsInUnicodeCodePoint,
|
NonHexCharsInUnicodeCodePt,
|
||||||
/// TODO Invalid Unicode code point. It must be no more than \\u{10FFFF}.
|
/// TODO Invalid Unicode code point. It must be no more than \\u{10FFFF}.
|
||||||
UnicodeCodePointTooLarge,
|
UnicodeCodePtTooLarge,
|
||||||
InvalidUnicodeCodePoint,
|
InvalidUnicodeCodePt,
|
||||||
MalformedEscapedUnicode,
|
MalformedEscapedUnicode,
|
||||||
NoUnicodeDigits,
|
NoUnicodeDigits,
|
||||||
|
|
||||||
|
|
|
@ -18,7 +18,7 @@ fn ascii_hex_digits<'a>() -> impl Parser<'a, &'a str, EString<'a>> {
|
||||||
// We didn't find any hex digits!
|
// We didn't find any hex digits!
|
||||||
return Err((
|
return Err((
|
||||||
NoProgress,
|
NoProgress,
|
||||||
EString::CodePointEnd(state.line, state.column),
|
EString::CodePtEnd(state.line, state.column),
|
||||||
state,
|
state,
|
||||||
));
|
));
|
||||||
} else {
|
} else {
|
||||||
|
@ -32,7 +32,7 @@ fn ascii_hex_digits<'a>() -> impl Parser<'a, &'a str, EString<'a>> {
|
||||||
|
|
||||||
Err((
|
Err((
|
||||||
NoProgress,
|
NoProgress,
|
||||||
EString::CodePointEnd(state.line, state.column),
|
EString::CodePtEnd(state.line, state.column),
|
||||||
state,
|
state,
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
@ -257,9 +257,9 @@ pub fn parse<'a>() -> impl Parser<'a, StrLiteral<'a>, EString<'a>> {
|
||||||
// give a canonicalization error if the digits form
|
// give a canonicalization error if the digits form
|
||||||
// an invalid unicode code point.
|
// an invalid unicode code point.
|
||||||
let (_progress, loc_digits, new_state) = between!(
|
let (_progress, loc_digits, new_state) = between!(
|
||||||
word1(b'(', EString::CodePointOpen),
|
word1(b'(', EString::CodePtOpen),
|
||||||
loc(ascii_hex_digits()),
|
loc(ascii_hex_digits()),
|
||||||
word1(b')', EString::CodePointEnd)
|
word1(b')', EString::CodePtEnd)
|
||||||
)
|
)
|
||||||
.parse(arena, state)?;
|
.parse(arena, state)?;
|
||||||
|
|
||||||
|
|
|
@ -77,7 +77,7 @@ pub enum Problem {
|
||||||
},
|
},
|
||||||
InvalidInterpolation(Region),
|
InvalidInterpolation(Region),
|
||||||
InvalidHexadecimal(Region),
|
InvalidHexadecimal(Region),
|
||||||
InvalidUnicodeCodePoint(Region),
|
InvalidUnicodeCodePt(Region),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug, PartialEq)]
|
#[derive(Clone, Debug, PartialEq)]
|
||||||
|
@ -160,7 +160,7 @@ pub enum RuntimeError {
|
||||||
|
|
||||||
InvalidInterpolation(Region),
|
InvalidInterpolation(Region),
|
||||||
InvalidHexadecimal(Region),
|
InvalidHexadecimal(Region),
|
||||||
InvalidUnicodeCodePoint(Region),
|
InvalidUnicodeCodePt(Region),
|
||||||
|
|
||||||
/// When the author specifies a type annotation but no implementation
|
/// When the author specifies a type annotation but no implementation
|
||||||
NoImplementationNamed {
|
NoImplementationNamed {
|
||||||
|
|
|
@ -313,7 +313,7 @@ pub fn can_problem<'b>(
|
||||||
]),
|
]),
|
||||||
alloc.reflow(r"Learn more about working with unicode in roc at TODO"),
|
alloc.reflow(r"Learn more about working with unicode in roc at TODO"),
|
||||||
]),
|
]),
|
||||||
Problem::InvalidUnicodeCodePoint(region) => alloc.stack(vec![
|
Problem::InvalidUnicodeCodePt(region) => alloc.stack(vec![
|
||||||
alloc.reflow("This unicode code point is invalid:"),
|
alloc.reflow("This unicode code point is invalid:"),
|
||||||
alloc.region(region),
|
alloc.region(region),
|
||||||
alloc.reflow("Learn more about working with unicode in roc at TODO"),
|
alloc.reflow("Learn more about working with unicode in roc at TODO"),
|
||||||
|
@ -931,7 +931,7 @@ fn pretty_runtime_error<'b>(
|
||||||
region
|
region
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
RuntimeError::InvalidUnicodeCodePoint(region) => {
|
RuntimeError::InvalidUnicodeCodePt(region) => {
|
||||||
todo!(
|
todo!(
|
||||||
"TODO runtime error for an invalid \\u(...) code point at region {:?}",
|
"TODO runtime error for an invalid \\u(...) code point at region {:?}",
|
||||||
region
|
region
|
||||||
|
|
|
@ -826,7 +826,7 @@ fn to_str_report<'a>(
|
||||||
title: "WEIRD ESCAPE".to_string(),
|
title: "WEIRD ESCAPE".to_string(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
EString::CodePointOpen(row, col) | EString::CodePointEnd(row, col) => {
|
EString::CodePtOpen(row, col) | EString::CodePtEnd(row, col) => {
|
||||||
let surroundings = Region::from_rows_cols(start_row, start_col, row, col);
|
let surroundings = Region::from_rows_cols(start_row, start_col, row, col);
|
||||||
let region = Region::from_row_col(row, col);
|
let region = Region::from_row_col(row, col);
|
||||||
|
|
||||||
|
|
|
@ -423,12 +423,12 @@ fn str_starts_with() {
|
||||||
#[test]
|
#[test]
|
||||||
fn str_starts_with_code_point() {
|
fn str_starts_with_code_point() {
|
||||||
assert_evals_to!(
|
assert_evals_to!(
|
||||||
&format!(r#"Str.startsWithCodePoint "foobar" {}"#, 'f' as u32),
|
&format!(r#"Str.startsWithCodePt "foobar" {}"#, 'f' as u32),
|
||||||
true,
|
true,
|
||||||
bool
|
bool
|
||||||
);
|
);
|
||||||
assert_evals_to!(
|
assert_evals_to!(
|
||||||
&format!(r#"Str.startsWithCodePoint "zoobar" {}"#, 'f' as u32),
|
&format!(r#"Str.startsWithCodePt "zoobar" {}"#, 'f' as u32),
|
||||||
false,
|
false,
|
||||||
bool
|
bool
|
||||||
);
|
);
|
||||||
|
|
|
@ -1015,10 +1015,10 @@ fn flatten_str_lines<'a>(
|
||||||
buf.push(ch);
|
buf.push(ch);
|
||||||
}
|
}
|
||||||
None => {
|
None => {
|
||||||
// env.problem(Problem::InvalidUnicodeCodePoint(loc_hex_digits.region));
|
// env.problem(Problem::InvalidUnicodeCodePt(loc_hex_digits.region));
|
||||||
//
|
//
|
||||||
// return (
|
// return (
|
||||||
// Expr::RuntimeError(RuntimeError::InvalidUnicodeCodePoint(
|
// Expr::RuntimeError(RuntimeError::InvalidUnicodeCodePt(
|
||||||
// loc_hex_digits.region,
|
// loc_hex_digits.region,
|
||||||
// )),
|
// )),
|
||||||
// output,
|
// output,
|
||||||
|
|
|
@ -40,8 +40,8 @@ Problem :
|
||||||
NumF32 Endi,
|
NumF32 Endi,
|
||||||
Utf8 Str,
|
Utf8 Str,
|
||||||
Utf16 Str Endi,
|
Utf16 Str Endi,
|
||||||
CodePointUtf8,
|
CodePtUtf8,
|
||||||
CodePointUtf16 Endi,
|
CodePtUtf16 Endi,
|
||||||
GraphemeUtf8,
|
GraphemeUtf8,
|
||||||
GraphemeUtf16 Endi,
|
GraphemeUtf16 Endi,
|
||||||
End,
|
End,
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
package roc/unicode 0.1.0
|
package roc/unicode 0.1.0
|
||||||
roc 0.0.0
|
roc 0.0.0
|
||||||
exposes [ Unicode, Unicode.Scalar, Unicode.CodePoint ]
|
exposes [ Unicode, Unicode.Scalar, Unicode.CodePt ]
|
||||||
packages {}
|
packages {}
|
||||||
license UPL-1.0
|
license UPL-1.0
|
||||||
|
|
||||||
|
|
|
@ -3,8 +3,8 @@ interface Unicode.Scalar
|
||||||
[
|
[
|
||||||
Scalar,
|
Scalar,
|
||||||
toStr,
|
toStr,
|
||||||
toCodePoint,
|
toCodePt,
|
||||||
fromCodePoint,
|
fromCodePt,
|
||||||
parseUtf8,
|
parseUtf8,
|
||||||
parseUtf16,
|
parseUtf16,
|
||||||
chompUtf8,
|
chompUtf8,
|
||||||
|
@ -12,8 +12,8 @@ interface Unicode.Scalar
|
||||||
]
|
]
|
||||||
imports
|
imports
|
||||||
[
|
[
|
||||||
Unicode.CodePoint.Internal as Internal
|
Unicode.CodePt.Internal as Internal
|
||||||
Unicode.CodePoint.{ CodePoint },
|
Unicode.CodePt.{ CodePt },
|
||||||
Bytes.{ Bytes }
|
Bytes.{ Bytes }
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -31,15 +31,15 @@ toStr = \@Scalar u32
|
||||||
# already validated this!
|
# already validated this!
|
||||||
toStr (@Scalar (scalar * 256))
|
toStr (@Scalar (scalar * 256))
|
||||||
|
|
||||||
toCodePoint : Scalar -> CodePoint
|
toCodePt : Scalar -> CodePt
|
||||||
toCodePoint = \@Scalar u32 -> Internal.fromU32Unchecked u32
|
toCodePt = \@Scalar u32 -> Internal.fromU32Unchecked u32
|
||||||
|
|
||||||
fromCodePoint : CodePoint -> Result Scalar [ PointWasSurrogate ]*
|
fromCodePt : CodePt -> Result Scalar [ PointWasSurrogate ]*
|
||||||
|
|
||||||
parseUtf8 : Bytes -> Result { val : Scalar, rest : Bytes } [ Expected [ Utf8CodePoint ]* Bytes ]*
|
parseUtf8 : Bytes -> Result { val : Scalar, rest : Bytes } [ Expected [ Utf8CodePt ]* Bytes ]*
|
||||||
parseUtf16 : Bytes, Endi -> Result { val : Scalar, rest : Bytes } [ Expected [ Utf16CodePoint Endi ]* Bytes ]*
|
parseUtf16 : Bytes, Endi -> Result { val : Scalar, rest : Bytes } [ Expected [ Utf16CodePt Endi ]* Bytes ]*
|
||||||
|
|
||||||
chompUtf8 : Bytes, CodePoint -> Result Str [ Expected [ ExactCodePoint CodePoint ]* Bytes ]*
|
chompUtf8 : Bytes, CodePt -> Result Str [ Expected [ ExactCodePt CodePt ]* Bytes ]*
|
||||||
chompUtf16 : Bytes, CodePoint, Endi -> Result Str [ Expected [ ExactCodePoint CodePoint ]* Bytes ]*
|
chompUtf16 : Bytes, CodePt, Endi -> Result Str [ Expected [ ExactCodePt CodePt ]* Bytes ]*
|
||||||
|
|
||||||
isAsciiDigit : CodePoint -> Bool
|
isAsciiDigit : CodePt -> Bool
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue