MCPcopy Create free account
hub / github.com/KDAB/codebrowser / identAndHighlightMacro

Function identAndHighlightMacro

data/codebrowser.js:158–259  ·  view source on GitHub ↗
(origin)

Source from the content-addressed store, hash-verified

156
157 // ident and highlight code (for macros)
158 function identAndHighlightMacro(origin) {
159
160 // count the number of slashes before character i in origin
161 function countSlashes(i) {
162 var count = 0;
163 while(count < i && origin.charAt(i-count-1) == '\\')
164 count++;
165 return count;
166 }
167
168 var len = origin.length;
169 var result = "";
170 var ident= "\n";
171 var parenLevel = 0;
172 var string = 0; //0 = none 1=" 2='
173 var lineLen = 0;
174
175 for (var i = 0; i < len; ++i) {
176 var c = origin.charAt(i);
177 switch (c) {
178 case '>': lineLen++; result+="&gt;"; break;
179 case '<': lineLen++; result+="&lt;"; break;
180 case '&': lineLen++; result+="&amp;"; break;
181 case ')':
182 result+=")";
183 if (!string) {
184 parenLevel--;
185 if (parenLevel < 0) parenLevel = 0;
186 }
187 break;
188 case '(':
189 result+="(";
190 if (!string && i > 1)
191 parenLevel++;
192 break;
193 case ';':
194 result+=";";
195 if (parenLevel==0 && !string) {
196 result += ident;
197 lineLen = 0;
198 }
199 break;
200 case '{':
201 result+="{";
202 if (parenLevel==0 && !string) {
203 ident+=" ";
204 result+=ident;
205 lineLen = 0;
206 }
207 break;
208 case '}':
209 if (parenLevel==0 && !string) {
210 if (lineLen == 0 && ident.length > 2)
211 result = result.slice(0, -2)
212 result += "}";
213 ident = ident.slice(0, -2);
214 if (i+1 < len && origin.charAt(i+1) != ';') {
215 result += ident;

Callers 1

onMouseEnterRefFunction · 0.85

Calls 1

countSlashesFunction · 0.85

Tested by

no test coverage detected