emissions-api-sdk 1.0.11 → 1.0.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +157 -0
- package/dist/Constants.js +4 -1
- package/dist/api/AuditLog.js +99 -0
- package/dist/api/EconomicActivity.js +24 -0
- package/dist/api/Factor.js +72 -1
- package/dist/api/PhysicalActivity.js +87 -0
- package/dist/api/RealEstate.js +23 -0
- package/dist/api/TypeRecommender.js +67 -2
- package/dist/coverage/clover.xml +154 -89
- package/dist/coverage/coverage-final.json +15 -9
- package/dist/coverage/lcov-report/index.html +21 -21
- package/dist/coverage/lcov-report/src/Client.ts.html +32 -32
- package/dist/coverage/lcov-report/src/Constants.ts.html +36 -27
- package/dist/coverage/lcov-report/src/api/AuditLog.ts.html +388 -0
- package/dist/coverage/lcov-report/src/api/Calculation.ts.html +1 -1
- package/dist/coverage/lcov-report/src/api/EconomicActivity.ts.html +77 -5
- package/dist/coverage/lcov-report/src/api/Factor.ts.html +216 -3
- package/dist/coverage/lcov-report/src/api/FactorSets.ts.html +1 -1
- package/dist/coverage/lcov-report/src/api/Fugitive.ts.html +1 -1
- package/dist/coverage/lcov-report/src/api/Location.ts.html +1 -1
- package/dist/coverage/lcov-report/src/api/Metadata.ts.html +1 -1
- package/dist/coverage/lcov-report/src/api/Mobile.ts.html +1 -1
- package/dist/coverage/lcov-report/src/api/PhysicalActivity.ts.html +361 -0
- package/dist/coverage/lcov-report/src/api/RealEstate.ts.html +74 -5
- package/dist/coverage/lcov-report/src/api/Stationary.ts.html +1 -1
- package/dist/coverage/lcov-report/src/api/TransportationAndDistribution.ts.html +1 -1
- package/dist/coverage/lcov-report/src/api/TypeRecommender.ts.html +199 -4
- package/dist/coverage/lcov-report/src/api/Usage.ts.html +1 -1
- package/dist/coverage/lcov-report/src/api/index.html +36 -6
- package/dist/coverage/lcov-report/src/index.html +7 -7
- package/dist/coverage/lcov-report/src/request.ts.html +5 -5
- package/dist/coverage/lcov-report/src/utils.ts.html +6 -6
- package/dist/coverage/lcov-report/test/index.html +1 -1
- package/dist/coverage/lcov-report/test/mocks/AttributionRequest.ts.html +151 -0
- package/dist/coverage/lcov-report/test/mocks/CommonRequest.ts.html +1 -1
- package/dist/coverage/lcov-report/test/mocks/EconomicActivityAttributionRequest.ts.html +148 -0
- package/dist/coverage/lcov-report/test/mocks/FactorRequest.ts.html +1 -1
- package/dist/coverage/lcov-report/test/mocks/GenericCalculationRequest.ts.html +1 -1
- package/dist/coverage/lcov-report/test/mocks/LocationRequest.ts.html +1 -1
- package/dist/coverage/lcov-report/test/mocks/PhysicalActivityEVICRequest.ts.html +148 -0
- package/dist/coverage/lcov-report/test/mocks/PhysicalActivityRequest.ts.html +151 -0
- package/dist/coverage/lcov-report/test/mocks/SearchRequest.ts.html +148 -4
- package/dist/coverage/lcov-report/test/mocks/index.html +64 -4
- package/dist/coverage/lcov-report/test/testUtils.ts.html +1 -1
- package/dist/coverage/lcov.info +254 -124
- package/dist/index.js +3 -1
- package/dist/interfaces/response/AuditLogResponse.js +2 -0
- package/dist/types/Constants.d.ts +3 -0
- package/dist/types/api/AuditLog.d.ts +37 -0
- package/dist/types/api/EconomicActivity.d.ts +24 -0
- package/dist/types/api/Factor.d.ts +72 -1
- package/dist/types/api/PhysicalActivity.d.ts +76 -0
- package/dist/types/api/RealEstate.d.ts +23 -0
- package/dist/types/api/TypeRecommender.d.ts +67 -2
- package/dist/types/index.d.ts +4 -0
- package/dist/types/interfaces/Api.d.ts +17 -1
- package/dist/types/interfaces/common.d.ts +48 -0
- package/dist/types/interfaces/response/AuditLogResponse.d.ts +40 -0
- package/dist/types/interfaces/response/TypeRecommenderResponse.d.ts +1 -0
- package/docs/_sources/authentication.rst.txt +26 -4
- package/docs/_sources/getting_started.rst.txt +538 -74
- package/docs/_sources/index.rst.txt +11 -0
- package/docs/_sources/reference.rst.txt +26 -0
- package/docs/_sources/troubleshooting.rst.txt +77 -12
- package/docs/_static/base-stemmer.js +476 -0
- package/docs/_static/english-stemmer.js +1066 -0
- package/docs/authentication.html +31 -5
- package/docs/client.html +3 -1
- package/docs/genindex.html +22 -2
- package/docs/getting_started.html +715 -82
- package/docs/index.html +35 -0
- package/docs/reference.html +412 -3
- package/docs/sdk.html +2 -0
- package/docs/search.html +2 -0
- package/docs/searchindex.js +1 -1
- package/docs/troubleshooting.html +75 -17
- package/package.json +7 -3
- package/sphinx-build/source/authentication.rst +26 -4
- package/sphinx-build/source/getting_started.rst +538 -74
- package/sphinx-build/source/index.rst +11 -0
- package/sphinx-build/source/reference.rst +26 -0
- package/sphinx-build/source/troubleshooting.rst +77 -12
- package/src/Constants.ts +3 -0
- package/src/api/AuditLog.ts +102 -0
- package/src/api/EconomicActivity.ts +24 -0
- package/src/api/Factor.ts +72 -1
- package/src/api/PhysicalActivity.ts +92 -0
- package/src/api/RealEstate.ts +23 -0
- package/src/api/TypeRecommender.ts +67 -2
- package/src/index.ts +7 -1
- package/src/interfaces/Api.ts +22 -6
- package/src/interfaces/common.ts +58 -0
- package/src/interfaces/response/AuditLogResponse.ts +47 -0
- package/src/interfaces/response/TypeRecommenderResponse.ts +2 -0
- package/test/apiTest.test.ts +59 -3
- package/test/auditLog.test.ts +216 -0
- package/test/mocks/AttributionRequest.ts +23 -0
- package/test/mocks/EconomicActivityAttributionRequest.ts +22 -0
- package/test/mocks/PhysicalActivityEVICRequest.ts +22 -0
- package/test/mocks/PhysicalActivityRequest.ts +23 -0
- package/test/mocks/SearchRequest.ts +48 -0
|
@@ -99,12 +99,61 @@ These errors occur when ``Client.getClient()`` is called with invalid or missing
|
|
|
99
99
|
|
|
100
100
|
----
|
|
101
101
|
|
|
102
|
+
4. Missing Client ID with PAT Token
|
|
103
|
+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
104
|
+
|
|
105
|
+
**Error Message:**
|
|
106
|
+
|
|
107
|
+
.. code-block:: text
|
|
108
|
+
|
|
109
|
+
Error: If patToken is provided, "clientId" must also be provided.
|
|
110
|
+
|
|
111
|
+
**Cause:** Personal Access Token (PAT) provided without client ID
|
|
112
|
+
|
|
113
|
+
**Solution:** Provide ``clientId`` parameter when using a PAT token
|
|
114
|
+
|
|
115
|
+
**Sample Function Call That Causes This Error:**
|
|
116
|
+
|
|
117
|
+
.. code-block:: typescript
|
|
118
|
+
|
|
119
|
+
await Client.getClient({
|
|
120
|
+
patToken: 'your-pat-token'
|
|
121
|
+
// Missing clientId parameter
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
----
|
|
125
|
+
|
|
126
|
+
5. Organization ID Provided with PAT Token
|
|
127
|
+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
128
|
+
|
|
129
|
+
**Error Message:**
|
|
130
|
+
|
|
131
|
+
.. code-block:: text
|
|
132
|
+
|
|
133
|
+
Error: orgId should not be provided when using patToken.
|
|
134
|
+
|
|
135
|
+
**Cause:** Organization ID should not be used with Personal Access Token authentication
|
|
136
|
+
|
|
137
|
+
**Solution:** Remove ``orgId`` parameter when using PAT token authentication
|
|
138
|
+
|
|
139
|
+
**Sample Function Call That Causes This Error:**
|
|
140
|
+
|
|
141
|
+
.. code-block:: typescript
|
|
142
|
+
|
|
143
|
+
await Client.getClient({
|
|
144
|
+
patToken: 'your-pat-token',
|
|
145
|
+
clientId: 'client123',
|
|
146
|
+
orgId: 'org456' // This should not be provided with PAT token
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
----
|
|
150
|
+
|
|
102
151
|
Authentication Errors (HTTP 401)
|
|
103
152
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
104
153
|
|
|
105
154
|
These errors occur when authentication credentials are invalid or expired.
|
|
106
155
|
|
|
107
|
-
|
|
156
|
+
6. Invalid API Key
|
|
108
157
|
^^^^^^^^^^^^^^^^^^
|
|
109
158
|
|
|
110
159
|
**Error Response:**
|
|
@@ -135,7 +184,7 @@ These errors occur when authentication credentials are invalid or expired.
|
|
|
135
184
|
|
|
136
185
|
----
|
|
137
186
|
|
|
138
|
-
|
|
187
|
+
7. Invalid Organization ID
|
|
139
188
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
140
189
|
|
|
141
190
|
**Error Response:**
|
|
@@ -166,7 +215,7 @@ These errors occur when authentication credentials are invalid or expired.
|
|
|
166
215
|
|
|
167
216
|
----
|
|
168
217
|
|
|
169
|
-
|
|
218
|
+
8. Invalid Client ID
|
|
170
219
|
^^^^^^^^^^^^^^^^^^^^^
|
|
171
220
|
|
|
172
221
|
**Error Response:**
|
|
@@ -197,7 +246,7 @@ These errors occur when authentication credentials are invalid or expired.
|
|
|
197
246
|
|
|
198
247
|
----
|
|
199
248
|
|
|
200
|
-
|
|
249
|
+
9. Empty Token Response
|
|
201
250
|
^^^^^^^^^^^^^^^^^^^^^^^^
|
|
202
251
|
|
|
203
252
|
**Error Message:**
|
|
@@ -233,8 +282,8 @@ These errors occur when authentication credentials are invalid or expired.
|
|
|
233
282
|
|
|
234
283
|
----
|
|
235
284
|
|
|
236
|
-
|
|
237
|
-
|
|
285
|
+
10. Missing Expiry Field in Token
|
|
286
|
+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
238
287
|
|
|
239
288
|
**Error Message:**
|
|
240
289
|
|
|
@@ -341,6 +390,14 @@ Error Summary Table
|
|
|
341
390
|
- ``If apiKey is provided , "clientId" and "OrgId" must also be provided.``
|
|
342
391
|
- N/A
|
|
343
392
|
- Provide all three parameters
|
|
393
|
+
* - Configuration
|
|
394
|
+
- ``If patToken is provided, "clientId" must also be provided.``
|
|
395
|
+
- N/A
|
|
396
|
+
- Provide clientId with PAT token
|
|
397
|
+
* - Configuration
|
|
398
|
+
- ``orgId should not be provided when using patToken.``
|
|
399
|
+
- N/A
|
|
400
|
+
- Remove orgId when using PAT token
|
|
344
401
|
* - Authentication
|
|
345
402
|
- ``Cannot pass the security checks...``
|
|
346
403
|
- 401
|
|
@@ -369,14 +426,22 @@ Required Configuration Parameters
|
|
|
369
426
|
|
|
370
427
|
When calling ``Client.getClient()``, the following parameters are required based on authentication method:
|
|
371
428
|
|
|
372
|
-
|
|
373
|
-
|
|
429
|
+
Personal Access Token (PAT) Authentication (Recommended)
|
|
430
|
+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
431
|
+
|
|
432
|
+
- ``patToken`` - Your Personal Access Token
|
|
433
|
+
- ``clientId`` - Your client ID
|
|
434
|
+
|
|
435
|
+
**Note:** Do not provide ``orgId`` when using PAT token authentication.
|
|
436
|
+
|
|
437
|
+
API Key Authentication
|
|
438
|
+
~~~~~~~~~~~~~~~~~~~~~~
|
|
374
439
|
|
|
375
440
|
- ``apiKey`` - Your IBM Cloud API key
|
|
376
441
|
- ``clientId`` - Your client ID
|
|
377
442
|
- ``orgId`` - Your organization ID
|
|
378
|
-
- ``host`` - API host URL
|
|
379
|
-
- ``authUrl`` - Authentication URL
|
|
443
|
+
- ``host`` - API host URL (optional, uses default if not provided)
|
|
444
|
+
- ``authUrl`` - Authentication URL (optional, uses default if not provided)
|
|
380
445
|
|
|
381
446
|
Token Authentication
|
|
382
447
|
~~~~~~~~~~~~~~~~~~~~
|
|
@@ -479,8 +544,8 @@ For issues not covered in this guide:
|
|
|
479
544
|
|
|
480
545
|
----
|
|
481
546
|
|
|
482
|
-
**Last Updated:**
|
|
547
|
+
**Last Updated:** 2026-05-31
|
|
483
548
|
|
|
484
|
-
**SDK Version:** 1.0.
|
|
549
|
+
**SDK Version:** 1.0.2
|
|
485
550
|
|
|
486
551
|
**Coverage:** SDK initialization, client instance, and authentication errors
|
|
@@ -0,0 +1,476 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
|
|
3
|
+
/**@constructor*/
|
|
4
|
+
BaseStemmer = function() {
|
|
5
|
+
/** @protected */
|
|
6
|
+
this.current = '';
|
|
7
|
+
this.cursor = 0;
|
|
8
|
+
this.limit = 0;
|
|
9
|
+
this.limit_backward = 0;
|
|
10
|
+
this.bra = 0;
|
|
11
|
+
this.ket = 0;
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* @param {string} value
|
|
15
|
+
*/
|
|
16
|
+
this.setCurrent = function(value) {
|
|
17
|
+
this.current = value;
|
|
18
|
+
this.cursor = 0;
|
|
19
|
+
this.limit = this.current.length;
|
|
20
|
+
this.limit_backward = 0;
|
|
21
|
+
this.bra = this.cursor;
|
|
22
|
+
this.ket = this.limit;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* @return {string}
|
|
27
|
+
*/
|
|
28
|
+
this.getCurrent = function() {
|
|
29
|
+
return this.current;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* @param {BaseStemmer} other
|
|
34
|
+
*/
|
|
35
|
+
this.copy_from = function(other) {
|
|
36
|
+
/** @protected */
|
|
37
|
+
this.current = other.current;
|
|
38
|
+
this.cursor = other.cursor;
|
|
39
|
+
this.limit = other.limit;
|
|
40
|
+
this.limit_backward = other.limit_backward;
|
|
41
|
+
this.bra = other.bra;
|
|
42
|
+
this.ket = other.ket;
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* @param {number[]} s
|
|
47
|
+
* @param {number} min
|
|
48
|
+
* @param {number} max
|
|
49
|
+
* @return {boolean}
|
|
50
|
+
*/
|
|
51
|
+
this.in_grouping = function(s, min, max) {
|
|
52
|
+
/** @protected */
|
|
53
|
+
if (this.cursor >= this.limit) return false;
|
|
54
|
+
var ch = this.current.charCodeAt(this.cursor);
|
|
55
|
+
if (ch > max || ch < min) return false;
|
|
56
|
+
ch -= min;
|
|
57
|
+
if ((s[ch >>> 3] & (0x1 << (ch & 0x7))) == 0) return false;
|
|
58
|
+
this.cursor++;
|
|
59
|
+
return true;
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* @param {number[]} s
|
|
64
|
+
* @param {number} min
|
|
65
|
+
* @param {number} max
|
|
66
|
+
* @return {boolean}
|
|
67
|
+
*/
|
|
68
|
+
this.go_in_grouping = function(s, min, max) {
|
|
69
|
+
/** @protected */
|
|
70
|
+
while (this.cursor < this.limit) {
|
|
71
|
+
var ch = this.current.charCodeAt(this.cursor);
|
|
72
|
+
if (ch > max || ch < min)
|
|
73
|
+
return true;
|
|
74
|
+
ch -= min;
|
|
75
|
+
if ((s[ch >>> 3] & (0x1 << (ch & 0x7))) == 0)
|
|
76
|
+
return true;
|
|
77
|
+
this.cursor++;
|
|
78
|
+
}
|
|
79
|
+
return false;
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* @param {number[]} s
|
|
84
|
+
* @param {number} min
|
|
85
|
+
* @param {number} max
|
|
86
|
+
* @return {boolean}
|
|
87
|
+
*/
|
|
88
|
+
this.in_grouping_b = function(s, min, max) {
|
|
89
|
+
/** @protected */
|
|
90
|
+
if (this.cursor <= this.limit_backward) return false;
|
|
91
|
+
var ch = this.current.charCodeAt(this.cursor - 1);
|
|
92
|
+
if (ch > max || ch < min) return false;
|
|
93
|
+
ch -= min;
|
|
94
|
+
if ((s[ch >>> 3] & (0x1 << (ch & 0x7))) == 0) return false;
|
|
95
|
+
this.cursor--;
|
|
96
|
+
return true;
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* @param {number[]} s
|
|
101
|
+
* @param {number} min
|
|
102
|
+
* @param {number} max
|
|
103
|
+
* @return {boolean}
|
|
104
|
+
*/
|
|
105
|
+
this.go_in_grouping_b = function(s, min, max) {
|
|
106
|
+
/** @protected */
|
|
107
|
+
while (this.cursor > this.limit_backward) {
|
|
108
|
+
var ch = this.current.charCodeAt(this.cursor - 1);
|
|
109
|
+
if (ch > max || ch < min) return true;
|
|
110
|
+
ch -= min;
|
|
111
|
+
if ((s[ch >>> 3] & (0x1 << (ch & 0x7))) == 0) return true;
|
|
112
|
+
this.cursor--;
|
|
113
|
+
}
|
|
114
|
+
return false;
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* @param {number[]} s
|
|
119
|
+
* @param {number} min
|
|
120
|
+
* @param {number} max
|
|
121
|
+
* @return {boolean}
|
|
122
|
+
*/
|
|
123
|
+
this.out_grouping = function(s, min, max) {
|
|
124
|
+
/** @protected */
|
|
125
|
+
if (this.cursor >= this.limit) return false;
|
|
126
|
+
var ch = this.current.charCodeAt(this.cursor);
|
|
127
|
+
if (ch > max || ch < min) {
|
|
128
|
+
this.cursor++;
|
|
129
|
+
return true;
|
|
130
|
+
}
|
|
131
|
+
ch -= min;
|
|
132
|
+
if ((s[ch >>> 3] & (0X1 << (ch & 0x7))) == 0) {
|
|
133
|
+
this.cursor++;
|
|
134
|
+
return true;
|
|
135
|
+
}
|
|
136
|
+
return false;
|
|
137
|
+
};
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* @param {number[]} s
|
|
141
|
+
* @param {number} min
|
|
142
|
+
* @param {number} max
|
|
143
|
+
* @return {boolean}
|
|
144
|
+
*/
|
|
145
|
+
this.go_out_grouping = function(s, min, max) {
|
|
146
|
+
/** @protected */
|
|
147
|
+
while (this.cursor < this.limit) {
|
|
148
|
+
var ch = this.current.charCodeAt(this.cursor);
|
|
149
|
+
if (ch <= max && ch >= min) {
|
|
150
|
+
ch -= min;
|
|
151
|
+
if ((s[ch >>> 3] & (0X1 << (ch & 0x7))) != 0) {
|
|
152
|
+
return true;
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
this.cursor++;
|
|
156
|
+
}
|
|
157
|
+
return false;
|
|
158
|
+
};
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* @param {number[]} s
|
|
162
|
+
* @param {number} min
|
|
163
|
+
* @param {number} max
|
|
164
|
+
* @return {boolean}
|
|
165
|
+
*/
|
|
166
|
+
this.out_grouping_b = function(s, min, max) {
|
|
167
|
+
/** @protected */
|
|
168
|
+
if (this.cursor <= this.limit_backward) return false;
|
|
169
|
+
var ch = this.current.charCodeAt(this.cursor - 1);
|
|
170
|
+
if (ch > max || ch < min) {
|
|
171
|
+
this.cursor--;
|
|
172
|
+
return true;
|
|
173
|
+
}
|
|
174
|
+
ch -= min;
|
|
175
|
+
if ((s[ch >>> 3] & (0x1 << (ch & 0x7))) == 0) {
|
|
176
|
+
this.cursor--;
|
|
177
|
+
return true;
|
|
178
|
+
}
|
|
179
|
+
return false;
|
|
180
|
+
};
|
|
181
|
+
|
|
182
|
+
/**
|
|
183
|
+
* @param {number[]} s
|
|
184
|
+
* @param {number} min
|
|
185
|
+
* @param {number} max
|
|
186
|
+
* @return {boolean}
|
|
187
|
+
*/
|
|
188
|
+
this.go_out_grouping_b = function(s, min, max) {
|
|
189
|
+
/** @protected */
|
|
190
|
+
while (this.cursor > this.limit_backward) {
|
|
191
|
+
var ch = this.current.charCodeAt(this.cursor - 1);
|
|
192
|
+
if (ch <= max && ch >= min) {
|
|
193
|
+
ch -= min;
|
|
194
|
+
if ((s[ch >>> 3] & (0x1 << (ch & 0x7))) != 0) {
|
|
195
|
+
return true;
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
this.cursor--;
|
|
199
|
+
}
|
|
200
|
+
return false;
|
|
201
|
+
};
|
|
202
|
+
|
|
203
|
+
/**
|
|
204
|
+
* @param {string} s
|
|
205
|
+
* @return {boolean}
|
|
206
|
+
*/
|
|
207
|
+
this.eq_s = function(s)
|
|
208
|
+
{
|
|
209
|
+
/** @protected */
|
|
210
|
+
if (this.limit - this.cursor < s.length) return false;
|
|
211
|
+
if (this.current.slice(this.cursor, this.cursor + s.length) != s)
|
|
212
|
+
{
|
|
213
|
+
return false;
|
|
214
|
+
}
|
|
215
|
+
this.cursor += s.length;
|
|
216
|
+
return true;
|
|
217
|
+
};
|
|
218
|
+
|
|
219
|
+
/**
|
|
220
|
+
* @param {string} s
|
|
221
|
+
* @return {boolean}
|
|
222
|
+
*/
|
|
223
|
+
this.eq_s_b = function(s)
|
|
224
|
+
{
|
|
225
|
+
/** @protected */
|
|
226
|
+
if (this.cursor - this.limit_backward < s.length) return false;
|
|
227
|
+
if (this.current.slice(this.cursor - s.length, this.cursor) != s)
|
|
228
|
+
{
|
|
229
|
+
return false;
|
|
230
|
+
}
|
|
231
|
+
this.cursor -= s.length;
|
|
232
|
+
return true;
|
|
233
|
+
};
|
|
234
|
+
|
|
235
|
+
/**
|
|
236
|
+
* @param {Among[]} v
|
|
237
|
+
* @return {number}
|
|
238
|
+
*/
|
|
239
|
+
this.find_among = function(v)
|
|
240
|
+
{
|
|
241
|
+
/** @protected */
|
|
242
|
+
var i = 0;
|
|
243
|
+
var j = v.length;
|
|
244
|
+
|
|
245
|
+
var c = this.cursor;
|
|
246
|
+
var l = this.limit;
|
|
247
|
+
|
|
248
|
+
var common_i = 0;
|
|
249
|
+
var common_j = 0;
|
|
250
|
+
|
|
251
|
+
var first_key_inspected = false;
|
|
252
|
+
|
|
253
|
+
while (true)
|
|
254
|
+
{
|
|
255
|
+
var k = i + ((j - i) >>> 1);
|
|
256
|
+
var diff = 0;
|
|
257
|
+
var common = common_i < common_j ? common_i : common_j; // smaller
|
|
258
|
+
// w[0]: string, w[1]: substring_i, w[2]: result, w[3]: function (optional)
|
|
259
|
+
var w = v[k];
|
|
260
|
+
var i2;
|
|
261
|
+
for (i2 = common; i2 < w[0].length; i2++)
|
|
262
|
+
{
|
|
263
|
+
if (c + common == l)
|
|
264
|
+
{
|
|
265
|
+
diff = -1;
|
|
266
|
+
break;
|
|
267
|
+
}
|
|
268
|
+
diff = this.current.charCodeAt(c + common) - w[0].charCodeAt(i2);
|
|
269
|
+
if (diff != 0) break;
|
|
270
|
+
common++;
|
|
271
|
+
}
|
|
272
|
+
if (diff < 0)
|
|
273
|
+
{
|
|
274
|
+
j = k;
|
|
275
|
+
common_j = common;
|
|
276
|
+
}
|
|
277
|
+
else
|
|
278
|
+
{
|
|
279
|
+
i = k;
|
|
280
|
+
common_i = common;
|
|
281
|
+
}
|
|
282
|
+
if (j - i <= 1)
|
|
283
|
+
{
|
|
284
|
+
if (i > 0) break; // v->s has been inspected
|
|
285
|
+
if (j == i) break; // only one item in v
|
|
286
|
+
|
|
287
|
+
// - but now we need to go round once more to get
|
|
288
|
+
// v->s inspected. This looks messy, but is actually
|
|
289
|
+
// the optimal approach.
|
|
290
|
+
|
|
291
|
+
if (first_key_inspected) break;
|
|
292
|
+
first_key_inspected = true;
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
do {
|
|
296
|
+
var w = v[i];
|
|
297
|
+
if (common_i >= w[0].length)
|
|
298
|
+
{
|
|
299
|
+
this.cursor = c + w[0].length;
|
|
300
|
+
if (w.length < 4) return w[2];
|
|
301
|
+
var res = w[3](this);
|
|
302
|
+
this.cursor = c + w[0].length;
|
|
303
|
+
if (res) return w[2];
|
|
304
|
+
}
|
|
305
|
+
i = w[1];
|
|
306
|
+
} while (i >= 0);
|
|
307
|
+
return 0;
|
|
308
|
+
};
|
|
309
|
+
|
|
310
|
+
// find_among_b is for backwards processing. Same comments apply
|
|
311
|
+
/**
|
|
312
|
+
* @param {Among[]} v
|
|
313
|
+
* @return {number}
|
|
314
|
+
*/
|
|
315
|
+
this.find_among_b = function(v)
|
|
316
|
+
{
|
|
317
|
+
/** @protected */
|
|
318
|
+
var i = 0;
|
|
319
|
+
var j = v.length
|
|
320
|
+
|
|
321
|
+
var c = this.cursor;
|
|
322
|
+
var lb = this.limit_backward;
|
|
323
|
+
|
|
324
|
+
var common_i = 0;
|
|
325
|
+
var common_j = 0;
|
|
326
|
+
|
|
327
|
+
var first_key_inspected = false;
|
|
328
|
+
|
|
329
|
+
while (true)
|
|
330
|
+
{
|
|
331
|
+
var k = i + ((j - i) >> 1);
|
|
332
|
+
var diff = 0;
|
|
333
|
+
var common = common_i < common_j ? common_i : common_j;
|
|
334
|
+
var w = v[k];
|
|
335
|
+
var i2;
|
|
336
|
+
for (i2 = w[0].length - 1 - common; i2 >= 0; i2--)
|
|
337
|
+
{
|
|
338
|
+
if (c - common == lb)
|
|
339
|
+
{
|
|
340
|
+
diff = -1;
|
|
341
|
+
break;
|
|
342
|
+
}
|
|
343
|
+
diff = this.current.charCodeAt(c - 1 - common) - w[0].charCodeAt(i2);
|
|
344
|
+
if (diff != 0) break;
|
|
345
|
+
common++;
|
|
346
|
+
}
|
|
347
|
+
if (diff < 0)
|
|
348
|
+
{
|
|
349
|
+
j = k;
|
|
350
|
+
common_j = common;
|
|
351
|
+
}
|
|
352
|
+
else
|
|
353
|
+
{
|
|
354
|
+
i = k;
|
|
355
|
+
common_i = common;
|
|
356
|
+
}
|
|
357
|
+
if (j - i <= 1)
|
|
358
|
+
{
|
|
359
|
+
if (i > 0) break;
|
|
360
|
+
if (j == i) break;
|
|
361
|
+
if (first_key_inspected) break;
|
|
362
|
+
first_key_inspected = true;
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
do {
|
|
366
|
+
var w = v[i];
|
|
367
|
+
if (common_i >= w[0].length)
|
|
368
|
+
{
|
|
369
|
+
this.cursor = c - w[0].length;
|
|
370
|
+
if (w.length < 4) return w[2];
|
|
371
|
+
var res = w[3](this);
|
|
372
|
+
this.cursor = c - w[0].length;
|
|
373
|
+
if (res) return w[2];
|
|
374
|
+
}
|
|
375
|
+
i = w[1];
|
|
376
|
+
} while (i >= 0);
|
|
377
|
+
return 0;
|
|
378
|
+
};
|
|
379
|
+
|
|
380
|
+
/* to replace chars between c_bra and c_ket in this.current by the
|
|
381
|
+
* chars in s.
|
|
382
|
+
*/
|
|
383
|
+
/**
|
|
384
|
+
* @param {number} c_bra
|
|
385
|
+
* @param {number} c_ket
|
|
386
|
+
* @param {string} s
|
|
387
|
+
* @return {number}
|
|
388
|
+
*/
|
|
389
|
+
this.replace_s = function(c_bra, c_ket, s)
|
|
390
|
+
{
|
|
391
|
+
/** @protected */
|
|
392
|
+
var adjustment = s.length - (c_ket - c_bra);
|
|
393
|
+
this.current = this.current.slice(0, c_bra) + s + this.current.slice(c_ket);
|
|
394
|
+
this.limit += adjustment;
|
|
395
|
+
if (this.cursor >= c_ket) this.cursor += adjustment;
|
|
396
|
+
else if (this.cursor > c_bra) this.cursor = c_bra;
|
|
397
|
+
return adjustment;
|
|
398
|
+
};
|
|
399
|
+
|
|
400
|
+
/**
|
|
401
|
+
* @return {boolean}
|
|
402
|
+
*/
|
|
403
|
+
this.slice_check = function()
|
|
404
|
+
{
|
|
405
|
+
/** @protected */
|
|
406
|
+
if (this.bra < 0 ||
|
|
407
|
+
this.bra > this.ket ||
|
|
408
|
+
this.ket > this.limit ||
|
|
409
|
+
this.limit > this.current.length)
|
|
410
|
+
{
|
|
411
|
+
return false;
|
|
412
|
+
}
|
|
413
|
+
return true;
|
|
414
|
+
};
|
|
415
|
+
|
|
416
|
+
/**
|
|
417
|
+
* @param {number} c_bra
|
|
418
|
+
* @return {boolean}
|
|
419
|
+
*/
|
|
420
|
+
this.slice_from = function(s)
|
|
421
|
+
{
|
|
422
|
+
/** @protected */
|
|
423
|
+
var result = false;
|
|
424
|
+
if (this.slice_check())
|
|
425
|
+
{
|
|
426
|
+
this.replace_s(this.bra, this.ket, s);
|
|
427
|
+
result = true;
|
|
428
|
+
}
|
|
429
|
+
return result;
|
|
430
|
+
};
|
|
431
|
+
|
|
432
|
+
/**
|
|
433
|
+
* @return {boolean}
|
|
434
|
+
*/
|
|
435
|
+
this.slice_del = function()
|
|
436
|
+
{
|
|
437
|
+
/** @protected */
|
|
438
|
+
return this.slice_from("");
|
|
439
|
+
};
|
|
440
|
+
|
|
441
|
+
/**
|
|
442
|
+
* @param {number} c_bra
|
|
443
|
+
* @param {number} c_ket
|
|
444
|
+
* @param {string} s
|
|
445
|
+
*/
|
|
446
|
+
this.insert = function(c_bra, c_ket, s)
|
|
447
|
+
{
|
|
448
|
+
/** @protected */
|
|
449
|
+
var adjustment = this.replace_s(c_bra, c_ket, s);
|
|
450
|
+
if (c_bra <= this.bra) this.bra += adjustment;
|
|
451
|
+
if (c_bra <= this.ket) this.ket += adjustment;
|
|
452
|
+
};
|
|
453
|
+
|
|
454
|
+
/**
|
|
455
|
+
* @return {string}
|
|
456
|
+
*/
|
|
457
|
+
this.slice_to = function()
|
|
458
|
+
{
|
|
459
|
+
/** @protected */
|
|
460
|
+
var result = '';
|
|
461
|
+
if (this.slice_check())
|
|
462
|
+
{
|
|
463
|
+
result = this.current.slice(this.bra, this.ket);
|
|
464
|
+
}
|
|
465
|
+
return result;
|
|
466
|
+
};
|
|
467
|
+
|
|
468
|
+
/**
|
|
469
|
+
* @return {string}
|
|
470
|
+
*/
|
|
471
|
+
this.assign_to = function()
|
|
472
|
+
{
|
|
473
|
+
/** @protected */
|
|
474
|
+
return this.current.slice(0, this.limit);
|
|
475
|
+
};
|
|
476
|
+
};
|