Debian Codegraph @

plugins/ubuntu-plugin/imports/utils/QtCoreAPI.js

raw symbols SCIP
1 .pragma library
2
3 /************** Adds most of QString/QByteArray API to JS String *******************************/
4
5 function addMethod(object, method) {
6 if (typeof object[method.name] === 'undefined') {
7 Object.defineProperty(object, method.name, {
8 "value": method,
9 "enumerable": false
10 });
11 }
12 }
13
14 function at (idx) {
15 return (this [idx]);
16 }
17 addMethod (Array.prototype, at);
18 addMethod (String.prototype, at);
19
20
21 function first () {
22 return this [0];
23 }
24 addMethod (Array.prototype, first);
25 addMethod (String.prototype, first);
26
27
28 function last () {
29 return (this.length ? this [this.length -1] : undefined);
30 }
31 addMethod (Array.prototype, last);
32 addMethod (String.prototype, last);
33
34
35 function contains (value) {
36 return (this.indexOf (value) > -1);
37 }
38 addMethod (Array.prototype, contains);
39 addMethod (String.prototype, contains);
40
41
42 function size () {
43 return (this.length);
44 }
45 addMethod (Array.prototype, size);
46 addMethod (String.prototype, size);
47
48
49 function isEmpty () {
50 return (!this.length);
51 }
52 addMethod (Array.prototype, isEmpty);
53 addMethod (String.prototype, isEmpty);
54
55
56 function clear () {
57 this.splice (0, this.length);
58 }
59 addMethod (Array.prototype, clear);
60
61
62 function foreach (callback) {
63 for (var i = 0; i < this.length; callback (i, this [i]), i++);
64 }
65 addMethod (Array.prototype, foreach);
66
67
68 function append (value) {
69 this.push (value);
70 }
71 addMethod (Array.prototype, append);
72
73
74 function prepend (value) {
75 this.unshift (value);
76 }
77 addMethod (Array.prototype, prepend);
78
79
80 function removeAt (idx) {
81 this.splice (idx, 1);
82 }
83 addMethod (Array.prototype, removeAt);
84
85
86 function removeAll (value) {
87 var ret = 0;
88 var it = 0;
89 while (it < this.length) {
90 if (this [it] === (value)) {
91 this.splice (it, 1);
92 ret++;
93 }
94 else { it++; }
95 }
96 return ret;
97 }
98 addMethod (Array.prototype, removeAll);
99
100
101 function takeAt (idx) {
102 var ret = this [idx];
103 this.splice (idx, 1);
104 return ret;
105 }
106 addMethod (Array.prototype, takeAt);
107
108
109 function erase (idx) {
110 this [idx] = undefined;
111 }
112 addMethod (Array.prototype, erase);
113
114
115 function swap (idx1, idx2) {
116 var tmp = this [idx1];
117 this [idx1] = this [idx2];
118 this [idx2] = tmp;
119 }
120 addMethod (Array.prototype, swap);
121
122
123 function replace (idx, value) {
124 this [idx] = value;
125 }
126 addMethod (Array.prototype, replace);
127
128
129 function squeeze () {
130 var it = 0;
131 while (it < this.length) {
132 if (this [it] !== null && this [it] !== undefined) {
133 this.splice (it, 1);
134 }
135 else { it++; }
136 }
137 }
138 addMethod (Array.prototype, squeeze);
139
140
141 function append (str) {
142 return String (this + (str || ""));
143 }
144 addMethod (String.prototype, append);
145
146
147 function prepend (str) {
148 return String ((str || "") + this);
149 }
150 addMethod (String.prototype, prepend);
151
152
153 function trimmed () {
154 return String (this.replace (/\s*$/, '').replace (/^\s*/, ''));
155 }
156 addMethod (String.prototype, trimmed);
157
158
159 function remove (str) {
160 var ret = String (this);
161 while (ret.indexOf (str) > -1) {
162 ret = ret.replace (str, '');
163 }
164 return ret;
165 }
166 addMethod (String.prototype, remove);
167
168
169 function repeat (str, count) {
170 return (new Array (count +1).join (str));
171 }
172 addMethod (String, repeat);
173
174
175 function mid (pos, len) {
176 return this.substr (pos, len);
177 }
178 addMethod (String.prototype, mid);
179
180
181 function left (len) {
182 return (len < this.length ? this.substr (0, len) : this);
183 }
184 addMethod (String.prototype, left);
185
186
187 function right (len) {
188 return (len < this.length ? this.substr (this.length - len, len) : this);
189 }
190 addMethod (String.prototype, right);
191
192
193 function startsWith (str) {
194 return (str && this.indexOf (str) === 0);
195 }
196 addMethod (String.prototype, startsWith);
197
198
199 function endsWith (str) {
200 return (str && this.lastIndexOf (str) > -1 && this.lastIndexOf (str) === (this.length - str.length));
201 }
202 addMethod (String.prototype, endsWith);
203
204
205 function toBase64 () {
206 return Qt.atob (this);
207 }
208 addMethod (String.prototype, toBase64);
209
210
211 function fromBase64 (str) {
212 return Qt.btoa (str);
213 }
214 addMethod (String, fromBase64);