class IOSStringsResource extends ResourceFilter {

    @Override
    public LanguageBundle parse(InputStream inStream, FilterOptions options)
            throws IOException, ResourceFilterException {

        BufferedReader reader = new BufferedReader(new InputStreamReader(inStream, CHAR_SET));
        LanguageBundleBuilder bb = new LanguageBundleBuilder(true);
        String line;
        List<String> notes = new ArrayList<>();
        Boolean commentIsGlobal = true;
        while ((line = reader.readLine()) != null) {
            if (line.trim().startsWith(COMMENT_BEGIN)) {// begins with /*
                // skip comments until line ends with */
                // the short circuit expression evaluation handles both
                // single and multi lined comments
                String comment = line.substring(line.indexOf(COMMENT_BEGIN)+2);
                Boolean commentEndProcessed = false;
                while (!commentEndProcessed && line != null) {
                    if (comment.trim().endsWith(COMMENT_END)) {
                        comment = comment.substring(0, comment.lastIndexOf(COMMENT_END));
                        commentEndProcessed = true;
                    }
                    notes.add(comment);
                    if (!commentEndProcessed) {
                        line = reader.readLine();
                        comment = line;
                    }
                }
            } else if (commentIsGlobal && line.isEmpty()) {
                commentIsGlobal = false;
                if (!notes.isEmpty()) {
                    bb.addNotes(notes);
                    notes.clear();
                }
            } else if (line.matches("^\\s*\".*")) { // begins with quote char
                // new entry
                StringBuilder entry = new StringBuilder(128);

                // keep appending lines until entry termination via semi-colon
                do {
                    entry.append(line.trim()).append(' ');
                } while (!line.matches(".*[^\\\\];\\s*$") && (line = reader.readLine()) != null);

                // split across " = "
                String[] parts = entry.toString().split("\"\\s*=\\s*\"");
                String key = parts[0].substring(parts[0].indexOf('"') + 1).trim();
                String value = parts[1].substring(0, parts[1].lastIndexOf('"')).trim();

                if (notes.isEmpty()) {
                    bb.addResourceString(key, value);
                } else {
                    bb.addResourceString(ResourceString.with(key, value).notes(notes));
                    notes.clear();
                }
            }
        }
        return bb.build();
    }

}