-
Notifications
You must be signed in to change notification settings - Fork 5
/
ulazcomment.pas
169 lines (161 loc) · 6.78 KB
/
ulazcomment.pas
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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
(******************************************************************************)
(* Lazcomment 08.09.2009 *)
(* *)
(* Version : 0.01 *)
(* *)
(* Author : Uwe Schächterle (Corpsman) *)
(* *)
(* Support : www.Corpsman.de *)
(* *)
(* Description : comments or uncomments selected textblocks *)
(* *)
(* License : See the file license.md, located under: *)
(* https://github.com/PascalCorpsman/Software_Licenses/blob/main/license.md *)
(* for details about the license. *)
(* *)
(* It is not allowed to change or remove this text from any *)
(* source file of the project. *)
(* *)
(* Warranty : There is no warranty, neither in correctness of the *)
(* implementation, nor anything other that could happen *)
(* or go wrong, use at your own risk. *)
(* *)
(* Known Issues: none *)
(* *)
(* History : 0.01 - Initial version *)
(* *)
(******************************************************************************)
Unit ulazcomment;
{$MODE objfpc}{$H+}
Interface
Uses classes;
Procedure Comment(Const Lines: TStrings; SelStart, SelEnd: Integer; is_C_Code: Boolean = false);
Implementation
Procedure Comment(Const Lines: TStrings; SelStart, SelEnd: Integer; is_C_Code: Boolean = false);
Var
b: Boolean;
i, j, k: integer;
Begin
If selend < selstart Then Begin
i := selstart;
selstart := selend;
selend := i;
End;
If SelStart = SelEnd Then Begin
// Eine einzige ganze Zeile Kommentieren -- Fertig, getestet.
For i := Selstart Downto 1 Do
If (Lines.text[i] = #10) Or (i = 1) Then Begin
// wir haben nun zwar das crt aber die "Leerzeichen, am Anfang der Zeile müssen ignoriert werden."
If (i <> 1) Then
j := i + 1
Else
j := 1;
While lines.text[j] = #32 Do
inc(j);
If (lines.text[j] = '/') And (lines.text[j + 1] = '/') Then Begin
// Kommentar Entfernen
Lines.text := copy(Lines.text, 1, j - 1) + copy(lines.text, j + 2, length(lines.text));
exit;
End
Else Begin
// Kommentar Einfügen
Lines.text := copy(Lines.text, 1, i) + '//' + copy(lines.text, i + 1, length(lines.text));
exit;
End;
End;
End
Else Begin
// Es mus unterschieden werden, zwischen kommentar in einer Zeile, oder mehrere Zeilen Auskommentieren.
b := false;
For i := SelStart To SelEnd Do
If lines.text[i] = #10 Then Begin
b := True;
break;
End;
If b Then Begin
// Mehrere Zeilen wurden zum auskommentieren ausgewählt -- Fertig, getestet.
(*
Erst mal ermitteln, ob ein oder Auskommentiert werden mus.
*)
i := selstart;
While lines.text[i] <> #10 Do
dec(i);
inc(i);
While lines.text[i] = #32 Do
inc(i);
If (lines.text[i] = '/') And (lines.text[i + 1] = '/') Then Begin
// Kommentar Entfernen
i := SelEnd;
j := selstart;
While i >= j Do Begin
If lines.text[i] = #10 Then Begin
k := i + 1;
While lines.text[k] = #32 Do
inc(k);
If (Lines.text[k] = '/') And (Lines.text[k + 1] = '/') Then Begin
lines.text := copy(lines.text, 1, k - 1) + copy(lines.text, k + 2, length(lines.text));
End;
End;
dec(i);
End;
While (i >= 1) And (lines.text[i] <> #10) Do Begin
dec(i);
End;
k := i + 1;
While lines.text[k] = #32 Do
inc(k);
If (Lines.text[k] = '/') And (Lines.text[k + 1] = '/') Then Begin
lines.text := copy(lines.text, 1, k - 1) + copy(lines.text, k + 2, length(lines.text));
End;
End
Else Begin
// Kommentar Einfügen
i := SelEnd;
j := selstart;
While i >= j Do Begin
If lines.text[i] = #10 Then Begin
lines.text := copy(lines.text, 1, i) + '//' + copy(lines.text, i + 1, length(lines.text));
End;
dec(i);
End;
i := j;
While (i >= 1) And (lines.text[i] <> #10) Do Begin
dec(i);
End;
lines.text := copy(lines.text, 1, i) + '//' + copy(lines.text, i + 1, length(lines.text));
End;
End
Else Begin
//Ein kurzer Teilstring in einer Zeile wurde ausgewählt und wird mit { } auskommentiert. -- Fertig, getestet.
If is_C_Code Then Begin
If (Lines.text[selstart] = '/') And (Lines.text[selstart + 1] = '*') And (Lines.text[selend - 2] = '*') And (Lines.text[selend - 1] = '/') Then Begin
// Kommentar Entfernen
lines.text := copy(lines.text, 1, selstart - 1) +
copy(lines.text, Selstart + 2, selend - selstart - 4) +
copy(lines.text, selend, length(lines.text));
End
Else Begin
// Kommentar Einfügen
Lines.text := copy(Lines.text, 1, selstart - 1) + '/*' +
copy(lines.text, selstart, selend - selstart) + '*/' +
copy(Lines.text, SelEnd, length(lines.text));
End;
End
Else Begin
If (Lines.text[selstart] = '{') And (Lines.text[selend - 1] = '}') Then Begin
// Kommentar Entfernen
lines.text := copy(lines.text, 1, selstart - 1) +
copy(lines.text, Selstart + 1, selend - selstart - 2) +
copy(lines.text, selend, length(lines.text));
End
Else Begin
// Kommentar Einfügen
Lines.text := copy(Lines.text, 1, selstart - 1) + '{' +
copy(lines.text, selstart, selend - selstart) + '}' +
copy(Lines.text, SelEnd, length(lines.text));
End;
End;
End;
End;
End;
End.