Changes for 2.1.0:

[1] Updates to improve the ParseUtil functionality.

[2] Added check for null font argument.
This commit is contained in:
Norberto Lopez
2025-07-30 18:06:33 -04:00
parent 1727820320
commit b01a6095f8
5 changed files with 95 additions and 7 deletions

View File

@@ -26,7 +26,7 @@ public class AppInfo
* Note we do not make the Version directly visible and final so other classes will not utilized a cached version
* when built via Ant.
*/
private static String Version = "2.0.0";
private static String Version = "2.1.0";
/**
* Returns the version of the application

View File

@@ -76,7 +76,8 @@ public class GuiUtil
{
var tmpB = new JButton(aTitle);
tmpB.addActionListener(aActionListener);
tmpB.setFont(aFont);
if (aFont != null)
tmpB.setFont(aFont);
return tmpB;
}

View File

@@ -13,6 +13,9 @@
// limitations under the License.
package glum.io;
import java.util.ArrayList;
import java.util.List;
/**
* Collection of utility methods for parsing values from text input.
*
@@ -20,6 +23,15 @@ package glum.io;
*/
public class ParseUtil
{
/**
* Utility method to strip the white space from an array of tokens.
*/
public static void cleanTokens(String[] aTokenArr)
{
for (int c1 = 0; c1 < aTokenArr.length; c1++)
aTokenArr[c1] = aTokenArr[c1].strip();
}
/**
* Reads a boolean from a string with out throwing a exception.
*/
@@ -137,12 +149,61 @@ public class ParseUtil
}
/**
* Utility method to strip the white space from an array of tokens.
* Utility method that strips out the 1st and last double quotes from a string.
* <p>
* If there are no double quotes at the 1st and last position then the original string is returned.
*/
public static void cleanTokens(String[] aTokenArr)
public static String stripQuotes(String aStr)
{
for (int c1 = 0; c1 < aTokenArr.length; c1++)
aTokenArr[c1] = aTokenArr[c1].strip();
if (aStr.startsWith("\"") == true && aStr.endsWith("\"") == true)
return aStr.substring(1, aStr.length() - 1);
return aStr;
}
/**
* Method to parse the specified input string and break it up based on commas. Note quoted string with the tokenizing
* char (aSplitChar) will be preserved.
* <p>
* The basis of this method is from:
* https://stackoverflow.com/questions/1757065/java-splitting-a-comma-separated-string-but-ignoring-commas-in-quotes
*
* @param aInputStr
* The input string to tokenize.
* @param aSplitChar
* The character to split the input string by.
* @param aParseTokenAttr
* Provides the behavior specific to tokenization.
* @return
*/
public static List<String> tokenizeByChar(String aInputStr, char aSplitChar, TokenParseAttr aTokenParseAttr)
{
var begIdx = 0;
var inQuotes = false;
var resultL = new ArrayList<String>();
for (int currIdx = 0; currIdx < aInputStr.length(); currIdx++)
{
var evalChar = aInputStr.charAt(currIdx);
if (evalChar == '"')
inQuotes = !inQuotes;
else if (evalChar == aSplitChar && inQuotes == false)
{
var tokenStr = aTokenParseAttr.apply(aInputStr.substring(begIdx, currIdx));
resultL.add(tokenStr);
begIdx = currIdx + 1;
}
}
// Ensure the last char is not a comma. We do not want a trailing comma in the last string
var endIdx = aInputStr.length();
if (endIdx > begIdx && aInputStr.charAt(endIdx - 1) == aSplitChar)
endIdx--;
// Add the last string
var tokenStr = aTokenParseAttr.apply(aInputStr.substring(begIdx));
if (aTokenParseAttr.keepEmptyTailToken() == true || tokenStr.length() > 0)
resultL.add(tokenStr);
return resultL;
}
}

View File

@@ -0,0 +1,26 @@
package glum.io;
/**
* Record which defines configuration attributes to control parsing behavior.
*
* @author lopeznr1
*/
public record TokenParseAttr(boolean stripTokenWhiteSpace, boolean keepEmptyTailToken)
{
/** The default {@link TokenParseAttr}. */
public static final TokenParseAttr Default = new TokenParseAttr(false, true);
/**
* Given the specified input string returns the string with the relevant transformations as specified by this
* {@link TokenParseAttr}.
*/
public String apply(String aInputStr)
{
var retStr = aInputStr;
if (stripTokenWhiteSpace == true)
retStr = retStr.strip();
return retStr;
}
}

View File

@@ -15,7 +15,7 @@ import traceback
# Define the (baseline) version
baseVersion = "2.0.0"
baseVersion = "2.1.0"
# Define relevant base names
appBaseName = 'Glum'