mirror of
https://github.com/JHUAPL/Glum.git
synced 2026-01-08 16:43:49 -05:00
Changes for 2.1.0:
[1] Updates to improve the ParseUtil functionality. [2] Added check for null font argument.
This commit is contained in:
@@ -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
|
* Note we do not make the Version directly visible and final so other classes will not utilized a cached version
|
||||||
* when built via Ant.
|
* when built via Ant.
|
||||||
*/
|
*/
|
||||||
private static String Version = "2.0.0";
|
private static String Version = "2.1.0";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the version of the application
|
* Returns the version of the application
|
||||||
|
|||||||
@@ -76,7 +76,8 @@ public class GuiUtil
|
|||||||
{
|
{
|
||||||
var tmpB = new JButton(aTitle);
|
var tmpB = new JButton(aTitle);
|
||||||
tmpB.addActionListener(aActionListener);
|
tmpB.addActionListener(aActionListener);
|
||||||
tmpB.setFont(aFont);
|
if (aFont != null)
|
||||||
|
tmpB.setFont(aFont);
|
||||||
|
|
||||||
return tmpB;
|
return tmpB;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,6 +13,9 @@
|
|||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
package glum.io;
|
package glum.io;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Collection of utility methods for parsing values from text input.
|
* Collection of utility methods for parsing values from text input.
|
||||||
*
|
*
|
||||||
@@ -20,6 +23,15 @@ package glum.io;
|
|||||||
*/
|
*/
|
||||||
public class ParseUtil
|
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.
|
* 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++)
|
if (aStr.startsWith("\"") == true && aStr.endsWith("\"") == true)
|
||||||
aTokenArr[c1] = aTokenArr[c1].strip();
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
26
src/glum/io/TokenParseAttr.java
Normal file
26
src/glum/io/TokenParseAttr.java
Normal 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -15,7 +15,7 @@ import traceback
|
|||||||
|
|
||||||
|
|
||||||
# Define the (baseline) version
|
# Define the (baseline) version
|
||||||
baseVersion = "2.0.0"
|
baseVersion = "2.1.0"
|
||||||
|
|
||||||
# Define relevant base names
|
# Define relevant base names
|
||||||
appBaseName = 'Glum'
|
appBaseName = 'Glum'
|
||||||
|
|||||||
Reference in New Issue
Block a user