Mercurial > projects > dil
annotate trunk/src/dil/doc/Doc.d @ 722:ceaac6a24258
Added isUnicodeAlpha() for DDocParser and MacroParser.
author | Aziz K?ksal <aziz.koeksal@gmail.com> |
---|---|
date | Fri, 01 Feb 2008 19:44:00 +0100 |
parents | be887ada3e3e |
children | 41cad5ca4863 |
rev | line source |
---|---|
676
c4e3a34e40f1
Added new module dil.doc.Doc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
1 /++ |
c4e3a34e40f1
Added new module dil.doc.Doc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
2 Author: Aziz Köksal |
c4e3a34e40f1
Added new module dil.doc.Doc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
3 License: GPL3 |
c4e3a34e40f1
Added new module dil.doc.Doc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
4 +/ |
c4e3a34e40f1
Added new module dil.doc.Doc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
5 module dil.doc.Doc; |
c4e3a34e40f1
Added new module dil.doc.Doc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
6 |
c4e3a34e40f1
Added new module dil.doc.Doc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
7 import dil.ast.Node; |
712
f8875ef9a66d
Added function sanitize() to dil.doc.Doc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
680
diff
changeset
|
8 import dil.lexer.Funcs; |
716
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
9 import dil.Unicode; |
712
f8875ef9a66d
Added function sanitize() to dil.doc.Doc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
680
diff
changeset
|
10 import common; |
676
c4e3a34e40f1
Added new module dil.doc.Doc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
11 |
716
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
12 class DDocComment |
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
13 { |
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
14 Section[] sections; |
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
15 Section summary; /// Optional summary section. |
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
16 Section description; /// Optional description section. |
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
17 |
722
ceaac6a24258
Added isUnicodeAlpha() for DDocParser and MacroParser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
718
diff
changeset
|
18 this(Section[] sections, Section summary, Section description) |
716
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
19 { |
722
ceaac6a24258
Added isUnicodeAlpha() for DDocParser and MacroParser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
718
diff
changeset
|
20 this.sections = sections; |
ceaac6a24258
Added isUnicodeAlpha() for DDocParser and MacroParser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
718
diff
changeset
|
21 this.summary = summary; |
ceaac6a24258
Added isUnicodeAlpha() for DDocParser and MacroParser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
718
diff
changeset
|
22 this.description = description; |
716
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
23 } |
722
ceaac6a24258
Added isUnicodeAlpha() for DDocParser and MacroParser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
718
diff
changeset
|
24 } |
ceaac6a24258
Added isUnicodeAlpha() for DDocParser and MacroParser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
718
diff
changeset
|
25 |
ceaac6a24258
Added isUnicodeAlpha() for DDocParser and MacroParser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
718
diff
changeset
|
26 struct DDocParser |
ceaac6a24258
Added isUnicodeAlpha() for DDocParser and MacroParser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
718
diff
changeset
|
27 { |
ceaac6a24258
Added isUnicodeAlpha() for DDocParser and MacroParser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
718
diff
changeset
|
28 char* p; |
ceaac6a24258
Added isUnicodeAlpha() for DDocParser and MacroParser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
718
diff
changeset
|
29 char* textEnd; |
ceaac6a24258
Added isUnicodeAlpha() for DDocParser and MacroParser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
718
diff
changeset
|
30 Section[] sections; |
ceaac6a24258
Added isUnicodeAlpha() for DDocParser and MacroParser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
718
diff
changeset
|
31 Section summary; /// Optional summary section. |
ceaac6a24258
Added isUnicodeAlpha() for DDocParser and MacroParser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
718
diff
changeset
|
32 Section description; /// Optional description section. |
716
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
33 |
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
34 /// Parses the DDoc text into sections. |
722
ceaac6a24258
Added isUnicodeAlpha() for DDocParser and MacroParser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
718
diff
changeset
|
35 Section[] parse(string text) |
716
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
36 { |
722
ceaac6a24258
Added isUnicodeAlpha() for DDocParser and MacroParser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
718
diff
changeset
|
37 if (!text.length) |
ceaac6a24258
Added isUnicodeAlpha() for DDocParser and MacroParser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
718
diff
changeset
|
38 return null; |
ceaac6a24258
Added isUnicodeAlpha() for DDocParser and MacroParser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
718
diff
changeset
|
39 if (text[$-1] != '\0') |
ceaac6a24258
Added isUnicodeAlpha() for DDocParser and MacroParser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
718
diff
changeset
|
40 text ~= '\0'; |
ceaac6a24258
Added isUnicodeAlpha() for DDocParser and MacroParser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
718
diff
changeset
|
41 p = text.ptr; |
ceaac6a24258
Added isUnicodeAlpha() for DDocParser and MacroParser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
718
diff
changeset
|
42 textEnd = p + text.length; |
ceaac6a24258
Added isUnicodeAlpha() for DDocParser and MacroParser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
718
diff
changeset
|
43 |
716
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
44 char* summaryBegin; |
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
45 char* idBegin, idEnd; |
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
46 char* nextIdBegin, nextIdEnd; |
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
47 |
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
48 skipWhitespace(p); |
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
49 summaryBegin = p; |
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
50 |
722
ceaac6a24258
Added isUnicodeAlpha() for DDocParser and MacroParser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
718
diff
changeset
|
51 if (findNextIdColon(idBegin, idEnd)) |
716
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
52 { // Check that this is not an explicit section. |
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
53 if (summaryBegin != idBegin) |
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
54 scanSummaryAndDescription(summaryBegin, idBegin); |
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
55 } |
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
56 else // There are no explicit sections. |
722
ceaac6a24258
Added isUnicodeAlpha() for DDocParser and MacroParser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
718
diff
changeset
|
57 { |
ceaac6a24258
Added isUnicodeAlpha() for DDocParser and MacroParser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
718
diff
changeset
|
58 scanSummaryAndDescription(summaryBegin, textEnd); |
ceaac6a24258
Added isUnicodeAlpha() for DDocParser and MacroParser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
718
diff
changeset
|
59 return null; |
ceaac6a24258
Added isUnicodeAlpha() for DDocParser and MacroParser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
718
diff
changeset
|
60 } |
716
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
61 |
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
62 assert(idBegin && idEnd); |
722
ceaac6a24258
Added isUnicodeAlpha() for DDocParser and MacroParser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
718
diff
changeset
|
63 while (findNextIdColon(nextIdBegin, nextIdEnd)) |
716
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
64 { |
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
65 sections ~= new Section(makeString(idBegin, idEnd), makeString(idEnd+1, nextIdBegin)); |
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
66 idBegin = nextIdBegin; |
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
67 idEnd = nextIdEnd; |
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
68 } |
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
69 // Add last section. |
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
70 sections ~= new Section(makeString(idBegin, idEnd), makeString(idEnd+1, textEnd)); |
722
ceaac6a24258
Added isUnicodeAlpha() for DDocParser and MacroParser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
718
diff
changeset
|
71 return sections; |
716
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
72 } |
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
73 |
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
74 void scanSummaryAndDescription(char* p, char* end) |
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
75 { |
722
ceaac6a24258
Added isUnicodeAlpha() for DDocParser and MacroParser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
718
diff
changeset
|
76 assert(p < end); |
716
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
77 char* sectionBegin = p; |
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
78 // Search for the end of the first paragraph. |
722
ceaac6a24258
Added isUnicodeAlpha() for DDocParser and MacroParser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
718
diff
changeset
|
79 while (p < end && !(*p == '\n' && p[1] == '\n')) |
716
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
80 p++; |
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
81 // The first paragraph is the summary. |
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
82 summary = new Section("", makeString(sectionBegin, p)); |
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
83 sections ~= summary; |
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
84 // The rest is the description section. |
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
85 if (p != end) |
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
86 { |
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
87 sectionBegin = p; |
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
88 skipWhitespace(p); |
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
89 if (p < end) |
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
90 { |
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
91 description = new Section("", makeString(sectionBegin, end)); |
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
92 sections ~= description; |
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
93 } |
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
94 } |
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
95 } |
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
96 |
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
97 void skipWhitespace(ref char* p) |
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
98 { |
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
99 while (isspace(*p) || *p == '\n') |
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
100 p++; |
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
101 } |
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
102 |
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
103 /// Find next "Identifier:". |
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
104 /// Params: |
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
105 /// p = current character pointer |
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
106 /// idBegin = set to the first character of the Identifier |
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
107 /// idEnd = set to the colon following the Identifier |
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
108 /// Returns: true if found |
722
ceaac6a24258
Added isUnicodeAlpha() for DDocParser and MacroParser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
718
diff
changeset
|
109 bool findNextIdColon(ref char* ref_idBegin, ref char* ref_idEnd) |
716
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
110 { |
722
ceaac6a24258
Added isUnicodeAlpha() for DDocParser and MacroParser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
718
diff
changeset
|
111 auto p = this.p; |
716
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
112 while (*p != '\0') |
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
113 { |
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
114 auto idBegin = p; |
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
115 assert(isascii(*p) || isLeadByte(*p)); |
722
ceaac6a24258
Added isUnicodeAlpha() for DDocParser and MacroParser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
718
diff
changeset
|
116 if (isidbeg(*p) || isUnicodeAlpha(p, textEnd)) // IdStart |
716
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
117 { |
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
118 do // IdChar* |
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
119 p++; |
722
ceaac6a24258
Added isUnicodeAlpha() for DDocParser and MacroParser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
718
diff
changeset
|
120 while (isident(*p) || isUnicodeAlpha(p, textEnd)) |
716
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
121 if (*p == ':') // : |
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
122 { |
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
123 ref_idBegin = idBegin; |
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
124 ref_idEnd = p; |
722
ceaac6a24258
Added isUnicodeAlpha() for DDocParser and MacroParser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
718
diff
changeset
|
125 this.p = p; |
716
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
126 return true; |
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
127 } |
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
128 } |
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
129 else if (!isascii(*p)) |
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
130 { // Skip UTF-8 sequences. |
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
131 while (!isascii(*++p)) |
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
132 {} |
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
133 continue; |
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
134 } |
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
135 p++; |
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
136 } |
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
137 return false; |
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
138 } |
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
139 } |
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
140 |
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
141 class Section |
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
142 { |
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
143 string name; |
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
144 string text; |
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
145 this(string name, string text) |
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
146 { |
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
147 this.name = name; |
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
148 this.text = text; |
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
149 } |
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
150 } |
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
151 |
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
152 char[] makeString(char* begin, char* end) |
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
153 { |
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
154 return begin[0 .. end - begin]; |
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
155 } |
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
156 |
676
c4e3a34e40f1
Added new module dil.doc.Doc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
157 bool isDoxygenComment(Token* token) |
c4e3a34e40f1
Added new module dil.doc.Doc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
158 { // Doxygen: '/+!' '/*!' '//!' |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
676
diff
changeset
|
159 return token.kind == TOK.Comment && token.start[2] == '!'; |
676
c4e3a34e40f1
Added new module dil.doc.Doc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
160 } |
c4e3a34e40f1
Added new module dil.doc.Doc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
161 |
c4e3a34e40f1
Added new module dil.doc.Doc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
162 bool isDDocComment(Token* token) |
c4e3a34e40f1
Added new module dil.doc.Doc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
163 { // DDOC: '/++' '/**' '///' |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
676
diff
changeset
|
164 return token.kind == TOK.Comment && token.start[1] == token.start[2]; |
676
c4e3a34e40f1
Added new module dil.doc.Doc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
165 } |
c4e3a34e40f1
Added new module dil.doc.Doc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
166 |
c4e3a34e40f1
Added new module dil.doc.Doc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
167 /++ |
c4e3a34e40f1
Added new module dil.doc.Doc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
168 Returns the surrounding documentation comment tokens. |
c4e3a34e40f1
Added new module dil.doc.Doc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
169 Note: this function works correctly only if |
c4e3a34e40f1
Added new module dil.doc.Doc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
170 the source text is syntactically correct. |
c4e3a34e40f1
Added new module dil.doc.Doc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
171 +/ |
714
140469ecb90e
Added code and applied fixes.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
712
diff
changeset
|
172 Token*[] getDocTokens(Node node, bool function(Token*) isDocComment = &isDDocComment) |
676
c4e3a34e40f1
Added new module dil.doc.Doc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
173 { |
c4e3a34e40f1
Added new module dil.doc.Doc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
174 Token*[] comments; |
714
140469ecb90e
Added code and applied fixes.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
712
diff
changeset
|
175 auto isEnumMember = node.kind == NodeKind.EnumMemberDeclaration; |
676
c4e3a34e40f1
Added new module dil.doc.Doc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
176 // Get preceding comments. |
c4e3a34e40f1
Added new module dil.doc.Doc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
177 auto token = node.begin; |
c4e3a34e40f1
Added new module dil.doc.Doc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
178 // Scan backwards until we hit another declaration. |
714
140469ecb90e
Added code and applied fixes.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
712
diff
changeset
|
179 Loop: |
676
c4e3a34e40f1
Added new module dil.doc.Doc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
180 while (1) |
c4e3a34e40f1
Added new module dil.doc.Doc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
181 { |
c4e3a34e40f1
Added new module dil.doc.Doc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
182 token = token.prev; |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
676
diff
changeset
|
183 if (token.kind == TOK.LBrace || |
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
676
diff
changeset
|
184 token.kind == TOK.RBrace || |
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
676
diff
changeset
|
185 token.kind == TOK.Semicolon || |
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
676
diff
changeset
|
186 token.kind == TOK.HEAD || |
714
140469ecb90e
Added code and applied fixes.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
712
diff
changeset
|
187 (isEnumMember && token.kind == TOK.Comma)) |
676
c4e3a34e40f1
Added new module dil.doc.Doc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
188 break; |
c4e3a34e40f1
Added new module dil.doc.Doc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
189 |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
676
diff
changeset
|
190 if (token.kind == TOK.Comment) |
714
140469ecb90e
Added code and applied fixes.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
712
diff
changeset
|
191 { // Check that this comment doesn't belong to the previous declaration. |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
676
diff
changeset
|
192 switch (token.prev.kind) |
676
c4e3a34e40f1
Added new module dil.doc.Doc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
193 { |
714
140469ecb90e
Added code and applied fixes.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
712
diff
changeset
|
194 case TOK.Semicolon, TOK.RBrace, TOK.Comma: |
140469ecb90e
Added code and applied fixes.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
712
diff
changeset
|
195 break Loop; |
676
c4e3a34e40f1
Added new module dil.doc.Doc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
196 default: |
c4e3a34e40f1
Added new module dil.doc.Doc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
197 if (isDocComment(token)) |
714
140469ecb90e
Added code and applied fixes.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
712
diff
changeset
|
198 comments = [token] ~ comments; |
676
c4e3a34e40f1
Added new module dil.doc.Doc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
199 } |
c4e3a34e40f1
Added new module dil.doc.Doc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
200 } |
c4e3a34e40f1
Added new module dil.doc.Doc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
201 } |
c4e3a34e40f1
Added new module dil.doc.Doc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
202 // Get single comment to the right. |
c4e3a34e40f1
Added new module dil.doc.Doc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
203 token = node.end.next; |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
676
diff
changeset
|
204 if (token.kind == TOK.Comment && isDocComment(token)) |
676
c4e3a34e40f1
Added new module dil.doc.Doc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
205 comments ~= token; |
714
140469ecb90e
Added code and applied fixes.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
712
diff
changeset
|
206 else if (isEnumMember) |
676
c4e3a34e40f1
Added new module dil.doc.Doc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
207 { |
c4e3a34e40f1
Added new module dil.doc.Doc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
208 token = node.end.nextNWS; |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
676
diff
changeset
|
209 if (token.kind == TOK.Comma) |
676
c4e3a34e40f1
Added new module dil.doc.Doc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
210 { |
c4e3a34e40f1
Added new module dil.doc.Doc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
211 token = token.next; |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
676
diff
changeset
|
212 if (token.kind == TOK.Comment && isDocComment(token)) |
676
c4e3a34e40f1
Added new module dil.doc.Doc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
213 comments ~= token; |
c4e3a34e40f1
Added new module dil.doc.Doc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
214 } |
c4e3a34e40f1
Added new module dil.doc.Doc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
215 } |
c4e3a34e40f1
Added new module dil.doc.Doc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
216 return comments; |
c4e3a34e40f1
Added new module dil.doc.Doc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
217 } |
712
f8875ef9a66d
Added function sanitize() to dil.doc.Doc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
680
diff
changeset
|
218 |
714
140469ecb90e
Added code and applied fixes.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
712
diff
changeset
|
219 bool isLineComment(Token* t) |
140469ecb90e
Added code and applied fixes.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
712
diff
changeset
|
220 { |
140469ecb90e
Added code and applied fixes.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
712
diff
changeset
|
221 assert(t.kind == TOK.Comment); |
140469ecb90e
Added code and applied fixes.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
712
diff
changeset
|
222 return t.start[1] == '/'; |
140469ecb90e
Added code and applied fixes.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
712
diff
changeset
|
223 } |
140469ecb90e
Added code and applied fixes.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
712
diff
changeset
|
224 |
140469ecb90e
Added code and applied fixes.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
712
diff
changeset
|
225 /// Extracts the text body of the comment tokens. |
140469ecb90e
Added code and applied fixes.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
712
diff
changeset
|
226 string getDDocText(Token*[] tokens) |
140469ecb90e
Added code and applied fixes.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
712
diff
changeset
|
227 { |
140469ecb90e
Added code and applied fixes.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
712
diff
changeset
|
228 string result; |
140469ecb90e
Added code and applied fixes.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
712
diff
changeset
|
229 foreach (token; tokens) |
140469ecb90e
Added code and applied fixes.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
712
diff
changeset
|
230 { |
140469ecb90e
Added code and applied fixes.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
712
diff
changeset
|
231 auto n = isLineComment(token) ? 0 : 2; // 0 for "//", 2 for "+/" and "*/". |
140469ecb90e
Added code and applied fixes.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
712
diff
changeset
|
232 result ~= sanitize(token.srcText[3 .. $-n], token.start[1]); |
140469ecb90e
Added code and applied fixes.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
712
diff
changeset
|
233 } |
140469ecb90e
Added code and applied fixes.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
712
diff
changeset
|
234 return result; |
140469ecb90e
Added code and applied fixes.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
712
diff
changeset
|
235 } |
140469ecb90e
Added code and applied fixes.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
712
diff
changeset
|
236 |
712
f8875ef9a66d
Added function sanitize() to dil.doc.Doc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
680
diff
changeset
|
237 /// Sanitizes a DDoc comment string. |
714
140469ecb90e
Added code and applied fixes.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
712
diff
changeset
|
238 /// Leading "commentChar"s are removed from the lines. |
712
f8875ef9a66d
Added function sanitize() to dil.doc.Doc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
680
diff
changeset
|
239 /// The various newline types are converted to '\n'. |
f8875ef9a66d
Added function sanitize() to dil.doc.Doc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
680
diff
changeset
|
240 /// Params: |
f8875ef9a66d
Added function sanitize() to dil.doc.Doc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
680
diff
changeset
|
241 /// comment = the string to be sanitized. |
f8875ef9a66d
Added function sanitize() to dil.doc.Doc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
680
diff
changeset
|
242 /// commentChar = '/', '+', or '*' |
f8875ef9a66d
Added function sanitize() to dil.doc.Doc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
680
diff
changeset
|
243 string sanitize(string comment, char commentChar) |
f8875ef9a66d
Added function sanitize() to dil.doc.Doc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
680
diff
changeset
|
244 { |
f8875ef9a66d
Added function sanitize() to dil.doc.Doc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
680
diff
changeset
|
245 string result = comment.dup ~ '\0'; |
f8875ef9a66d
Added function sanitize() to dil.doc.Doc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
680
diff
changeset
|
246 |
f8875ef9a66d
Added function sanitize() to dil.doc.Doc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
680
diff
changeset
|
247 assert(result[$-1] == '\0'); |
f8875ef9a66d
Added function sanitize() to dil.doc.Doc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
680
diff
changeset
|
248 bool newline = true; // Indicates whether a newline has been encountered. |
f8875ef9a66d
Added function sanitize() to dil.doc.Doc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
680
diff
changeset
|
249 uint i, j; |
f8875ef9a66d
Added function sanitize() to dil.doc.Doc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
680
diff
changeset
|
250 for (; i < result.length; i++) |
f8875ef9a66d
Added function sanitize() to dil.doc.Doc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
680
diff
changeset
|
251 { |
f8875ef9a66d
Added function sanitize() to dil.doc.Doc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
680
diff
changeset
|
252 if (newline) |
f8875ef9a66d
Added function sanitize() to dil.doc.Doc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
680
diff
changeset
|
253 { // Ignore commentChars at the beginning of each new line. |
f8875ef9a66d
Added function sanitize() to dil.doc.Doc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
680
diff
changeset
|
254 newline = false; |
f8875ef9a66d
Added function sanitize() to dil.doc.Doc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
680
diff
changeset
|
255 while (isspace(result[i])) |
f8875ef9a66d
Added function sanitize() to dil.doc.Doc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
680
diff
changeset
|
256 { i++; } |
f8875ef9a66d
Added function sanitize() to dil.doc.Doc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
680
diff
changeset
|
257 while (result[i] == commentChar) |
f8875ef9a66d
Added function sanitize() to dil.doc.Doc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
680
diff
changeset
|
258 { i++; } |
f8875ef9a66d
Added function sanitize() to dil.doc.Doc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
680
diff
changeset
|
259 } |
f8875ef9a66d
Added function sanitize() to dil.doc.Doc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
680
diff
changeset
|
260 // Check for Newline. |
f8875ef9a66d
Added function sanitize() to dil.doc.Doc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
680
diff
changeset
|
261 switch (result[i]) |
f8875ef9a66d
Added function sanitize() to dil.doc.Doc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
680
diff
changeset
|
262 { |
f8875ef9a66d
Added function sanitize() to dil.doc.Doc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
680
diff
changeset
|
263 case '\r': |
f8875ef9a66d
Added function sanitize() to dil.doc.Doc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
680
diff
changeset
|
264 if (result[i+1] == '\n') |
f8875ef9a66d
Added function sanitize() to dil.doc.Doc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
680
diff
changeset
|
265 i++; |
f8875ef9a66d
Added function sanitize() to dil.doc.Doc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
680
diff
changeset
|
266 case '\n': |
f8875ef9a66d
Added function sanitize() to dil.doc.Doc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
680
diff
changeset
|
267 result[j++] = '\n'; // Copy Newline as '\n'. |
f8875ef9a66d
Added function sanitize() to dil.doc.Doc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
680
diff
changeset
|
268 newline = true; |
f8875ef9a66d
Added function sanitize() to dil.doc.Doc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
680
diff
changeset
|
269 continue; |
f8875ef9a66d
Added function sanitize() to dil.doc.Doc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
680
diff
changeset
|
270 default: |
f8875ef9a66d
Added function sanitize() to dil.doc.Doc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
680
diff
changeset
|
271 if (isUnicodeNewline(result.ptr + i)) |
f8875ef9a66d
Added function sanitize() to dil.doc.Doc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
680
diff
changeset
|
272 { |
f8875ef9a66d
Added function sanitize() to dil.doc.Doc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
680
diff
changeset
|
273 i++; i++; |
f8875ef9a66d
Added function sanitize() to dil.doc.Doc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
680
diff
changeset
|
274 goto case '\n'; |
f8875ef9a66d
Added function sanitize() to dil.doc.Doc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
680
diff
changeset
|
275 } |
f8875ef9a66d
Added function sanitize() to dil.doc.Doc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
680
diff
changeset
|
276 } |
f8875ef9a66d
Added function sanitize() to dil.doc.Doc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
680
diff
changeset
|
277 // Copy character. |
f8875ef9a66d
Added function sanitize() to dil.doc.Doc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
680
diff
changeset
|
278 result[j++] = result[i]; |
f8875ef9a66d
Added function sanitize() to dil.doc.Doc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
680
diff
changeset
|
279 } |
f8875ef9a66d
Added function sanitize() to dil.doc.Doc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
680
diff
changeset
|
280 result.length = j; // Adjust length. |
f8875ef9a66d
Added function sanitize() to dil.doc.Doc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
680
diff
changeset
|
281 // Lastly, strip trailing commentChars. |
f8875ef9a66d
Added function sanitize() to dil.doc.Doc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
680
diff
changeset
|
282 i = result.length - (1 + 1); |
f8875ef9a66d
Added function sanitize() to dil.doc.Doc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
680
diff
changeset
|
283 while (i && result[i] == commentChar) |
f8875ef9a66d
Added function sanitize() to dil.doc.Doc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
680
diff
changeset
|
284 { i--; } |
f8875ef9a66d
Added function sanitize() to dil.doc.Doc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
680
diff
changeset
|
285 return result; |
f8875ef9a66d
Added function sanitize() to dil.doc.Doc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
680
diff
changeset
|
286 } |