diff --git a/flow/src/org/labkey/flow/ScriptParser.java b/flow/src/org/labkey/flow/ScriptParser.java index 74f1507de..908bb131b 100644 --- a/flow/src/org/labkey/flow/ScriptParser.java +++ b/flow/src/org/labkey/flow/ScriptParser.java @@ -21,6 +21,7 @@ import org.apache.xmlbeans.XmlOptions; import org.fhcrc.cpas.flow.script.xml.ScriptDef; import org.fhcrc.cpas.flow.script.xml.ScriptDocument; +import org.labkey.api.util.StringUtilsLabKey; import org.xml.sax.SAXParseException; import java.io.StringReader; @@ -94,7 +95,7 @@ public void parse(String script) message = StringUtils.replace(message, "@" + ScriptDocument.type.getContentModel().getName().getNamespaceURI(), ""); String location = xmlError.getCursorLocation().xmlText(); if (location.length() > 100) - location = location.substring(0, 100); + location = StringUtilsLabKey.leftSurrogatePairFriendly(location, 100); addError(new Error("Schema Validation Error: " + message + "\nLocation of invalid XML: " + location)); } } diff --git a/protein/api-src/org/labkey/api/protein/ProteinManager.java b/protein/api-src/org/labkey/api/protein/ProteinManager.java index 38ffa0480..71710d2e0 100644 --- a/protein/api-src/org/labkey/api/protein/ProteinManager.java +++ b/protein/api-src/org/labkey/api/protein/ProteinManager.java @@ -20,6 +20,7 @@ import org.labkey.api.util.HashHelpers; import org.labkey.api.util.HtmlString; import org.labkey.api.util.LinkBuilder; +import org.labkey.api.util.StringUtilsLabKey; import org.labkey.api.view.NotFoundException; import java.io.ByteArrayOutputStream; @@ -100,7 +101,7 @@ private static SimpleProtein ensureProteinInDatabase(String sequence, Organism o map.put("Mass", PeptideHelpers.computeMass(sequenceBytes, 0, sequenceBytes.length, PeptideHelpers.AMINO_ACID_AVERAGE_MASSES)); map.put("OrgId", organism.getOrgId()); map.put("Hash", hashSequence(sequence)); - map.put("Description", description == null ? null : (description.length() > 200 ? description.substring(0, 196) + "..." : description)); + map.put("Description", description == null ? null : (description.length() > 200 ? StringUtilsLabKey.leftSurrogatePairFriendly(description, 196) + "..." : description)); map.put("BestName", name); map.put("Length", sequence.length()); map.put("InsertDate", new Date()); diff --git a/protein/api-src/org/labkey/api/protein/ProteinPlus.java b/protein/api-src/org/labkey/api/protein/ProteinPlus.java index 673b63de4..8718d17cc 100644 --- a/protein/api-src/org/labkey/api/protein/ProteinPlus.java +++ b/protein/api-src/org/labkey/api/protein/ProteinPlus.java @@ -18,6 +18,7 @@ import org.labkey.api.protein.fasta.FastaProtein; import org.labkey.api.util.HashHelpers; +import org.labkey.api.util.StringUtilsLabKey; public class ProteinPlus { @@ -111,7 +112,7 @@ public String getBestName() { result = getProtein().getHeader(); } - if (result.length() > 500) result = result.substring(0, 499); + if (result.length() > 500) result = StringUtilsLabKey.leftSurrogatePairFriendly(result, 499); return result; } } diff --git a/protein/api-src/org/labkey/api/protein/fasta/FastaDbLoader.java b/protein/api-src/org/labkey/api/protein/fasta/FastaDbLoader.java index 721809eaa..befb46042 100644 --- a/protein/api-src/org/labkey/api/protein/fasta/FastaDbLoader.java +++ b/protein/api-src/org/labkey/api/protein/fasta/FastaDbLoader.java @@ -37,6 +37,7 @@ import org.labkey.api.protein.organism.OrganismGuessStrategy; import org.labkey.api.util.HashHelpers; import org.labkey.api.util.NetworkDrive; +import org.labkey.api.util.StringUtilsLabKey; import org.labkey.api.view.ViewBackgroundInfo; import java.io.File; @@ -259,7 +260,7 @@ protected void preProcessSequences(List mouthful, Connection c, Log } else { - if (desc.length() >= 200) desc = desc.substring(0, 195) + "..."; + if (desc.length() >= 200) desc = StringUtilsLabKey.leftSurrogatePairFriendly(desc, 195) + "..."; fdbu._addSeqStmt.setString(3, desc); } fdbu._addSeqStmt.setDouble(4, curSeq.getProtein().getMass()); diff --git a/protein/api-src/org/labkey/api/protein/fasta/IdPattern.java b/protein/api-src/org/labkey/api/protein/fasta/IdPattern.java index a8dffeb6f..257449ab3 100644 --- a/protein/api-src/org/labkey/api/protein/fasta/IdPattern.java +++ b/protein/api-src/org/labkey/api/protein/fasta/IdPattern.java @@ -27,6 +27,7 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; import java.util.regex.PatternSyntaxException; +import org.labkey.api.util.StringUtilsLabKey; /** * this class implements a regular expression-based recognition of identifiers parsed from the fasta files. @@ -178,7 +179,7 @@ public static Map> createIdMap(String key, String value) { v = v.trim(); if (v.length() > 50) - v = v.substring(0, 50); + v = StringUtilsLabKey.leftSurrogatePairFriendly(v, 50); if (!v.isEmpty()) vals.add(v); } diff --git a/protein/api-src/org/labkey/api/protein/uniprot/uniprot.java b/protein/api-src/org/labkey/api/protein/uniprot/uniprot.java index 8c8c7c8a5..fa16a5cea 100644 --- a/protein/api-src/org/labkey/api/protein/uniprot/uniprot.java +++ b/protein/api-src/org/labkey/api/protein/uniprot/uniprot.java @@ -605,7 +605,7 @@ public int insertSequences(ParseContext context, Connection conn) throws SQLExce else { String tmp = curSeq.getDescription(); - if (tmp.length() >= 200) tmp = tmp.substring(0, 190) + "..."; + if (tmp.length() >= 200) tmp = StringUtilsLabKey.leftSurrogatePairFriendly(tmp, 190) + "..."; _addSeq.setString(3, tmp); } if (curSeq.getSourceChangeDate() == null) @@ -657,7 +657,7 @@ public int insertSequences(ParseContext context, Connection conn) throws SQLExce else { String tmp = curSeq.getBestName(); - if (tmp.length() >= 50) tmp = tmp.substring(0, 45) + "..."; + if (tmp.length() >= 50) tmp = StringUtilsLabKey.leftSurrogatePairFriendly(tmp, 45) + "..."; _addSeq.setString(11, tmp); } if (curSeq.getBestGeneName() == null) @@ -667,7 +667,7 @@ public int insertSequences(ParseContext context, Connection conn) throws SQLExce else { String tmp = curSeq.getBestGeneName(); - if (tmp.length() >= 50) tmp = tmp.substring(0, 45) + "..."; + if (tmp.length() >= 50) tmp = StringUtilsLabKey.leftSurrogatePairFriendly(tmp, 45) + "..."; _addSeq.setString(12, tmp); } // Timestamp at index 13 is set once for the whole prepared statement @@ -709,7 +709,7 @@ public int insertIdentifiers(ParseContext context, Connection conn) throws SQLEx { transactionCount++; String curIdentVal = curIdent.getIdentifier(); - if (curIdentVal.length() > 50) curIdentVal = curIdentVal.substring(0, 45) + "..."; + if (curIdentVal.length() > 50) curIdentVal = StringUtilsLabKey.leftSurrogatePairFriendly(curIdentVal, 45) + "..."; _addIdent.setString(1, curIdentVal); _addIdent.setString(2, curIdent.getIdentType()); UniprotSequence curSeq = curIdent.getSequence();