Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update StaticUtils#toLowerCase #241

Merged
merged 1 commit into from
Feb 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Locale;
import java.util.Objects;
import java.util.Set;

Expand Down Expand Up @@ -59,100 +60,7 @@ public static String toLowerCase(@Nullable final String s)
return null;
}

final int length = s.length();
final char[] charArray = s.toCharArray();
for (int i=0; i < length; i++)
{
switch (charArray[i])
{
case 'A':
charArray[i] = 'a';
break;
case 'B':
charArray[i] = 'b';
break;
case 'C':
charArray[i] = 'c';
break;
case 'D':
charArray[i] = 'd';
break;
case 'E':
charArray[i] = 'e';
break;
case 'F':
charArray[i] = 'f';
break;
case 'G':
charArray[i] = 'g';
break;
case 'H':
charArray[i] = 'h';
break;
case 'I':
charArray[i] = 'i';
break;
case 'J':
charArray[i] = 'j';
break;
case 'K':
charArray[i] = 'k';
break;
case 'L':
charArray[i] = 'l';
break;
case 'M':
charArray[i] = 'm';
break;
case 'N':
charArray[i] = 'n';
break;
case 'O':
charArray[i] = 'o';
break;
case 'P':
charArray[i] = 'p';
break;
case 'Q':
charArray[i] = 'q';
break;
case 'R':
charArray[i] = 'r';
break;
case 'S':
charArray[i] = 's';
break;
case 'T':
charArray[i] = 't';
break;
case 'U':
charArray[i] = 'u';
break;
case 'V':
charArray[i] = 'v';
break;
case 'W':
charArray[i] = 'w';
break;
case 'X':
charArray[i] = 'x';
break;
case 'Y':
charArray[i] = 'y';
break;
case 'Z':
charArray[i] = 'z';
break;
default:
if (charArray[i] > 0x7F)
{
return s.toLowerCase();
}
break;
}
}

return new String(charArray);
return s.toLowerCase(Locale.ROOT);
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

package com.unboundid.scim2.common;

import com.unboundid.scim2.common.utils.StaticUtils;
import org.testng.annotations.Test;

import static com.unboundid.scim2.common.utils.StaticUtils.splitCommaSeparatedString;
Expand Down Expand Up @@ -86,4 +87,23 @@ public void testSplitCommaSeparatedString()
assertThat(splitCommaSeparatedString(" value1 , , value3 "))
.containsExactly("value1", "", "value3");
}

/**
* Basic test for {@link StaticUtils#toLowerCase} that ensures it can accept
* {@code null} inputs.
*/
@Test
public void testToLowercase()
{
// A null input should not cause an exception.
//
// noinspection ConstantValue
assertThat(StaticUtils.toLowerCase(null)).isNull();

// These test cases are not extensive since the method is a wrapper around
// String#toLowerCase().
assertThat(StaticUtils.toLowerCase("lowerstring")).isEqualTo("lowerstring");
assertThat(StaticUtils.toLowerCase("sPoNgEbOb tExT"))

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lol

.isEqualTo("spongebob text");
}
}
Loading