int (int start, String s, int maxPosition, String closingQuote) { int end; int length = s.length(); if (s.trim().endsWith(closingQuote)) length -= 3; else if (start + length == maxPosition && (s.trim().endsWith("\"") || s.trim().endsWith("'"))) length -= 1; end = start + length; if (s.endsWith("\n")) end -= 1; return end; }