1 /* This file is part of NIT ( http://www.nitlanguage.org ).
3 Licensed under the Apache License, Version 2.0 (the "License");
4 you may not use this file except in compliance with the License.
5 You may obtain a copy of the License at
7 http://www.apache.org/licenses/LICENSE-2.0
9 Unless required by applicable law or agreed to in writing, software
10 distributed under the License is distributed on an "AS IS" BASIS,
11 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 See the License for the specific language governing permissions and
13 limitations under the License.
15 Documentation generator for the nit language.
16 Generate API documentation in HTML format from nit source code.
22 String
.prototype.startsWith
= function(prefix
, caseSensitive
) {
24 return this.toUpperCase().indexOf(prefix
.toUpperCase()) === 0;
26 return this.indexOf(prefix
) === 0;
29 // Compare two strings using Sorensen-Dice Coefficient
30 // see: http://en.wikipedia.org/wiki/S%C3%B8rensen%E2%80%93Dice_coefficient
31 String
.prototype.dice
= function(other
) {
32 var length1
= this.length
- 1;
33 var length2
= other
.length
- 1;
34 if(length1
< 1 || length2
< 1) return 0;
37 for(var i
= 0; i
< length2
; i
++) {
38 bigrams2
.push(other
.substr(i
, 2));
42 for(var i
= 0; i
< length1
; i
++) {
43 var bigram1
= this.substr(i
, 2);
44 for(var j
= 0; j
< length2
; j
++) {
45 if(bigram1
== bigrams2
[j]) {
52 return (2.0 * intersection
) / (length1
+ length2
);
57 String
.prototype._keyStr
= "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
59 // public method for encoding
60 String
.prototype.base64Encode
= function () {
62 var chr1
, chr2
, chr3
, enc1
, enc2
, enc3
, enc4
;
65 input
= this._utf8_encode();
67 while (i
< input
.length
) {
69 chr1
= input
.charCodeAt(i
++);
70 chr2
= input
.charCodeAt(i
++);
71 chr3
= input
.charCodeAt(i
++);
74 enc2
= ((chr1
& 3) << 4) |
(chr2
>> 4);
75 enc3
= ((chr2
& 15) << 2) |
(chr3
>> 6);
80 } else if (isNaN(chr3
)) {
85 this._keyStr
.charAt(enc1
) + this._keyStr
.charAt(enc2
) +
86 this._keyStr
.charAt(enc3
) + this._keyStr
.charAt(enc4
);
92 // public method for decoding
93 String
.prototype.base64Decode
= function () {
96 var enc1
, enc2
, enc3
, enc4
;
99 input
= this.replace(/[^A
-Za
-z0
-9\
+\
/\
=]/g
, "");
101 while (i
< input
.length
) {
103 enc1
= this._keyStr
.indexOf(input
.charAt(i
++));
104 enc2
= this._keyStr
.indexOf(input
.charAt(i
++));
105 enc3
= this._keyStr
.indexOf(input
.charAt(i
++));
106 enc4
= this._keyStr
.indexOf(input
.charAt(i
++));
108 chr1
= (enc1
<< 2) |
(enc2
>> 4);
109 chr2
= ((enc2
& 15) << 4) |
(enc3
>> 2);
110 chr3
= ((enc3
& 3) << 6) | enc4
;
112 output
= output
+ String
.fromCharCode(chr1
);
115 output
= output
+ String
.fromCharCode(chr2
);
118 output
= output
+ String
.fromCharCode(chr3
);
122 return output
._utf8_decode();;
125 // private method for UTF-8 encoding
126 String
.prototype._utf8_encode
= function () {
127 string
= this.replace(/\r\n/g
,"\n");
130 for (var n
= 0; n
< string
.length
; n
++) {
132 var c
= string
.charCodeAt(n
);
135 utftext
+= String
.fromCharCode(c
);
137 else if((c
> 127) && (c
< 2048)) {
138 utftext
+= String
.fromCharCode((c
>> 6) |
192);
139 utftext
+= String
.fromCharCode((c
& 63) |
128);
142 utftext
+= String
.fromCharCode((c
>> 12) |
224);
143 utftext
+= String
.fromCharCode(((c
>> 6) & 63) |
128);
144 utftext
+= String
.fromCharCode((c
& 63) |
128);
151 // private method for UTF-8 decoding
152 String
.prototype._utf8_decode
= function () {
157 while ( i
< this.length
) {
159 c
= this.charCodeAt(i
);
162 string
+= String
.fromCharCode(c
);
165 else if((c
> 191) && (c
< 224)) {
166 c2
= this.charCodeAt(i
+1);
167 string
+= String
.fromCharCode(((c
& 31) << 6) |
(c2
& 63));
171 c2
= this.charCodeAt(i
+1);
172 c3
= this.charCodeAt(i
+2);
173 string
+= String
.fromCharCode(((c
& 15) << 12) |
((c2
& 63) << 6) |
(c3
& 63));
181 // JQuery Case Insensitive :icontains selector
182 $
.expr
[':'].icontains
= function(obj
, index
, meta
, stack
){
183 return (obj
.textContent
.replace(/\
[[0-9]+\
]/g
, "") || obj
.innerText
.replace(/\
[[0-9]+\
]/g
, "") ||
jQuery(obj
).text().replace(/\
[[0-9]+\
]/g
, "") ||
'').toLowerCase().indexOf(meta
[3].toLowerCase()) >= 0;
187 // Extract anchor part (after #) from URL string
188 extractAnchor
: function(url
) {
189 var index
= url
.indexOf("#");
191 return url
.substring(index
+ 1);
196 delayEvent
: function(handler
, event
) {
197 if(this.delayEvent
.timeout
) {
198 clearTimeout(this.delayEvent
.timeout
);
200 this.delayEvent
.timeout
= setTimeout(function() {