Skip to content

Commit b534e28

Browse files
committed
Add String.equal, String.compare
1 parent 0a52e1c commit b534e28

File tree

3 files changed

+31
-0
lines changed

3 files changed

+31
-0
lines changed

src/Core__String.mjs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,20 @@
11
// Generated by ReScript, PLEASE EDIT WITH CARE
22

33

4+
function equal(a, b) {
5+
return a === b;
6+
}
7+
8+
function compare(a, b) {
9+
if (a === b) {
10+
return 0;
11+
} else if (a > b) {
12+
return 1;
13+
} else {
14+
return -1;
15+
}
16+
}
17+
418
function indexOfOpt(s, search) {
519
var index = s.indexOf(search);
620
if (index !== -1) {
@@ -26,6 +40,8 @@ function searchOpt(s, re) {
2640
}
2741

2842
export {
43+
equal ,
44+
compare ,
2945
indexOfOpt ,
3046
lastIndexOfOpt ,
3147
searchOpt ,

src/Core__String.res

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,17 @@
66
@val external fromCodePoint: int => string = "String.fromCodePoint"
77
@variadic @val external fromCodePointMany: array<int> => string = "String.fromCodePoint"
88

9+
let equal = (a: string, b: string) => a === b
10+
11+
let compare = (a: string, b: string) =>
12+
if a === b {
13+
0
14+
} else if a > b {
15+
1
16+
} else {
17+
-1
18+
}
19+
920
@get external length: string => int = "length"
1021
@get_index external get: (string, int) => option<string> = ""
1122
@send external charAt: (string, int) => string = "charAt"

src/Core__String.resi

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,10 @@ String.fromCodePointMany([0xd55c, 0xae00, 0x1f63a]) == `한글😺`
118118
@val
119119
external fromCodePointMany: array<int> => string = "String.fromCodePoint"
120120

121+
let equal: (string, string) => bool
122+
123+
let compare: (string, string) => int
124+
121125
/**
122126
`length(str)` returns the length of the given `string`.
123127
See [`String.length`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/length) on MDN.

0 commit comments

Comments
 (0)