newline() public méthode

public newline ( int pos ) : void
pos int
Résultat void
Exemple #1
0
        public int Read()
        {
            int c, comlen = 0;

            if (state == State.at_eof)
            {
                return(-1);
            }
            while (true)
            {
                // get a character
                if (back >= 0)
                { // back is used only in copy mode
                    c = back; back = -1;
                }
                else if (state == State.at_eof)
                {
                    c = -1;
                }
                else
                {
                    c = m_stream.Read();
                }
                if (c == '\r')
                {
                    continue;
                }
                while (sol && c == '#') // deal with #line directive
                {
                    while (c != ' ')
                    {
                        c = m_stream.Read();
                    }
                    lm.lines = 0;
                    while (c == ' ')
                    {
                        c = m_stream.Read();
                    }
                    while (c >= '0' && c <= '9')
                    {
                        lm.lines = lm.lines * 10 + (c - '0');
                        c        = m_stream.Read();
                    }
                    while (c == ' ')
                    {
                        c = m_stream.Read();
                    }
                    if (c == '"')
                    {
                        fname = "";
                        c     = m_stream.Read();
                        while (c != '"')
                        {
                            fname += c;
                            c      = m_stream.Read();
                        }
                    }
                    while (c != '\n')
                    {
                        c = m_stream.Read();
                    }
                    if (c == '\r')
                    {
                        c = m_stream.Read();
                    }
                }
                if (c < 0)
                {  // at EOF we must leave the loop
                    if (state == State.sol)
                    {
                        c = '/';
                    }
                    state = State.at_eof;
                    pos++;
                    return(c);
                }
                sol = false;
                // otherwise work through a state machine
                switch (state)
                {
                case State.copy:
                    if (c == '/')
                    {
                        state = State.sol;
                    }
                    else
                    {
                        if (c == '\n')
                        {
                            lm.newline(pos);
                            sol = true;
                        }
                        pos++;
                        return(c);
                    }
                    continue;

                case State.sol:     // solidus '/'
                    if (c == '*')
                    {
                        state = State.c_com;
                    }
                    else if (c == '/')
                    {
                        comlen = 2;
                        state  = State.cpp_com;
                    }
                    else
                    {
                        back  = c;
                        state = State.copy;
                        pos++;
                        return('/');
                    }
                    continue;

                case State.c_com:
                    comlen++;
                    if (c == '\n')
                    {
                        lm.newline(pos);
                        comlen = 0;
                        sol    = true;
                    }
                    if (c == '*')
                    {
                        state = State.c_star;
                    }
                    continue;

                case State.c_star:
                    comlen++;
                    if (c == '/')
                    {
                        lm.comment(pos, comlen);
                        state = State.copy;
                    }
                    else if (c == '*')        // 4.7j
                    {
                        state = State.c_star; // 4.7j
                    }
                    else
                    {
                        state = State.c_com;
                    }
                    continue;

                case State.cpp_com:
                    if (c == '\n')
                    {
                        state = State.copy;
                        sol   = true;
                        pos++;
                        return(c);
                    }
                    else
                    {
                        comlen++;
                    }
                    continue;
                }
            }
            /* notreached */
        }
Exemple #2
0
        public int Read()
        {
            int c, comlen = 0;

            if (state == State.at_eof)
            {
                return(-1);
            }
            while (true)
            {
                // get a character
                if (back >= 0)
                {                 // back is used only in copy mode
                    c = back; back = -1;
                }
                else if (state == State.at_eof)
                {
                    c = -1;
                }
                else
                {
                    c = m_stream.Read();
                }
                if (c == '\r')
                {
                    continue;
                }
                if (c < 0)
                {                  // at EOF we must leave the loop
                    if (state == State.sol)
                    {
                        c = '/';
                    }
                    state = State.at_eof;
                    pos++;
                    return(c);
                }
                // otherwise work through a state machine
                switch (state)
                {
                case State.copy:
                    if (c == '/')
                    {
                        state = State.sol;
                    }
                    else
                    {
                        if (c == '\n')
                        {
                            lm.newline(pos);
                        }
                        pos++;
                        return(c);
                    } continue;

                case State.sol:                         // solidus '/'
                    if (c == '*')
                    {
                        state = State.c_com;
                    }
                    else if (c == '/')
                    {
                        comlen = 2;
                        state  = State.cpp_com;
                    }
                    else
                    {
                        back  = c;
                        state = State.copy;
                        pos++;
                        return('/');
                    }
                    continue;

                case State.c_com:
                    comlen++;
                    if (c == '\n')
                    {
                        lm.newline(pos);
                        comlen = 0;
                    }
                    if (c == '*')
                    {
                        state = State.c_star;
                    }
                    continue;

                case State.c_star:
                    comlen++;
                    if (c == '/')
                    {
                        lm.comment(pos, comlen);
                        state = State.copy;
                    }
                    else
                    {
                        state = State.c_com;
                    }
                    continue;

                case State.cpp_com:
                    if (c == '\n')
                    {
                        state = State.copy;
                        pos++;
                        return(c);
                    }
                    else
                    {
                        comlen++;
                    }
                    continue;
                }
            }
            /* notreached */
        }