File tree Expand file tree Collapse file tree 3 files changed +46
-0
lines changed
Expand file tree Collapse file tree 3 files changed +46
-0
lines changed Original file line number Diff line number Diff line change @@ -63,6 +63,12 @@ assert String.byteLength("a") == 1
6363assert String.byteLength(emoji) == 4
6464assert String.byteLength(emojis) == 98
6565
66+ // String.isEmpty
67+ assert String.isEmpty(empty) == true
68+ assert String.isEmpty(short) == false
69+ assert String.isEmpty(emoji) == false
70+ assert String.isEmpty(emojis) == false
71+
6672// indexOf tests
6773assert String.indexOf(empty, empty) == Some(0)
6874assert String.indexOf(empty, short) == Some(0)
Original file line number Diff line number Diff line change @@ -98,6 +98,21 @@ provide let byteLength = (string: String) => {
9898 Conv.wasmI32ToNumber(WasmI32.load(string, 4n))
9999}
100100
101+ /**
102+ * Determines if the string contains no characters.
103+ *
104+ * @param string: The string to inspect
105+ * @returns `true` if the string is empty and `false` otherwise
106+ *
107+ * @since v0.6.0
108+ */
109+ @unsafe
110+ provide let isEmpty = (string: String) => {
111+ from WasmI32 use { (==) }
112+ let strPtr = WasmI32.fromGrain(string)
113+ WasmI32.load(strPtr, 4n) == 0n
114+ }
115+
101116/**
102117 * Finds the first position of a substring in the input string.
103118 *
Original file line number Diff line number Diff line change @@ -137,6 +137,31 @@ Examples:
137137String.byteLength("🌾") == 4
138138```
139139
140+ ### String.** isEmpty**
141+
142+ <details disabled >
143+ <summary tabindex =" -1 " >Added in <code >next</code ></summary >
144+ No other changes yet.
145+ </details >
146+
147+ ``` grain
148+ isEmpty : (string: String) => Bool
149+ ```
150+
151+ Determines if the string contains no characters.
152+
153+ Parameters:
154+
155+ | param| type| description|
156+ | -----| ----| -----------|
157+ | ` string ` | ` String ` | The string to inspect|
158+
159+ Returns:
160+
161+ | type| description|
162+ | ----| -----------|
163+ | ` Bool ` | ` true ` if the string is empty and ` false ` otherwise|
164+
140165### String.** indexOf**
141166
142167<details disabled >
You can’t perform that action at this time.
0 commit comments