/** * Splits an iCal line into key and value by the first * unquoted colon. * @param icalLine String */ protected static String[] icalLineKeyValue(String icalLine){ int delim = indexOfFirstUnquotedColon(icalLine); if(delim == -1){ return new String[]{"",""}; } String key = icalLine.substring(0,delim); String value = icalLine.substring(delim+1); return new String[]{key,value}; }
/** * Splits an iCal line into key and value by the first * unquoted colon. * @param icalLine String */ protected static String[] icalLineKeyValue(String icalLine){ int delim = indexOfFirstUnquotedColon(icalLine); if(delim == -1){ return new String[]{"",""}; } String key = icalLine.substring(0,delim); String value = icalLine.substring(delim+1); return new String[]{key,value}; }
/** * @param icalLine String * @return location of first non quote enclosed colon */ private static int indexOfFirstUnquotedColon(String icalLine){ int colon = icalLine.indexOf(":"); int quote = icalLine.indexOf("\""); if(quote == -1){ return colon; }else{ if(colon<quote){ return colon; }else{ //next quote, skipping past a colon if exists int nextQuote = icalLine.indexOf("\"", quote+1); if(nextQuote==-1){ //will only happen if the quotes are unbalanced return -1; }else{ return nextQuote + indexOfFirstUnquotedColon(icalLine.substring(nextQuote+1, icalLine.length())) + 1; } } } }
/** * @param icalLine String * @return location of first non quote enclosed colon */ private static int indexOfFirstUnquotedColon(String icalLine){ int colon = icalLine.indexOf(":"); int quote = icalLine.indexOf("\""); if(quote == -1){ return colon; }else{ if(colon<quote){ return colon; }else{ //next quote, skipping past a colon if exists int nextQuote = icalLine.indexOf("\"", quote+1); if(nextQuote==-1){ //will only happen if the quotes are unbalanced return -1; }else{ return nextQuote + indexOfFirstUnquotedColon(icalLine.substring(nextQuote+1, icalLine.length())) + 1; } } } }