~efargaspro/+junk/codeblocks-16.01-release

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