From ea8a75596cecfe3479b08847a163912a77382d7b Mon Sep 17 00:00:00 2001 From: James Ahlborn Date: Tue, 13 Nov 2018 23:06:27 +0000 Subject: share nchars impl git-svn-id: https://svn.code.sf.net/p/jackcess/code/jackcess/trunk@1223 f203690c-595d-4dc9-a70b-905162fa7fd2 --- .../jackcess/impl/expr/DefaultFunctions.java | 10 ++-------- .../jackcess/impl/expr/DefaultTextFunctions.java | 8 ++++++-- 2 files changed, 8 insertions(+), 10 deletions(-) (limited to 'src') diff --git a/src/main/java/com/healthmarketscience/jackcess/impl/expr/DefaultFunctions.java b/src/main/java/com/healthmarketscience/jackcess/impl/expr/DefaultFunctions.java index 7a582d6..dcb2348 100644 --- a/src/main/java/com/healthmarketscience/jackcess/impl/expr/DefaultFunctions.java +++ b/src/main/java/com/healthmarketscience/jackcess/impl/expr/DefaultFunctions.java @@ -551,13 +551,13 @@ public class DefaultFunctions if(groupDigits) { fmt.append("#,"); - appendNum(fmt, '#', numGroupDigits - 1); + DefaultTextFunctions.nchars(fmt, numGroupDigits - 1, '#'); } fmt.append(incLeadDigit ? "0" : "#"); if(numDecDigits > 0) { fmt.append("."); - appendNum(fmt, '0', numDecDigits); + DefaultTextFunctions.nchars(fmt, numDecDigits, '0'); } if(isPercent) { @@ -597,10 +597,4 @@ public class DefaultFunctions throw new IllegalStateException("Duplicate function " + fname); } } - - private static void appendNum(StringBuilder sb, char c, int num) { - for(int i = 0; i < num; ++i) { - sb.append(c); - } - } } diff --git a/src/main/java/com/healthmarketscience/jackcess/impl/expr/DefaultTextFunctions.java b/src/main/java/com/healthmarketscience/jackcess/impl/expr/DefaultTextFunctions.java index 5291c3c..f8c4a88 100644 --- a/src/main/java/com/healthmarketscience/jackcess/impl/expr/DefaultTextFunctions.java +++ b/src/main/java/com/healthmarketscience/jackcess/impl/expr/DefaultTextFunctions.java @@ -428,12 +428,16 @@ public class DefaultTextFunctions private static String nchars(int num, char c) { StringBuilder sb = new StringBuilder(num); + nchars(sb, num, c); + return sb.toString(); + } + + static void nchars(StringBuilder sb, int num, char c) { for(int i = 0; i < num; ++i) { sb.append(c); } - return sb.toString(); } - + private static String trim(String str, boolean doLeft, boolean doRight) { int start = 0; int end = str.length(); -- cgit v1.2.3