summaryrefslogtreecommitdiffstats
path: root/vespajlib/src
diff options
context:
space:
mode:
authorArne Juul <arnej@verizonmedia.com>2021-06-29 09:02:05 +0000
committerArne Juul <arnej@verizonmedia.com>2021-06-29 09:52:33 +0000
commit73aa0d1882f0b2ec62e55e42dafc8a4765a31b1b (patch)
treee9f1974e7889f8ad489a8efc7dfbb9991cde34ea /vespajlib/src
parente8713a281bd8619f89b276bfca1a339b48a64e6e (diff)
add convenience function wrapping "String.format(Locale.US, ...)"
Diffstat (limited to 'vespajlib/src')
-rw-r--r--vespajlib/src/main/java/com/yahoo/text/Text.java4
-rw-r--r--vespajlib/src/test/java/com/yahoo/text/TextTestCase.java4
2 files changed, 8 insertions, 0 deletions
diff --git a/vespajlib/src/main/java/com/yahoo/text/Text.java b/vespajlib/src/main/java/com/yahoo/text/Text.java
index 85b28639d89..4b1ee57b47d 100644
--- a/vespajlib/src/main/java/com/yahoo/text/Text.java
+++ b/vespajlib/src/main/java/com/yahoo/text/Text.java
@@ -1,6 +1,7 @@
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.text;
+import java.util.Locale;
import java.util.OptionalInt;
/**
@@ -186,4 +187,7 @@ public final class Text {
return s.substring(0, length - 4) + " ...";
}
+ public static String fmt(String format, Object... args) {
+ return String.format(Locale.US, format, args);
+ }
}
diff --git a/vespajlib/src/test/java/com/yahoo/text/TextTestCase.java b/vespajlib/src/test/java/com/yahoo/text/TextTestCase.java
index 8bb8b2aaad5..83ac6342e70 100644
--- a/vespajlib/src/test/java/com/yahoo/text/TextTestCase.java
+++ b/vespajlib/src/test/java/com/yahoo/text/TextTestCase.java
@@ -72,4 +72,8 @@ public class TextTestCase {
assertEquals("a ...", Text.truncate("ab cde", 5));
}
+ @Test
+ public void testFormat() {
+ assertEquals("foo 3.14", Text.fmt("%s %.2f", "foo", 3.1415926536));
+ }
}