~efargaspro/+junk/codeblocks-16.01-release

« back to all changes in this revision

Viewing changes to src/plugins/contrib/FortranProject/textcutter.cpp

  • Committer: damienlmoore at gmail
  • Date: 2016-02-02 02:43:22 UTC
  • Revision ID: damienlmoore@gmail.com-20160202024322-yql5qmtbwdyamdwd
Code::BlocksĀ 16.01

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
#include "textcutter.h"
 
3
 
 
4
TextCutter::TextCutter(const wxString& allText, FortranSourceForm fsForm)
 
5
{
 
6
    m_Text = allText;
 
7
    m_TextLen = m_Text.length();
 
8
    m_CurSourceForm = fsForm;
 
9
    m_CurIdx = 0;
 
10
    m_CurColumn = 1;
 
11
}
 
12
 
 
13
TextCutter::~TextCutter()
 
14
{
 
15
};
 
16
 
 
17
void TextCutter::GetChunk(wxString& chunk, bool& isWord)
 
18
{
 
19
    isWord = false;
 
20
    chunk = wxEmptyString;
 
21
    if (IsEOF())
 
22
        return;
 
23
 
 
24
    unsigned int start = m_CurIdx;
 
25
    if (isalpha(CurrentChar()) || CurrentChar() == '_')
 
26
    {
 
27
        while (!IsEOF() &&
 
28
               (isalnum(CurrentChar()) || CurrentChar() == '_'))
 
29
            MoveToNextChar();
 
30
        chunk = m_Text.Mid(start, m_CurIdx - start);
 
31
        isWord = true;
 
32
    }
 
33
    else
 
34
    {
 
35
        SkipWhiteSpace();
 
36
        SkipUnwanted();
 
37
        if (start != m_CurIdx)
 
38
        {
 
39
            chunk = m_Text.Mid(start, m_CurIdx - start);
 
40
            return;
 
41
        }
 
42
 
 
43
        if (isdigit(CurrentChar()))
 
44
        {
 
45
            // numbers
 
46
            while (!IsEOF() && CharInString(CurrentChar(), "0123456789.abcdefABCDEFXxLl"))
 
47
                MoveToNextChar();
 
48
 
 
49
        }
 
50
        else if (CurrentChar() == '"' ||
 
51
                CurrentChar() == '\'')
 
52
        {
 
53
            // string, char, etc.
 
54
            wxChar match = CurrentChar();
 
55
            MoveToNextChar();  // skip starting ' or "
 
56
            SkipToChar(match);
 
57
            MoveToNextChar(); // skip ending ' or "
 
58
        }
 
59
        else
 
60
        {
 
61
            MoveToNextChar();
 
62
        }
 
63
        chunk = m_Text.Mid(start, m_CurIdx - start);
 
64
    }
 
65
    return;
 
66
}
 
67
 
 
68
bool TextCutter::SkipWhiteSpace()
 
69
{
 
70
    if (IsEOF())
 
71
        return false;
 
72
    while (!IsEOF() && isspace(CurrentChar()))
 
73
        MoveToNextChar();
 
74
    return true;
 
75
}
 
76
 
 
77
bool TextCutter::MoveToNextChar()
 
78
{
 
79
    if (IsEOF())
 
80
        return false;
 
81
        ++m_CurIdx;
 
82
        ++m_CurColumn;
 
83
    AdjustColumn();
 
84
    return true;
 
85
}
 
86
 
 
87
void TextCutter::AdjustColumn()
 
88
{
 
89
        if (CurrentChar() == '\n')
 
90
                m_CurColumn = 0;
 
91
}
 
92
 
 
93
wxChar TextCutter::CurrentChar()
 
94
{
 
95
    return m_Text.GetChar(m_CurIdx);
 
96
}
 
97
 
 
98
wxChar TextCutter::NextChar()
 
99
{
 
100
    if (m_CurIdx+1 >= m_TextLen)
 
101
        return '\0';
 
102
    return m_Text.GetChar(m_CurIdx+1);
 
103
}
 
104
 
 
105
void TextCutter::SkipUnwanted()
 
106
{
 
107
    if (IsEOF())
 
108
        return;
 
109
        while (CurrentChar() == '#' ||
 
110
           CurrentChar() == '!' ||
 
111
           ((CurrentChar() == 'c' || CurrentChar() == 'C' || CurrentChar() == '*') && m_CurColumn == 1 && m_CurSourceForm == fsfFixed))
 
112
        {
 
113
        SkipToEOL();
 
114
        SkipWhiteSpace();
 
115
        if (IsEOF())
 
116
            return;
 
117
        }
 
118
}
 
119
 
 
120
void TextCutter::SkipToChar(const wxChar& ch)
 
121
{
 
122
        // skip everything until we find ch
 
123
        while (1)
 
124
        {
 
125
                while (!IsEOF() && CurrentChar() != ch && CurrentChar() != '\n')
 
126
                        MoveToNextChar();
 
127
        break;
 
128
        }
 
129
}
 
130
 
 
131
bool TextCutter::CharInString(const char ch, const char* chars)
 
132
{
 
133
        int len = strlen(chars);
 
134
        for (int i = 0; i < len; ++i)
 
135
        {
 
136
                if (ch == chars[i])
 
137
                        return true;
 
138
        }
 
139
        return false;
 
140
}
 
141
 
 
142
void TextCutter::SkipToEOL()
 
143
{
 
144
    while (!IsEOF() && CurrentChar() != '\n')
 
145
        MoveToNextChar();
 
146
}