s/CodePoint/CodePt/g

This commit is contained in:
Richard Feldman 2021-08-07 15:18:51 -04:00
parent 69b1497907
commit 267836226c
25 changed files with 69 additions and 69 deletions

View file

@ -88,7 +88,7 @@ comptime {
exportStrFn(str.countSegments, "count_segments");
exportStrFn(str.countGraphemeClusters, "count_grapheme_clusters");
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.strConcatC, "concat");
exportStrFn(str.strJoinWithC, "joinWith");

View file

@ -865,8 +865,8 @@ pub fn startsWith(string: RocStr, prefix: RocStr) callconv(.C) bool {
return true;
}
// Str.startsWithCodePoint
pub fn startsWithCodePoint(string: RocStr, prefix: u32) callconv(.C) bool {
// Str.startsWithCodePt
pub fn startsWithCodePt(string: RocStr, prefix: u32) callconv(.C) bool {
const bytes_len = string.len();
const bytes_ptr = string.asU8ptr();
@ -886,18 +886,18 @@ pub fn startsWithCodePoint(string: RocStr, prefix: u32) callconv(.C) bool {
return true;
}
test "startsWithCodePoint: ascii char" {
test "startsWithCodePt: ascii char" {
const whole = RocStr.init("foobar", 6);
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 no = RocStr.init("foobar", 6);
const prefix = '💖';
try expect(startsWithCodePoint(yes, prefix));
try expect(!startsWithCodePoint(no, prefix));
try expect(startsWithCodePt(yes, prefix));
try expect(!startsWithCodePt(no, prefix));
}
test "startsWith: foo starts with fo" {

View file

@ -194,13 +194,13 @@ startsWith : Str, Str -> Bool
##
## **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.startsWithCodePoint '鹏'`
## instead of `Str.startsWithCodePoint "鹏"`. ('鹏' evaluates to the [U32]
## in a single code point, you can use (for example) `Str.startsWithCodePt '鹏'`
## instead of `Str.startsWithCodePt "鹏"`. ('鹏' evaluates to the [U32]
## 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
## single [U32]. You'd need to use `Str.startsWithCodePoint "🕊"` instead.
startsWithCodePoint : Str, U32 -> Bool
## single [U32]. You'd need to use `Str.startsWithCodePt "🕊"` instead.
startsWithCodePt : Str, U32 -> 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),
## return a [Str] containing only that scalar.
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 ]*
## 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
## 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
## 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)
## 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.
##

View file

@ -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_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_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_NUMBER_OF_BYTES: &str = "roc_builtins.str.number_of_bytes";
pub const STR_FROM_INT: &str = "roc_builtins.str.from_int";

View file

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

View file

@ -58,7 +58,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_POINT => str_starts_with_code_point,
STR_STARTS_WITH_CODE_PT => str_starts_with_code_point,
STR_ENDS_WITH => str_ends_with,
STR_COUNT_GRAPHEMES => str_count_graphemes,
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)
}
/// Str.startsWithCodePoint : Str, U32 -> Bool
/// Str.startsWithCodePt : Str, U32 -> Bool
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

View file

@ -1600,10 +1600,10 @@ fn flatten_str_lines<'a>(
buf.push(ch);
}
None => {
env.problem(Problem::InvalidUnicodeCodePoint(loc_hex_digits.region));
env.problem(Problem::InvalidUnicodeCodePt(loc_hex_digits.region));
return (
Expr::RuntimeError(RuntimeError::InvalidUnicodeCodePoint(
Expr::RuntimeError(RuntimeError::InvalidUnicodeCodePt(
loc_hex_digits.region,
)),
output,

View file

@ -313,7 +313,7 @@ pub fn canonical_string_literal<'a>(_arena: &Bump, _raw: &'a str, _region: Regio
// problems.push(Loc {
// region,
// value: Problem::UnicodeCodePointTooLarge,
// value: Problem::UnicodeCodePtTooLarge,
// });
// } else {
// // 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),
// None => {
// problems.push(loc_escaped_unicode(
// Problem::InvalidUnicodeCodePoint,
// Problem::InvalidUnicodeCodePt,
// &state,
// start_of_unicode,
// 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() {
// Problem::NoUnicodeDigits
// } else {
// Problem::NonHexCharsInUnicodeCodePoint
// Problem::NonHexCharsInUnicodeCodePt
// };
// problems.push(loc_escaped_unicode(

View file

@ -1590,7 +1590,7 @@ mod test_can {
// // (Rust has this restriction. I assume it's a good idea.)
// assert_malformed_str(
// r#""abc\u{110000}def""#,
// vec![Located::new(0, 7, 0, 12, Problem::UnicodeCodePointTooLarge)],
// vec![Located::new(0, 7, 0, 12, Problem::UnicodeCodePtTooLarge)],
// );
// }

View file

@ -4412,8 +4412,8 @@ fn run_low_level<'a, 'ctx, 'env>(
str_starts_with(env, scope, args[0], args[1])
}
StrStartsWithCodePoint => {
// Str.startsWithCodePoint : Str, U32 -> Bool
StrStartsWithCodePt => {
// Str.startsWithCodePt : Str, U32 -> Bool
debug_assert_eq!(args.len(), 2);
str_starts_with_code_point(env, scope, args[0], args[1])

View file

@ -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>(
env: &Env<'a, 'ctx, 'env>,
scope: &Scope<'a, 'ctx>,
@ -188,7 +188,7 @@ pub fn str_starts_with_code_point<'a, 'ctx, 'env>(
call_bitcode_fn(
env,
&[str_i128.into(), prefix],
bitcode::STR_STARTS_WITH_CODE_POINT,
bitcode::STR_STARTS_WITH_CODE_PT,
)
}

View file

@ -7,7 +7,7 @@ pub enum LowLevel {
StrJoinWith,
StrIsEmpty,
StrStartsWith,
StrStartsWithCodePoint,
StrStartsWithCodePt,
StrEndsWith,
StrSplit,
StrCountGraphemes,
@ -113,7 +113,7 @@ impl LowLevel {
| StrJoinWith
| StrIsEmpty
| StrStartsWith
| StrStartsWithCodePoint
| StrStartsWithCodePt
| StrEndsWith
| StrSplit
| StrCountGraphemes

View file

@ -919,7 +919,7 @@ define_builtins! {
13 STR_UT8_PROBLEM: "Utf8Problem" // the Utf8Problem type alias
14 STR_UT8_BYTE_PROBLEM: "Utf8ByteProblem" // the Utf8ByteProblem type alias
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
}
4 LIST: "List" => {

View file

@ -1013,7 +1013,7 @@ pub fn lowlevel_borrow_signature(arena: &Bump, op: LowLevel) -> &[bool] {
| NumCeiling | NumFloor | NumToFloat | Not | NumIsFinite | NumAtan | NumAcos | NumAsin
| NumIntCast => arena.alloc_slice_copy(&[irrelevant]),
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]),
StrToBytes => arena.alloc_slice_copy(&[owned]),
StrFromInt | StrFromFloat => arena.alloc_slice_copy(&[irrelevant]),

View file

@ -436,8 +436,8 @@ pub enum Number {
pub enum EString<'a> {
Open(Row, Col),
CodePointOpen(Row, Col),
CodePointEnd(Row, Col),
CodePtOpen(Row, Col),
CodePtEnd(Row, Col),
Space(BadInputError, Row, Col),
EndlessSingle(Row, Col),

View file

@ -6,10 +6,10 @@ pub type Problems = Vec<Loc<Problem>>;
pub enum Problem {
// UNICODE CODE POINT
/// 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}.
UnicodeCodePointTooLarge,
InvalidUnicodeCodePoint,
UnicodeCodePtTooLarge,
InvalidUnicodeCodePt,
MalformedEscapedUnicode,
NoUnicodeDigits,

View file

@ -18,7 +18,7 @@ fn ascii_hex_digits<'a>() -> impl Parser<'a, &'a str, EString<'a>> {
// We didn't find any hex digits!
return Err((
NoProgress,
EString::CodePointEnd(state.line, state.column),
EString::CodePtEnd(state.line, state.column),
state,
));
} else {
@ -32,7 +32,7 @@ fn ascii_hex_digits<'a>() -> impl Parser<'a, &'a str, EString<'a>> {
Err((
NoProgress,
EString::CodePointEnd(state.line, state.column),
EString::CodePtEnd(state.line, state.column),
state,
))
}
@ -257,9 +257,9 @@ pub fn parse<'a>() -> impl Parser<'a, StrLiteral<'a>, EString<'a>> {
// give a canonicalization error if the digits form
// an invalid unicode code point.
let (_progress, loc_digits, new_state) = between!(
word1(b'(', EString::CodePointOpen),
word1(b'(', EString::CodePtOpen),
loc(ascii_hex_digits()),
word1(b')', EString::CodePointEnd)
word1(b')', EString::CodePtEnd)
)
.parse(arena, state)?;

View file

@ -77,7 +77,7 @@ pub enum Problem {
},
InvalidInterpolation(Region),
InvalidHexadecimal(Region),
InvalidUnicodeCodePoint(Region),
InvalidUnicodeCodePt(Region),
}
#[derive(Clone, Debug, PartialEq)]
@ -160,7 +160,7 @@ pub enum RuntimeError {
InvalidInterpolation(Region),
InvalidHexadecimal(Region),
InvalidUnicodeCodePoint(Region),
InvalidUnicodeCodePt(Region),
/// When the author specifies a type annotation but no implementation
NoImplementationNamed {

View file

@ -313,7 +313,7 @@ pub fn can_problem<'b>(
]),
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.region(region),
alloc.reflow("Learn more about working with unicode in roc at TODO"),
@ -931,7 +931,7 @@ fn pretty_runtime_error<'b>(
region
);
}
RuntimeError::InvalidUnicodeCodePoint(region) => {
RuntimeError::InvalidUnicodeCodePt(region) => {
todo!(
"TODO runtime error for an invalid \\u(...) code point at region {:?}",
region

View file

@ -826,7 +826,7 @@ fn to_str_report<'a>(
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 region = Region::from_row_col(row, col);

View file

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

View file

@ -1015,10 +1015,10 @@ fn flatten_str_lines<'a>(
buf.push(ch);
}
None => {
// env.problem(Problem::InvalidUnicodeCodePoint(loc_hex_digits.region));
// env.problem(Problem::InvalidUnicodeCodePt(loc_hex_digits.region));
//
// return (
// Expr::RuntimeError(RuntimeError::InvalidUnicodeCodePoint(
// Expr::RuntimeError(RuntimeError::InvalidUnicodeCodePt(
// loc_hex_digits.region,
// )),
// output,

View file

@ -40,8 +40,8 @@ Problem :
NumF32 Endi,
Utf8 Str,
Utf16 Str Endi,
CodePointUtf8,
CodePointUtf16 Endi,
CodePtUtf8,
CodePtUtf16 Endi,
GraphemeUtf8,
GraphemeUtf16 Endi,
End,

View file

@ -1,6 +1,6 @@
package roc/unicode 0.1.0
roc 0.0.0
exposes [ Unicode, Unicode.Scalar, Unicode.CodePoint ]
exposes [ Unicode, Unicode.Scalar, Unicode.CodePt ]
packages {}
license UPL-1.0

View file

@ -3,8 +3,8 @@ interface Unicode.Scalar
[
Scalar,
toStr,
toCodePoint,
fromCodePoint,
toCodePt,
fromCodePt,
parseUtf8,
parseUtf16,
chompUtf8,
@ -12,8 +12,8 @@ interface Unicode.Scalar
]
imports
[
Unicode.CodePoint.Internal as Internal
Unicode.CodePoint.{ CodePoint },
Unicode.CodePt.Internal as Internal
Unicode.CodePt.{ CodePt },
Bytes.{ Bytes }
]
@ -31,15 +31,15 @@ toStr = \@Scalar u32
# already validated this!
toStr (@Scalar (scalar * 256))
toCodePoint : Scalar -> CodePoint
toCodePoint = \@Scalar u32 -> Internal.fromU32Unchecked u32
toCodePt : Scalar -> CodePt
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 ]*
parseUtf16 : Bytes, Endi -> Result { val : Scalar, rest : Bytes } [ Expected [ Utf16CodePoint Endi ]* Bytes ]*
parseUtf8 : Bytes -> Result { val : Scalar, rest : Bytes } [ Expected [ Utf8CodePt ]* Bytes ]*
parseUtf16 : Bytes, Endi -> Result { val : Scalar, rest : Bytes } [ Expected [ Utf16CodePt Endi ]* Bytes ]*
chompUtf8 : Bytes, CodePoint -> Result Str [ Expected [ ExactCodePoint CodePoint ]* Bytes ]*
chompUtf16 : Bytes, CodePoint, Endi -> Result Str [ Expected [ ExactCodePoint CodePoint ]* Bytes ]*
chompUtf8 : Bytes, CodePt -> Result Str [ Expected [ ExactCodePt CodePt ]* Bytes ]*
chompUtf16 : Bytes, CodePt, Endi -> Result Str [ Expected [ ExactCodePt CodePt ]* Bytes ]*
isAsciiDigit : CodePoint -> Bool
isAsciiDigit : CodePt -> Bool