class Strings {

    public static String[] parseQualifiedName(String arg, int maxParts) {
        assert maxParts > 0 : maxParts;
        String[] result = new String[maxParts];
        int resIndex = 0;
        char lastQuote = 0;
        int prevEnd = 0;
        for(int i = 0; i < arg.length(); ++i) {
            char c = arg.charAt(i);
            boolean take = false;
            boolean toLower = true;
            if(lastQuote != 0) {
                if(c == lastQuote) {
                    take = true;
                    toLower = false;
                    lastQuote = 0;
                }
            } else if(c == '"' || c == '`') {
                lastQuote = c;
                prevEnd = i + 1;
            } else if(c == '.') {
                take = true;
            }
            if(take) {
                if(prevEnd < i) {
                    result[resIndex++] = consumeIdentifier(arg, prevEnd, i, toLower);
                }
                prevEnd = i + 1;
            }
        }
        if((resIndex < maxParts) && (prevEnd < arg.length())) {
            result[resIndex++] = consumeIdentifier(arg, prevEnd, arg.length(), lastQuote == 0);
        }
        int diff = maxParts - resIndex;
        if(diff > 0) {
            // Shift found and empty fill missing
            System.arraycopy(result, 0, result, maxParts - resIndex, resIndex);
            for(int i = 0; i < diff; ++i) {
                result[i] = "";
            }
        }
        return result;
    }

}