Skip to content

Commit

Permalink
Merge 24.11 to develop
Browse files Browse the repository at this point in the history
  • Loading branch information
labkey-teamcity committed Jan 31, 2025
2 parents 22738fd + 2bd83d5 commit 73a17a8
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 47 deletions.
46 changes: 0 additions & 46 deletions src/org/labkey/test/TestFileUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -693,50 +693,4 @@ public static File convertTabularToXlsx(File tabularFile, String delimiter, Stri

return excelFile;
}

// TODO should be able to use the methods in TSVWriter itself but currently has problems with NoClassDefFound
// TODO Consider using TestDataUtils.TsvQuoter instead
public static boolean shouldQuote(String value, String delimiter)
{
String escapeChars = _escapedCharsString + delimiter;

int len = value.length();
if (len == 0)
return false;
char firstCh = value.charAt(0);
char lastCh = value.charAt(len-1);
if (Character.isSpaceChar(firstCh) || Character.isSpaceChar(lastCh))
return true;
return StringUtils.containsAny(value,escapeChars);
}

public static String quoteValue(String value, String delimiter)
{
if (value == null)
return "";

String escaped = value;
if (shouldQuote(value, delimiter))
{
StringBuilder sb = new StringBuilder(value.length() + 10);
sb.append(_chQuote);
int i;
int lastMatch = 0;

while (-1 != (i = value.indexOf(_chQuote, lastMatch)))
{
sb.append(value, lastMatch, i);
sb.append(_chQuote).append(_chQuote);
lastMatch = i+1;
}

if (lastMatch < value.length())
sb.append(value.substring(lastMatch));

sb.append(_chQuote);
escaped = sb.toString();
}

return escaped;
}
}
3 changes: 2 additions & 1 deletion src/org/labkey/test/util/TestDataUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -133,12 +133,13 @@ private static String toTabular(List<Map<String, Object>> rowMaps, List<String>
*/
public static class TsvQuoter
{
protected char _escapeChar = '\\';
private static final char _chQuote = '"';
private final char[] _escapedChars;

public TsvQuoter(char delimiterChar)
{
_escapedChars = new char[] {'\r', '\n', _chQuote, delimiterChar};
_escapedChars = new char[] {'\r', '\n', _escapeChar, _chQuote, delimiterChar};
}

public TsvQuoter()
Expand Down

0 comments on commit 73a17a8

Please sign in to comment.