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.
26 String
.prototype.startsWith
= function(prefix
, caseSensitive
) {
28 return this.toUpperCase().indexOf(prefix
.toUpperCase()) === 0;
30 return this.indexOf(prefix
) === 0;
33 // Compare two strings using Sorensen-Dice Coefficient
34 // see: http://en.wikipedia.org/wiki/S%C3%B8rensen%E2%80%93Dice_coefficient
35 String
.prototype.dice
= function(other
) {
36 var length1
= this.length
- 1;
37 var length2
= other
.length
- 1;
38 if(length1
< 1 || length2
< 1) return 0;
41 for(var i
= 0; i
< length2
; i
++) {
42 bigrams2
.push(other
.substr(i
, 2));
46 for(var i
= 0; i
< length1
; i
++) {
47 var bigram1
= this.substr(i
, 2);
48 for(var j
= 0; j
< length2
; j
++) {
49 if(bigram1
== bigrams2
[j]) {
56 return (2.0 * intersection
) / (length1
+ length2
);
61 String
.prototype._keyStr
= "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
63 // public method for encoding
64 String
.prototype.base64Encode
= function () {
66 var chr1
, chr2
, chr3
, enc1
, enc2
, enc3
, enc4
;
69 input
= this._utf8_encode();
71 while (i
< input
.length
) {
73 chr1
= input
.charCodeAt(i
++);
74 chr2
= input
.charCodeAt(i
++);
75 chr3
= input
.charCodeAt(i
++);
78 enc2
= ((chr1
& 3) << 4) |
(chr2
>> 4);
79 enc3
= ((chr2
& 15) << 2) |
(chr3
>> 6);
84 } else if (isNaN(chr3
)) {
89 this._keyStr
.charAt(enc1
) + this._keyStr
.charAt(enc2
) +
90 this._keyStr
.charAt(enc3
) + this._keyStr
.charAt(enc4
);
96 // public method for decoding
97 String
.prototype.base64Decode
= function () {
100 var enc1
, enc2
, enc3
, enc4
;
103 input
= this.replace(/[^A
-Za
-z0
-9\
+\
/\
=]/g
, "");
105 while (i
< input
.length
) {
107 enc1
= this._keyStr
.indexOf(input
.charAt(i
++));
108 enc2
= this._keyStr
.indexOf(input
.charAt(i
++));
109 enc3
= this._keyStr
.indexOf(input
.charAt(i
++));
110 enc4
= this._keyStr
.indexOf(input
.charAt(i
++));
112 chr1
= (enc1
<< 2) |
(enc2
>> 4);
113 chr2
= ((enc2
& 15) << 4) |
(enc3
>> 2);
114 chr3
= ((enc3
& 3) << 6) | enc4
;
116 output
= output
+ String
.fromCharCode(chr1
);
119 output
= output
+ String
.fromCharCode(chr2
);
122 output
= output
+ String
.fromCharCode(chr3
);
126 return output
._utf8_decode();;
129 // private method for UTF-8 encoding
130 String
.prototype._utf8_encode
= function () {
131 string
= this.replace(/\r\n/g
,"\n");
134 for (var n
= 0; n
< string
.length
; n
++) {
136 var c
= string
.charCodeAt(n
);
139 utftext
+= String
.fromCharCode(c
);
141 else if((c
> 127) && (c
< 2048)) {
142 utftext
+= String
.fromCharCode((c
>> 6) |
192);
143 utftext
+= String
.fromCharCode((c
& 63) |
128);
146 utftext
+= String
.fromCharCode((c
>> 12) |
224);
147 utftext
+= String
.fromCharCode(((c
>> 6) & 63) |
128);
148 utftext
+= String
.fromCharCode((c
& 63) |
128);
155 // private method for UTF-8 decoding
156 String
.prototype._utf8_decode
= function () {
161 while ( i
< this.length
) {
163 c
= this.charCodeAt(i
);
166 string
+= String
.fromCharCode(c
);
169 else if((c
> 191) && (c
< 224)) {
170 c2
= this.charCodeAt(i
+1);
171 string
+= String
.fromCharCode(((c
& 31) << 6) |
(c2
& 63));
175 c2
= this.charCodeAt(i
+1);
176 c3
= this.charCodeAt(i
+2);
177 string
+= String
.fromCharCode(((c
& 15) << 12) |
((c2
& 63) << 6) |
(c3
& 63));
185 // JQuery Case Insensitive :icontains selector
186 $
.expr
[':'].icontains
= function(obj
, index
, meta
, stack
){
187 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;
191 // Extract anchor part (after #) from URL string
192 extractAnchor
: function(url
) {
193 var index
= url
.indexOf("#");
195 return url
.substring(index
+ 1);
200 delayEvent
: function(handler
, event
) {
201 if(this.delayEvent
.timeout
) {
202 clearTimeout(this.delayEvent
.timeout
);
204 this.delayEvent
.timeout
= setTimeout(function() {