class FeatureFileParser {

    public static String stripComments(final String line) {
        String trimmed = null;
        if (line != null) {

            final int idx = line.trim().indexOf("#");
            if (idx >= 0) {
                // is the # inside matched quotes

                boolean doTrim = false;

                if (idx == 0) {
                    // first char
                    doTrim = true;
                }

                final String[] splitByQuotes = line.split("\"[^\"]*\"|'[^']*'");
                // this will find parts of the string not in quotes
                for (final String split : splitByQuotes) {
                    if (split.contains("#") ) {
                        // hash exists not in a matching pair of quotes
                        doTrim = true;
                        break;
                    }
                }

                if (doTrim) {
                    trimmed = line.trim().substring(0, idx).trim();
                } else {
                    trimmed = line.trim();
                }
            } else {
                trimmed = line.trim();
            }
        }
        return trimmed;
    }

}