Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[bot] Fast-forward for 24.11.8 #2259

Merged
merged 1 commit into from
Feb 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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