private String stripFrame()

in tapestry-framework/src/org/apache/tapestry/util/exception/ExceptionAnalyzer.java [307:387]


    private String stripFrame(String frame)
    {
        char array[] = frame.toCharArray();

        int i = 0;
        int state = SKIP_LEADING_WHITESPACE;
        boolean more = true;

        while (more)
        {
            // Ran out of characters to skip?  Return the empty string.

            if (i == array.length)
                return "";

            char ch = array[i];

            switch (state)
            {
                // Ignore whitespace at the start of the line.

                case SKIP_LEADING_WHITESPACE :

                    if (Character.isWhitespace(ch))
                    {
                        i++;
                        continue;
                    }

                    if (ch == 'a')
                    {
                        state = SKIP_T;
                        i++;
                        continue;
                    }

                    // Found non-whitespace, not 'a'
                    more = false;
                    break;

                    // Skip over the 't' after an 'a'

                case SKIP_T :

                    if (ch == 't')
                    {
                        state = SKIP_OTHER_WHITESPACE;
                        i++;
                        continue;
                    }

                    // Back out the skipped-over 'a'

                    i--;
                    more = false;
                    break;

                    // Skip whitespace between 'at' and the name of the class

                case SKIP_OTHER_WHITESPACE :

                    if (Character.isWhitespace(ch))
                    {
                        i++;
                        continue;
                    }

                    // Not whitespace
                    more = false;
                    break;
            }

        }

        // Found nothing to strip out.

        if (i == 0)
            return frame;

        return frame.substring(i);
    }