-
Notifications
You must be signed in to change notification settings - Fork 293
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve application module performance and security bounds (#6647)
- Loading branch information
1 parent
b550bc8
commit 167e8f7
Showing
5 changed files
with
253 additions
and
115 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
dd-java-agent/agent-iast/src/main/java/com/datadog/iast/util/StringUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package com.datadog.iast.util; | ||
|
||
import javax.annotation.Nonnull; | ||
|
||
public abstract class StringUtils { | ||
|
||
private StringUtils() {} | ||
|
||
/** | ||
* Checks if the string ends with the selected suffix ignoring case. Note that this method does | ||
* not take locale into account. | ||
*/ | ||
public static boolean endsWithIgnoreCase( | ||
@Nonnull final String value, @Nonnull final String suffix) { | ||
if (value.length() < suffix.length()) { | ||
return false; | ||
} | ||
if (suffix.isEmpty()) { | ||
return true; | ||
} | ||
final int offset = value.length() - suffix.length(); | ||
return value.regionMatches(true, offset, suffix, 0, suffix.length()); | ||
} | ||
|
||
/** | ||
* Performs a substring of the selected string taking care of leading and trailing whitespaces. | ||
*/ | ||
@Nonnull | ||
public static String substringTrim(@Nonnull final String value, int start, int end) { | ||
if (start >= end) { | ||
return ""; | ||
} | ||
while (start < end && Character.isWhitespace(value.charAt(start))) { | ||
start++; | ||
} | ||
while (end > start && Character.isWhitespace(value.charAt(end - 1))) { | ||
end--; | ||
} | ||
return start >= end ? "" : value.substring(start, end); | ||
} | ||
} |
Oops, something went wrong.