
louise
Clone avec HTTPS, un jeton personnel en mot de passe, ou avec SSH, une clé ajoutée dans vos paramètres.
Dernier runRéussi#1197 · main · 10 min 35 s
1Étoiles
0Forks
0Issues
| 1 | /// Strings (`<>` concatenates; `show` renders values). |
| 2 | |
| 3 | /// The number of Unicode scalar values. |
| 4 | @extern c "tl_string_length" |
| 5 | pub fn length :: s: String -> Int |
| 6 | |
| 7 | /// `parts` with `separator` between them. Linear in the result's length: |
| 8 | /// it is allocated once, so prefer joining a list of parts to repeated `<>`. |
| 9 | @extern c "tl_string_join" |
| 10 | pub fn join :: parts: List<String> separator: String -> String |
| 11 | |
| 12 | /// All of `parts`, in order (`join(parts, "")`). |
| 13 | pub fn concat :: parts: List<String> -> String |
| 14 | { |
| 15 | join parts "" |
| 16 | } |
| 17 | |
| 18 | /// `s`, `times` times over (`""` when `times` is 0 or less). Linear in |
| 19 | /// the result's length: the copies are doubled, so it takes about |
| 20 | /// log2(times) concatenations and as many stack frames. |
| 21 | pub fn repeat :: s: String times: Int -> String |
| 22 | { |
| 23 | if times <= 0 |
| 24 | { |
| 25 | "" |
| 26 | } |
| 27 | else |
| 28 | { |
| 29 | let half = repeat s (times / 2) |
| 30 | let doubled = half <> half |
| 31 | if times % 2 == 0 |
| 32 | { |
| 33 | doubled |
| 34 | } |
| 35 | else |
| 36 | { |
| 37 | doubled <> s |
| 38 | } |
| 39 | } |
| 40 | } |
| 41 | |
| 42 | /// Whether `s` begins with `prefix`. |
| 43 | @extern c "tl_string_starts_with" |
| 44 | pub fn starts_with :: s: String prefix: String -> Bool |
| 45 | |
| 46 | /// Whether `s` ends with `suffix`. |
| 47 | @extern c "tl_string_ends_with" |
| 48 | pub fn ends_with :: s: String suffix: String -> Bool |
| 49 | |
| 50 | /// Whether `needle` occurs in `s`. |
| 51 | @extern c "tl_string_contains" |
| 52 | pub fn contains :: s: String needle: String -> Bool |
| 53 | |
| 54 | /// The byte index (UTF-8) of the first occurrence of `needle` in `s`, or |
| 55 | /// `None`; the empty needle is found at 0. A match always starts on a |
| 56 | /// character boundary. |
| 57 | @extern c "tl_string_find" |
| 58 | pub fn find :: s: String needle: String -> Option<Int> |
| 59 | |
| 60 | /// The length of `s` in bytes (UTF-8). |
| 61 | @extern c "tl_string_byte_length" |
| 62 | pub fn byte_length :: s: String -> Int |
| 63 | |
| 64 | /// `s` with ASCII letters in lowercase. |
| 65 | @extern c "tl_string_to_lower" |
| 66 | pub fn to_lower :: s: String -> String |
| 67 | |
| 68 | /// Whether `a` and `b` differ only in the case of ASCII letters |
| 69 | /// (`to_lower(a) == to_lower(b)`, without building either). |
| 70 | @extern c "tl_string_eq_ignore_ascii_case" |
| 71 | pub fn eq_ignore_ascii_case :: a: String b: String -> Bool |
| 72 | |
| 73 | /// `s` without leading and trailing whitespace. |
| 74 | @extern c "tl_string_trim" |
| 75 | pub fn trim :: s: String -> String |
| 76 | |
| 77 | /// The parts of `s` between occurrences of `separator`. |
| 78 | pub fn split :: s: String separator: String -> List<String> |
| 79 | { |
| 80 | split_raw s separator |
| 81 | } |
| 82 | |
| 83 | @extern c "tl_string_split" |
| 84 | fn split_raw :: s: String separator: String -> List<String> |
| 85 | |
| 86 | /// The characters of `s` (Unicode scalar values) as single-character |
| 87 | /// strings. |
| 88 | @extern c "tl_string_chars" |
| 89 | pub fn chars :: s: String -> List<String> |
| 90 | |
| 91 | /// The characters from `start` up to `end` (excluded). Both are clamped |
| 92 | /// to `0..length(s)`; the result is empty when `end <= start`. |
| 93 | @extern c "tl_string_slice" |
| 94 | pub fn slice :: s: String start: Int end: Int -> String |
| 95 | |
| 96 | /// The Int written in `s` (decimal, optional sign), or an `Error` |
| 97 | /// naming the text that is not one. |
| 98 | pub fn to_int :: s: String -> Result<Int, String> |
| 99 | { |
| 100 | let n = parse_int s |
| 101 | if n.0 |
| 102 | { |
| 103 | Ok(n.1) |
| 104 | } |
| 105 | else |
| 106 | { |
| 107 | Error("not an integer: " <> debug s) |
| 108 | } |
| 109 | } |
| 110 | |
| 111 | @extern c "tl_string_parse_int" |
| 112 | fn parse_int :: s: String -> (Bool, Int) |