~efargaspro/+junk/codeblocks-16.01-release

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
#include "textcutter.h"

TextCutter::TextCutter(const wxString& allText, FortranSourceForm fsForm)
{
    m_Text = allText;
    m_TextLen = m_Text.length();
    m_CurSourceForm = fsForm;
    m_CurIdx = 0;
    m_CurColumn = 1;
}

TextCutter::~TextCutter()
{
};

void TextCutter::GetChunk(wxString& chunk, bool& isWord)
{
    isWord = false;
    chunk = wxEmptyString;
    if (IsEOF())
        return;

    unsigned int start = m_CurIdx;
    if (isalpha(CurrentChar()) || CurrentChar() == '_')
    {
        while (!IsEOF() &&
               (isalnum(CurrentChar()) || CurrentChar() == '_'))
            MoveToNextChar();
        chunk = m_Text.Mid(start, m_CurIdx - start);
        isWord = true;
    }
    else
    {
        SkipWhiteSpace();
        SkipUnwanted();
        if (start != m_CurIdx)
        {
            chunk = m_Text.Mid(start, m_CurIdx - start);
            return;
        }

        if (isdigit(CurrentChar()))
        {
            // numbers
            while (!IsEOF() && CharInString(CurrentChar(), "0123456789.abcdefABCDEFXxLl"))
                MoveToNextChar();

        }
        else if (CurrentChar() == '"' ||
                CurrentChar() == '\'')
        {
            // string, char, etc.
            wxChar match = CurrentChar();
            MoveToNextChar();  // skip starting ' or "
            SkipToChar(match);
            MoveToNextChar(); // skip ending ' or "
        }
        else
        {
            MoveToNextChar();
        }
        chunk = m_Text.Mid(start, m_CurIdx - start);
    }
    return;
}

bool TextCutter::SkipWhiteSpace()
{
    if (IsEOF())
        return false;
    while (!IsEOF() && isspace(CurrentChar()))
        MoveToNextChar();
    return true;
}

bool TextCutter::MoveToNextChar()
{
    if (IsEOF())
        return false;
	++m_CurIdx;
	++m_CurColumn;
    AdjustColumn();
    return true;
}

void TextCutter::AdjustColumn()
{
	if (CurrentChar() == '\n')
		m_CurColumn = 0;
}

wxChar TextCutter::CurrentChar()
{
    return m_Text.GetChar(m_CurIdx);
}

wxChar TextCutter::NextChar()
{
    if (m_CurIdx+1 >= m_TextLen)
        return '\0';
    return m_Text.GetChar(m_CurIdx+1);
}

void TextCutter::SkipUnwanted()
{
    if (IsEOF())
        return;
	while (CurrentChar() == '#' ||
           CurrentChar() == '!' ||
           ((CurrentChar() == 'c' || CurrentChar() == 'C' || CurrentChar() == '*') && m_CurColumn == 1 && m_CurSourceForm == fsfFixed))
	{
        SkipToEOL();
        SkipWhiteSpace();
        if (IsEOF())
            return;
	}
}

void TextCutter::SkipToChar(const wxChar& ch)
{
	// skip everything until we find ch
	while (1)
	{
		while (!IsEOF() && CurrentChar() != ch && CurrentChar() != '\n')
			MoveToNextChar();
        break;
	}
}

bool TextCutter::CharInString(const char ch, const char* chars)
{
	int len = strlen(chars);
	for (int i = 0; i < len; ++i)
	{
		if (ch == chars[i])
			return true;
	}
	return false;
}

void TextCutter::SkipToEOL()
{
    while (!IsEOF() && CurrentChar() != '\n')
        MoveToNextChar();
}