Skip to content

Commit b42d8ec

Browse files
feat: implement std.equalsIgnoreCase (#1079)
Co-authored-by: Dave Cunningham <[email protected]>
1 parent 9f9cf3a commit b42d8ec

File tree

3 files changed

+13
-0
lines changed

3 files changed

+13
-0
lines changed

doc/_stdlib_gen/stdlib-content.jsonnet

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,14 @@ local html = import 'html.libsonnet';
371371
Returns true if the the given string is of zero length.
372372
|||,
373373
},
374+
{
375+
name: 'equalsIgnoreCase',
376+
params: ['str1', 'str2'],
377+
availableSince: 'upcoming',
378+
description: |||
379+
Returns true if the the given <code>str1</code> is equal to <code>str2</code> by doing case insensitive comparison, false otherwise.
380+
|||,
381+
},
374382
{
375383
name: 'asciiUpper',
376384
params: ['str'],

stdlib/std.jsonnet

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1724,6 +1724,8 @@ limitations under the License.
17241724
isEmpty(str):: std.length(str) == 0,
17251725

17261726
contains(arr, elem):: std.any([e == elem for e in arr]),
1727+
1728+
equalsIgnoreCase(str1, str2):: std.asciiLower(str1) == std.asciiLower(str2),
17271729

17281730
removeAt(arr, at):: [
17291731
arr[i],

test_suite/stdlib.jsonnet

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1562,6 +1562,9 @@ std.assertEqual(std.isEmpty('non-empty string'), false) &&
15621562
std.assertEqual(std.contains([1, 2, 3], 2), true) &&
15631563
std.assertEqual(std.contains([1, 2, 3], "foo"), false) &&
15641564

1565+
std.assertEqual(std.equalsIgnoreCase('foo', 'FOO'), true) &&
1566+
std.assertEqual(std.equalsIgnoreCase('foo', 'bar'), false) &&
1567+
15651568
std.assertEqual(std.remove([1, 2, 3], 2), [1, 3]) &&
15661569
std.assertEqual(std.removeAt([1, 2, 3], 1), [1, 3]) &&
15671570

0 commit comments

Comments
 (0)