@SuppressWarnings("AssignmentToForLoopParameter")
    private static boolean isQuoted(final StringBuilder sbString,
            final int pos) {
        boolean isQuoted = false;

        for (int curPos = 0; curPos < pos; curPos++) {
            if (sbString.charAt(curPos) == '\'') {
                isQuoted = !isQuoted;

                // if quote was escaped by backslash, it's like double quote
                if (pos > 0 && sbString.charAt(pos - 1) == '\\') {
                    isQuoted = !isQuoted;
                }
            } else if (sbString.charAt(curPos) == '$' && !isQuoted) {
                final int endPos = sbString.indexOf("$", curPos + 1);

                if (endPos == -1) {
                    return true;
                }

                final String tag = sbString.substring(curPos, endPos + 1);
                final int endTagPos = sbString.indexOf(tag, endPos + 1);

                // if end tag was not found or it was found after the checked
                // position, it's quoted
                if (endTagPos == -1 || endTagPos > pos) {
                    return true;
                }

                curPos = endTagPos + tag.length() - 1;
            }
        }

        return isQuoted;
    }