Skip to content

Commit

Permalink
Changes the truncated signal to signs only
Browse files Browse the repository at this point in the history
This eliminates the need to translate the truncated signal into various languages.

Fixes: SIRI-960
  • Loading branch information
mko-sci committed May 23, 2024
1 parent 19d2f93 commit 7c2ff38
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
4 changes: 2 additions & 2 deletions src/main/java/sirius/kernel/commons/Strings.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public class Strings {
/**
* Contains the marker/signal which should be used to depict that the string has been truncated.
*/
private static final String TRUNCATED_SIGNAL = ELLIPSIS + "[truncated]" + ELLIPSIS;
private static final String TRUNCATED_SIGNAL = ELLIPSIS + "[" + ELLIPSIS + "]" + ELLIPSIS;

/**
* Contains all characters which can safely be used for codes without too much confusion (e.g. 0 vs O are
Expand Down Expand Up @@ -407,7 +407,7 @@ public static String limit(@Nullable Object input, int length, boolean showEllip
* Truncates the given input in the middle by preserving characters from the start and end.
* <p>
* Note:
* Adds a truncated signal in the form of "…[truncated]…" in the middle of the string. This signal consist of 13 chars.
* Adds a truncated signal in the form of "…[]…" in the middle of the string. This signal consist of 5 chars.
* The chars of the signal are considered when determining if a truncation is necessary. Therefore, a truncation only
* takes place if the input string is longer than <tt>charsToPreserveFromStart</tt> + <tt>charsToPreserveFromEnd</tt> + length of the truncated signal.
*
Expand Down
10 changes: 5 additions & 5 deletions src/test/kotlin/sirius/kernel/commons/StringsTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -338,11 +338,11 @@ class StringsTest {
assertEquals("1234-6789", Strings.truncateMiddle("1234-6789", 4, 4))
assertEquals("1234-6789", Strings.truncateMiddle("1234-6789", 0, 4))
assertEquals("1234-6789", Strings.truncateMiddle("1234-6789", 4, 0))
assertEquals("1234-6789", Strings.truncateMiddle("1234-6789", 1, 1))
assertEquals("1234…[truncated]…6789", Strings.truncateMiddle("123456789-123456789-123456789", 4, 4))
assertEquals("…[truncated]…6789", Strings.truncateMiddle("123456789-123456789-123456789", 0, 4))
assertEquals("1234…[truncated]…", Strings.truncateMiddle("123456789-123456789-123456789", 4, 0))
assertEquals("1…[truncated]…9", Strings.truncateMiddle("123456789-123456789-123456789", 1, 1))
assertEquals("123-456", Strings.truncateMiddle("123-456", 1, 1))
assertEquals("1234…[]…6789", Strings.truncateMiddle("123456789-123456789-123456789", 4, 4))
assertEquals("…[]…6789", Strings.truncateMiddle("123456789-123456789-123456789", 0, 4))
assertEquals("1234…[]…", Strings.truncateMiddle("123456789-123456789-123456789", 4, 0))
assertEquals("1…[]…9", Strings.truncateMiddle("123456789-123456789-123456789", 1, 1))
assertEquals("12345678901234", Strings.truncateMiddle("12345678901234", 6, 6))
}
}

0 comments on commit 7c2ff38

Please sign in to comment.