forked from angular/angular
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprotoc-gen-dart
More file actions
executable file
·5015 lines (4910 loc) · 196 KB
/
protoc-gen-dart
File metadata and controls
executable file
·5015 lines (4910 loc) · 196 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env dart
// Compiled https://github.com/dart-lang/dart-protoc-plugin/releases, v0.5.0
import "dart:convert";
import "dart:typed_data";
import "dart:math";
import "dart:math" as _A;
import "dart:collection";
import "dart:async";
import "dart:io";
import "dart:io" as _B;
class CryptoUtils {
static String bytesToBase64_A(List<int> bytes, {bool urlSafe: false, bool addLineSeparator: false}) {
return _CryptoUtils_A.bytesToBase64_B(bytes, urlSafe, addLineSeparator);
}
}
const Base64Codec BASE64 = const Base64Codec();
const List<int> _decodeTable_A = const[-2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -1, -2, -2, -1, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, 62, -2, 62, -2, 63, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, -2, -2, -2, 0, -2, -2, -2, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, -2, -2, -2, -2, 63, -2, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2];
const String _encodeTableUrlSafe_A = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_";
const String _encodeTable_A = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
const int _LINE_LENGTH = 76;
const int _CR_A = 13;
const int _LF_A = 10;
const List<int> _PAD_BYTES = const[61];
const List<int> _ENCODED_PAD_BYTES = const[37, 51, 68];
const String _PAD = "=";
const String _ENCODED_PAD = "%3D";
class Base64Codec extends Codec<List<int>, String> {
final bool _urlSafe;
final bool _addLineSeparator;
final bool _encodePaddingCharacter;
const Base64Codec({bool urlSafe: false, bool addLineSeparator: false, bool encodePaddingCharacter: false}) : _urlSafe = urlSafe, _addLineSeparator = addLineSeparator, _encodePaddingCharacter = encodePaddingCharacter;
String get name => "base64";
String encode(List<int> bytes, {bool urlSafe, bool addLineSeparator, bool encodePaddingCharacter}) {
if (urlSafe == null) urlSafe = _urlSafe;
if (addLineSeparator == null) addLineSeparator = _addLineSeparator;
if (encodePaddingCharacter == null) {
encodePaddingCharacter = _encodePaddingCharacter;
}
return new Base64Encoder(urlSafe: urlSafe, addLineSeparator: addLineSeparator, encodePaddingCharacter: encodePaddingCharacter).convert(bytes);
}
Base64Encoder get encoder => new Base64Encoder(urlSafe: _urlSafe, addLineSeparator: _addLineSeparator, encodePaddingCharacter: _encodePaddingCharacter);
Base64Decoder get decoder => new Base64Decoder();
}
class Base64Encoder extends Converter<List<int>, String> {
final bool _urlSafe;
final bool _addLineSeparator;
final bool _encodePaddingCharacter;
final List<int> _pad;
const Base64Encoder({bool urlSafe: false, bool addLineSeparator: false, bool encodePaddingCharacter: false}) : _urlSafe = urlSafe, _addLineSeparator = addLineSeparator, _encodePaddingCharacter = encodePaddingCharacter, _pad = encodePaddingCharacter == true ? _ENCODED_PAD_BYTES : _PAD_BYTES;
String convert(List<int> bytes, [int start_A = 0, int end_A]) {
int bytes_length = bytes.length;
RangeError.checkValidRange(start_A, end_A, bytes_length);
if (end_A == null) end_A = bytes_length;
int length_A = end_A - start_A;
if (length_A == 0) {
return "";
}
final String lookup_A = _urlSafe ? _encodeTableUrlSafe_A : _encodeTable_A;
final int remainderLength = length_A.remainder(3);
final int chunkLength = length_A - remainderLength;
int baseOutputLength = ((length_A ~/ 3) * 4);
int remainderOutputLength;
if (_encodePaddingCharacter) {
remainderOutputLength = ((remainderLength > 0) ? 6 : 0);
} else {
remainderOutputLength = ((remainderLength > 0) ? 4 : 0);
}
int outputLength = baseOutputLength + remainderOutputLength;
if (_addLineSeparator) {
outputLength += ((outputLength - 1) ~/ _LINE_LENGTH) << 1;
}
List<int> out = new List<int>(outputLength);
int j = 0, i = start_A, c = 0;
while (i < chunkLength) {
int x_A = ((bytes[i++] << 16) & 0x00FFFFFF) | ((bytes[i++] << 8) & 0x00FFFFFF) | bytes[i++];
out[j++] = lookup_A.codeUnitAt(x_A >> 18);
out[j++] = lookup_A.codeUnitAt((x_A >> 12) & 0x3F);
out[j++] = lookup_A.codeUnitAt((x_A >> 6) & 0x3F);
out[j++] = lookup_A.codeUnitAt(x_A & 0x3F);
if (_addLineSeparator && ++c == 19 && j < outputLength - 2) {
out[j++] = _CR_A;
out[j++] = _LF_A;
c = 0;
}
}
if (remainderLength == 1) {
int x_A = bytes[i];
out[j++] = lookup_A.codeUnitAt(x_A >> 2);
out[j++] = lookup_A.codeUnitAt((x_A << 4) & 0x3F);
out.setRange(j, j + _pad.length, _pad);
out.setRange(j + _pad.length, j + 2 * _pad.length, _pad);
} else if (remainderLength == 2) {
int x_A = bytes[i];
int y_A = bytes[i + 1];
out[j++] = lookup_A.codeUnitAt(x_A >> 2);
out[j++] = lookup_A.codeUnitAt(((x_A << 4) | (y_A >> 4)) & 0x3F);
out[j++] = lookup_A.codeUnitAt((y_A << 2) & 0x3F);
out.setRange(j, j + _pad.length, _pad);
}
return new String.fromCharCodes(out);
}
_Base64EncoderSink startChunkedConversion(Sink<String> sink_A) {
StringConversionSink stringSink;
if (sink_A is StringConversionSink) {
stringSink = sink_A;
} else {
stringSink = new StringConversionSink.from(sink_A);
}
return new _Base64EncoderSink(stringSink, _urlSafe, _addLineSeparator);
}
}
class _Base64EncoderSink extends ChunkedConversionSink<List<int>> {
final Base64Encoder _encoder;
final ChunkedConversionSink<String> _outSink;
final List<int> _buffer_A = new List<int>();
int _bufferCount = 0;
_Base64EncoderSink(this._outSink, urlSafe, addLineSeparator) : _encoder = new Base64Encoder(urlSafe: urlSafe, addLineSeparator: addLineSeparator);
void add(List<int> chunk) {
var nextBufferCount = (chunk.length + _bufferCount) % 3;
int decodableLength = _bufferCount + chunk.length - nextBufferCount;
if (_bufferCount + chunk.length > _buffer_A.length) {
_buffer_A.replaceRange(_bufferCount, _buffer_A.length, chunk.sublist(0, _buffer_A.length - _bufferCount));
_buffer_A.addAll(chunk.sublist(_buffer_A.length - _bufferCount));
} else {
_buffer_A.replaceRange(_bufferCount, _bufferCount + chunk.length, chunk);
}
_outSink.add(_encoder.convert(_buffer_A, 0, decodableLength));
_buffer_A.removeRange(0, decodableLength);
_bufferCount = nextBufferCount;
}
void close() {
if (_bufferCount > 0) {
_outSink.add(_encoder.convert(_buffer_A.sublist(0, _bufferCount)));
}
_outSink.close();
}
}
class Base64Decoder extends Converter<String, List<int>> {
const Base64Decoder();
List<int> convert(String input_A) {
int length_A = input_A.length;
if (length_A == 0) {
return new Uint8List(0);
}
int normalLength = 0;
int i = 0;
while (i < length_A) {
int codeUnit = input_A.codeUnitAt(i);
int c = _decodeTable_A[codeUnit];
if (c == -2) {
if (codeUnit == _ENCODED_PAD_BYTES[0] && i < length_A - 2 && input_A.codeUnitAt(i + 1) == _ENCODED_PAD_BYTES[1] && input_A.codeUnitAt(i + 2) == _ENCODED_PAD_BYTES[2]) {
normalLength++;
i += 2;
} else {
throw new FormatException('Invalid character', input_A, i);
}
}
if (c >= 0) normalLength++;
i++;
}
if (normalLength % 4 != 0) {
throw new FormatException('''Size of Base 64 characters in Input
must be a multiple of 4''', input_A, normalLength);
}
int padLength = 0;
i = length_A - 1;
while (i >= 0) {
int currentCodeUnit = input_A.codeUnitAt(i);
if (currentCodeUnit == _ENCODED_PAD_BYTES[2] && i >= 2 && input_A.codeUnitAt(i - 1) == _ENCODED_PAD_BYTES[1] && input_A.codeUnitAt(i - 2) == _ENCODED_PAD_BYTES[0]) {
padLength++;
i -= 2;
} else if (_decodeTable_A[currentCodeUnit] > 0) {
break;
} else if (currentCodeUnit == _PAD_BYTES[0]) {
padLength++;
}
i--;
}
int outputLength = ((normalLength * 6) >> 3) - padLength;
List<int> out = new Uint8List(outputLength);
for (int i = 0, o = 0; o < outputLength;) {
int x_A = 0;
for (int j = 4; j > 0;) {
int c = _decodeTable_A[input_A.codeUnitAt(i++)];
if (c >= 0) {
x_A = ((x_A << 6) & 0x00FFFFFF) | c;
j--;
}
}
out[o++] = x_A >> 16;
if (o < outputLength) {
out[o++] = (x_A >> 8) & 0xFF;
if (o < outputLength) out[o++] = x_A & 0xFF;
}
}
return out;
}
_Base64DecoderSink startChunkedConversion(Sink<List<int>> sink_A) {
if (sink_A is! ByteConversionSink) {
sink_A = new ByteConversionSink.from(sink_A);
}
return new _Base64DecoderSink(sink_A);
}
}
class _Base64DecoderSink extends ChunkedConversionSink<String> {
final Base64Decoder _decoder_A = new Base64Decoder();
final ChunkedConversionSink<List<int>> _outSink;
String _unconverted = "";
_Base64DecoderSink(this._outSink);
void add(String chunk) {
if (chunk.isEmpty) return;
if (_unconverted.isNotEmpty) {
chunk = _unconverted + chunk;
}
chunk = chunk.replaceAll(_ENCODED_PAD, _PAD);
int decodableLength = chunk.length;
if (chunk.length > 3 && chunk.contains(_ENCODED_PAD[0], chunk.length - 2)) {
decodableLength = chunk.lastIndexOf(_ENCODED_PAD[0]);
}
decodableLength -= decodableLength % 4;
_unconverted = chunk.substring(decodableLength);
if (decodableLength > 0) {
_outSink.add(_decoder_A.convert(chunk.substring(0, decodableLength)));
}
}
void close() {
if (_unconverted.isNotEmpty) {
_outSink.add(_decoder_A.convert(_unconverted));
}
_outSink.close();
}
}
abstract class _CryptoUtils_A {
static String bytesToBase64_B(List<int> bytes, [bool urlSafe = false, bool addLineSeparator = false]) {
return BASE64.encode(bytes, urlSafe: urlSafe, addLineSeparator: addLineSeparator);
}
}
class Dart_options {
static final Extension defaultMixin = new Extension('FileOptions', 'defaultMixin', 96128839, PbFieldType.OS);
static final Extension mixin = new Extension('MessageOptions', 'mixin', 96128839, PbFieldType.OS);
static void registerAllExtensions(ExtensionRegistry registry) {
registry.add(defaultMixin);
registry.add(mixin);
}
}
class Int32 implements IntX {
static int _validateRadix(int radix) {
if (2 <= radix && radix <= 36) return radix;
throw new RangeError.range(radix, 2, 36, 'radix');
}
}
class Int64 implements IntX {
final int _l;
final int _m;
final int _h_A;
static const int _BITS = 22;
static const int _BITS01 = 44;
static const int _BITS2 = 20;
static const int _MASK = 4194303;
static const int _MASK2 = 1048575;
static const int _SIGN_BIT_MASK = 524288;
static const Int64 ZERO_A = const Int64._bits(0, 0, 0);
const Int64._bits(int this._l, int this._m, int this._h_A);
factory Int64([int value_A = 0]) {
int v0 = 0, v1 = 0, v2 = 0;
bool negative = false;
if (value_A < 0) {
negative = true;
value_A = -value_A - 1;
}
if (_haveBigInts) {
v0 = _MASK & value_A;
v1 = _MASK & (value_A >> _BITS);
v2 = _MASK2 & (value_A >> _BITS01);
} else {
v2 = value_A ~/ 17592186044416;
value_A -= v2 * 17592186044416;
v1 = value_A ~/ 4194304;
value_A -= v1 * 4194304;
v0 = value_A;
}
if (negative) {
v0 = ~v0;
v1 = ~v1;
v2 = ~v2;
}
return Int64._masked_A(v0, v1, v2);
}
factory Int64.fromBytes(List<int> bytes) {
int top_A = bytes[7] & 0xff;
top_A <<= 8;
top_A |= bytes[6] & 0xff;
top_A <<= 8;
top_A |= bytes[5] & 0xff;
top_A <<= 8;
top_A |= bytes[4] & 0xff;
int bottom_A = bytes[3] & 0xff;
bottom_A <<= 8;
bottom_A |= bytes[2] & 0xff;
bottom_A <<= 8;
bottom_A |= bytes[1] & 0xff;
bottom_A <<= 8;
bottom_A |= bytes[0] & 0xff;
return new Int64.fromInts(top_A, bottom_A);
}
factory Int64.fromInts(int top_A, int bottom_A) {
top_A &= 0xffffffff;
bottom_A &= 0xffffffff;
int d0 = _MASK & bottom_A;
int d1 = ((0xfff & top_A) << 10) | (0x3ff & (bottom_A >> _BITS));
int d2 = _MASK2 & (top_A >> 12);
return new Int64._bits(d0, d1, d2);
}
static Int64 _promote(value_A) {
if (value_A is Int64) {
return value_A;
} else if (value_A is int) {
return new Int64(value_A);
} else if (value_A is Int32) {
return value_A.toInt64();
}
throw new ArgumentError.value(value_A);
}
Int64 operator+(other) {
Int64 o = _promote(other);
int sum0 = _l + o._l;
int sum1 = _m + o._m + (sum0 >> _BITS);
int sum2 = _h_A + o._h_A + (sum1 >> _BITS);
return Int64._masked_A(sum0, sum1, sum2);
}
Int64 operator-(other) {
Int64 o = _promote(other);
return _sub(_l, _m, _h_A, o._l, o._m, o._h_A);
}
Int64 operator-() => _negate(_l, _m, _h_A);
Int64 operator*(other) {
Int64 o = _promote(other);
int a0 = _l & 0x1fff;
int a1 = (_l >> 13) | ((_m & 0xf) << 9);
int a2 = (_m >> 4) & 0x1fff;
int a3 = (_m >> 17) | ((_h_A & 0xff) << 5);
int a4 = (_h_A & 0xfff00) >> 8;
int b0 = o._l & 0x1fff;
int b1 = (o._l >> 13) | ((o._m & 0xf) << 9);
int b2 = (o._m >> 4) & 0x1fff;
int b3 = (o._m >> 17) | ((o._h_A & 0xff) << 5);
int b4 = (o._h_A & 0xfff00) >> 8;
int p0 = a0 * b0;
int p1 = a1 * b0;
int p2 = a2 * b0;
int p3 = a3 * b0;
int p4 = a4 * b0;
if (b1 != 0) {
p1 += a0 * b1;
p2 += a1 * b1;
p3 += a2 * b1;
p4 += a3 * b1;
}
if (b2 != 0) {
p2 += a0 * b2;
p3 += a1 * b2;
p4 += a2 * b2;
}
if (b3 != 0) {
p3 += a0 * b3;
p4 += a1 * b3;
}
if (b4 != 0) {
p4 += a0 * b4;
}
int c00 = p0 & 0x3fffff;
int c01 = (p1 & 0x1ff) << 13;
int c0 = c00 + c01;
int c10 = p0 >> 22;
int c11 = p1 >> 9;
int c12 = (p2 & 0x3ffff) << 4;
int c13 = (p3 & 0x1f) << 17;
int c1 = c10 + c11 + c12 + c13;
int c22 = p2 >> 18;
int c23 = p3 >> 5;
int c24 = (p4 & 0xfff) << 8;
int c2 = c22 + c23 + c24;
c1 += c0 >> _BITS;
c2 += c1 >> _BITS;
return Int64._masked_A(c0, c1, c2);
}
Int64 operator%(other) => _divide(this, other, _RETURN_MOD);
Int64 operator~/(other) => _divide(this, other, _RETURN_DIV);
Int64 remainder(other) => _divide(this, other, _RETURN_REM);
Int64 operator&(other) {
Int64 o = _promote(other);
int a0 = _l & o._l;
int a1 = _m & o._m;
int a2 = _h_A & o._h_A;
return new Int64._bits(a0, a1, a2);
}
Int64 operator|(other) {
Int64 o = _promote(other);
int a0 = _l | o._l;
int a1 = _m | o._m;
int a2 = _h_A | o._h_A;
return new Int64._bits(a0, a1, a2);
}
Int64 operator^(other) {
Int64 o = _promote(other);
int a0 = _l ^ o._l;
int a1 = _m ^ o._m;
int a2 = _h_A ^ o._h_A;
return Int64._masked_A(a0, a1, a2);
}
Int64 operator~() {
return Int64._masked_A(~_l, ~_m, ~_h_A);
}
Int64 operator<<(int n) {
if (n < 0) {
throw new ArgumentError.value(n);
}
n &= 63;
int res0, res1, res2;
if (n < _BITS) {
res0 = _l << n;
res1 = (_m << n) | (_l >> (_BITS - n));
res2 = (_h_A << n) | (_m >> (_BITS - n));
} else if (n < _BITS01) {
res0 = 0;
res1 = _l << (n - _BITS);
res2 = (_m << (n - _BITS)) | (_l >> (_BITS01 - n));
} else {
res0 = 0;
res1 = 0;
res2 = _l << (n - _BITS01);
}
return Int64._masked_A(res0, res1, res2);
}
Int64 operator>>(int n) {
if (n < 0) {
throw new ArgumentError.value(n);
}
n &= 63;
int res0, res1, res2;
int a2 = _h_A;
bool negative = (a2 & _SIGN_BIT_MASK) != 0;
if (negative && _MASK > _MASK2) {
a2 += (_MASK - _MASK2);
}
if (n < _BITS) {
res2 = _shiftRight(a2, n);
if (negative) {
res2 |= _MASK2 & ~(_MASK2 >> n);
}
res1 = _shiftRight(_m, n) | (a2 << (_BITS - n));
res0 = _shiftRight(_l, n) | (_m << (_BITS - n));
} else if (n < _BITS01) {
res2 = negative ? _MASK2 : 0;
res1 = _shiftRight(a2, n - _BITS);
if (negative) {
res1 |= _MASK & ~(_MASK >> (n - _BITS));
}
res0 = _shiftRight(_m, n - _BITS) | (a2 << (_BITS01 - n));
} else {
res2 = negative ? _MASK2 : 0;
res1 = negative ? _MASK : 0;
res0 = _shiftRight(a2, n - _BITS01);
if (negative) {
res0 |= _MASK & ~(_MASK >> (n - _BITS01));
}
}
return Int64._masked_A(res0, res1, res2);
}
bool operator==(other) {
Int64 o;
if (other is Int64) {
o = other;
} else if (other is int) {
if (_h_A == 0 && _m == 0) return _l == other;
if ((_MASK & other) == other) return false;
o = new Int64(other);
} else if (other is Int32) {
o = other.toInt64();
}
if (o != null) {
return _l == o._l && _m == o._m && _h_A == o._h_A;
}
return false;
}
int compareTo(IntX other) => _compareTo(other);
int _compareTo(other) {
Int64 o = _promote(other);
int signa = _h_A >> (_BITS2 - 1);
int signb = o._h_A >> (_BITS2 - 1);
if (signa != signb) {
return signa == 0 ? 1 : -1;
}
if (_h_A > o._h_A) {
return 1;
} else if (_h_A < o._h_A) {
return -1;
}
if (_m > o._m) {
return 1;
} else if (_m < o._m) {
return -1;
}
if (_l > o._l) {
return 1;
} else if (_l < o._l) {
return -1;
}
return 0;
}
bool operator<(other) => _compareTo(other) < 0;
bool operator<=(other) => _compareTo(other) <= 0;
bool operator>(other) => this._compareTo(other) > 0;
bool operator>=(other) => _compareTo(other) >= 0;
bool get isNegative => (_h_A & _SIGN_BIT_MASK) != 0;
bool get isZero => _h_A == 0 && _m == 0 && _l == 0;
int get hashCode {
int bottom_A = ((_m & 0x3ff) << _BITS) | _l;
int top_A = (_h_A << 12) | ((_m >> 10) & 0xfff);
return bottom_A ^ top_A;
}
Int64 abs() {
return this.isNegative ? -this : this;
}
List<int> toBytes() {
List<int> result_A = new List<int>(8);
result_A[0] = _l & 0xff;
result_A[1] = (_l >> 8) & 0xff;
result_A[2] = ((_m << 6) & 0xfc) | ((_l >> 16) & 0x3f);
result_A[3] = (_m >> 2) & 0xff;
result_A[4] = (_m >> 10) & 0xff;
result_A[5] = ((_h_A << 4) & 0xf0) | ((_m >> 18) & 0xf);
result_A[6] = (_h_A >> 4) & 0xff;
result_A[7] = (_h_A >> 12) & 0xff;
return result_A;
}
int toInt() {
int l = _l;
int m = _m;
int h = _h_A;
bool negative = false;
if ((_h_A & _SIGN_BIT_MASK) != 0) {
l = _MASK & ~_l;
m = _MASK & ~_m;
h = _MASK2 & ~_h_A;
negative = true;
}
if (_haveBigInts) {
int result_A = (h << _BITS01) | (m << _BITS) | l;
return negative ? -result_A - 1 : result_A;
} else {
if (negative) {
return -((l + 1) + (m * 4194304) + (h * 17592186044416));
} else {
return (l + (m * 4194304)) + (h * 17592186044416);
}
}
}
Int64 toInt64() => this;
String toString() => _toRadixString(10);
String toRadixString(int radix) {
return _toRadixString(Int32._validateRadix(radix));
}
String _toRadixString(int radix) {
int d0 = _l;
int d1 = _m;
int d2 = _h_A;
if (d0 == 0 && d1 == 0 && d2 == 0) return '0';
String sign_A = '';
if ((d2 & _SIGN_BIT_MASK) != 0) {
sign_A = '-';
d0 = 0 - d0;
int borrow = (d0 >> _BITS) & 1;
d0 &= _MASK;
d1 = 0 - d1 - borrow;
borrow = (d1 >> _BITS) & 1;
d1 &= _MASK;
d2 = 0 - d2 - borrow;
d2 &= _MASK2;
}
int d4 = (d2 << 4) | (d1 >> 18);
int d3 = (d1 >> 8) & 0x3ff;
d2 = ((d1 << 2) | (d0 >> 20)) & 0x3ff;
d1 = (d0 >> 10) & 0x3ff;
d0 = d0 & 0x3ff;
int fatRadix = _fatRadixTable[radix];
String chunk1 = "", chunk2 = "", chunk3 = "";
while (!(d4 == 0 && d3 == 0)) {
int q = d4 ~/ fatRadix;
int r = d4 - q * fatRadix;
d4 = q;
d3 += r << 10;
q = d3 ~/ fatRadix;
r = d3 - q * fatRadix;
d3 = q;
d2 += r << 10;
q = d2 ~/ fatRadix;
r = d2 - q * fatRadix;
d2 = q;
d1 += r << 10;
q = d1 ~/ fatRadix;
r = d1 - q * fatRadix;
d1 = q;
d0 += r << 10;
q = d0 ~/ fatRadix;
r = d0 - q * fatRadix;
d0 = q;
assert(chunk3 == "");
chunk3 = chunk2;
chunk2 = chunk1;
chunk1 = (fatRadix + r).toRadixString(radix).substring(1);
}
int residue = (d2 << 20) + (d1 << 10) + d0;
String leadingDigits = residue == 0 ? '' : residue.toRadixString(radix);
return '${sign_A}${leadingDigits}${chunk1}${chunk2}${chunk3}';
}
static const _fatRadixTable = const<int>[0, 0, 2 * 2 * 2 * 2 * 2 * 2 * 2 * 2 * 2 * 2 * 2 * 2 * 2 * 2 * 2 * 2 * 2 * 2 * 2 * 2, 3 * 3 * 3 * 3 * 3 * 3 * 3 * 3 * 3 * 3 * 3 * 3, 4 * 4 * 4 * 4 * 4 * 4 * 4 * 4 * 4 * 4, 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5, 6 * 6 * 6 * 6 * 6 * 6 * 6, 7 * 7 * 7 * 7 * 7 * 7 * 7, 8 * 8 * 8 * 8 * 8 * 8, 9 * 9 * 9 * 9 * 9 * 9, 10 * 10 * 10 * 10 * 10 * 10, 11 * 11 * 11 * 11 * 11, 12 * 12 * 12 * 12 * 12, 13 * 13 * 13 * 13 * 13, 14 * 14 * 14 * 14 * 14, 15 * 15 * 15 * 15 * 15, 16 * 16 * 16 * 16 * 16, 17 * 17 * 17 * 17, 18 * 18 * 18 * 18, 19 * 19 * 19 * 19, 20 * 20 * 20 * 20, 21 * 21 * 21 * 21, 22 * 22 * 22 * 22, 23 * 23 * 23 * 23, 24 * 24 * 24 * 24, 25 * 25 * 25 * 25, 26 * 26 * 26 * 26, 27 * 27 * 27 * 27, 28 * 28 * 28 * 28, 29 * 29 * 29 * 29, 30 * 30 * 30 * 30, 31 * 31 * 31 * 31, 32 * 32 * 32 * 32, 33 * 33 * 33, 34 * 34 * 34, 35 * 35 * 35, 36 * 36 * 36];
static Int64 _masked_A(int a0, int a1, int a2) => new Int64._bits(_MASK & a0, _MASK & a1, _MASK2 & a2);
static Int64 _sub(int a0, int a1, int a2, int b0, int b1, int b2) {
int diff0 = a0 - b0;
int diff1 = a1 - b1 - ((diff0 >> _BITS) & 1);
int diff2 = a2 - b2 - ((diff1 >> _BITS) & 1);
return _masked_A(diff0, diff1, diff2);
}
static Int64 _negate(int b0, int b1, int b2) {
return _sub(0, 0, 0, b0, b1, b2);
}
static bool _haveBigIntsCached = null;
static bool get _haveBigInts {
if (_haveBigIntsCached == null) {
var x_A = 9007199254740992;
if (2 + 2 != 4) {
x_A = 0;
}
var y_A = x_A + 1;
var same = y_A == x_A;
_haveBigIntsCached = !same;
}
return _haveBigIntsCached;
}
static int _shiftRight(int x_A, int n) {
if (x_A >= 0) {
return x_A >> n;
} else {
int shifted = x_A >> n;
if (shifted >= 0x80000000) {
shifted -= 4294967296;
}
return shifted;
}
}
static Int64 _divide(Int64 a, other, int what) {
Int64 b = _promote(other);
if (b.isZero) {
throw new IntegerDivisionByZeroException();
}
if (a.isZero) return ZERO_A;
bool aNeg = a.isNegative;
bool bNeg = b.isNegative;
a = a.abs();
b = b.abs();
int a0 = a._l;
int a1 = a._m;
int a2 = a._h_A;
int b0 = b._l;
int b1 = b._m;
int b2 = b._h_A;
return _divideHelper(a0, a1, a2, aNeg, b0, b1, b2, bNeg, what);
}
static const _RETURN_DIV = 1;
static const _RETURN_REM = 2;
static const _RETURN_MOD = 3;
static _divideHelper(int a0, int a1, int a2, bool aNeg, int b0, int b1, int b2, bool bNeg, int what) {
int q0 = 0, q1 = 0, q2 = 0;
int r0 = 0, r1 = 0, r2 = 0;
if (b2 == 0 && b1 == 0 && b0 < (1 << (30 - _BITS))) {
q2 = a2 ~/ b0;
int carry = a2 - q2 * b0;
int d1 = a1 + (carry << _BITS);
q1 = d1 ~/ b0;
carry = d1 - q1 * b0;
int d0 = a0 + (carry << _BITS);
q0 = d0 ~/ b0;
r0 = d0 - q0 * b0;
} else {
const double K2 = 17592186044416.0;
const double K1 = 4194304.0;
double ad = a0 + K1 * a1 + K2 * a2;
double bd = b0 + K1 * b1 + K2 * b2;
double qd = (ad / bd).floorToDouble();
double q2d = (qd / K2).floorToDouble();
qd = qd - K2 * q2d;
double q1d = (qd / K1).floorToDouble();
double q0d = qd - K1 * q1d;
q2 = q2d.toInt();
q1 = q1d.toInt();
q0 = q0d.toInt();
assert(q0 + K1 * q1 + K2 * q2 == (ad / bd).floorToDouble());
assert(q2 == 0 || b2 == 0);
double p0d = q0d * b0;
double p0carry = (p0d / K1).floorToDouble();
p0d = p0d - p0carry * K1;
double p1d = q1d * b0 + q0d * b1 + p0carry;
double p1carry = (p1d / K1).floorToDouble();
p1d = p1d - p1carry * K1;
double p2d = q2d * b0 + q1d * b1 + q0d * b2 + p1carry;
assert(p2d <= _MASK2);
int diff0 = a0 - p0d.toInt();
int diff1 = a1 - p1d.toInt() - ((diff0 >> _BITS) & 1);
int diff2 = a2 - p2d.toInt() - ((diff1 >> _BITS) & 1);
r0 = _MASK & diff0;
r1 = _MASK & diff1;
r2 = _MASK2 & diff2;
while (r2 >= _SIGN_BIT_MASK || r2 > b2 || (r2 == b2 && (r1 > b1 || (r1 == b1 && r0 >= b0)))) {
int m = (r2 & _SIGN_BIT_MASK) == 0 ? 1 : -1;
int d0 = r0 - m * b0;
int d1 = r1 - m * (b1 + ((d0 >> _BITS) & 1));
int d2 = r2 - m * (b2 + ((d1 >> _BITS) & 1));
r0 = _MASK & d0;
r1 = _MASK & d1;
r2 = _MASK2 & d2;
d0 = q0 + m;
d1 = q1 + m * ((d0 >> _BITS) & 1);
d2 = q2 + m * ((d1 >> _BITS) & 1);
q0 = _MASK & d0;
q1 = _MASK & d1;
q2 = _MASK2 & d2;
}
}
assert(Int64.ZERO_A <= new Int64._bits(r0, r1, r2));
assert(r2 < b2 || new Int64._bits(r0, r1, r2) < new Int64._bits(b0, b1, b2));
assert(what == _RETURN_DIV || what == _RETURN_MOD || what == _RETURN_REM);
if (what == _RETURN_DIV) {
if (aNeg != bNeg) return _negate(q0, q1, q2);
return Int64._masked_A(q0, q1, q2);
}
if (!aNeg) {
return Int64._masked_A(r0, r1, r2);
}
if (what == _RETURN_MOD) {
if (r0 == 0 && r1 == 0 && r2 == 0) {
return ZERO_A;
} else {
return _sub(b0, b1, b2, r0, r1, r2);
}
} else {
return _negate(r0, r1, r2);
}
}
}
abstract class IntX implements Comparable<IntX> {
IntX operator+(other);
IntX operator-(other);
IntX operator-();
IntX operator*(other);
IntX operator%(other);
IntX operator~/(other);
IntX remainder(other);
IntX operator&(other);
IntX operator|(other);
IntX operator^(other);
IntX operator~();
IntX operator<<(int shiftAmount);
IntX operator>>(int shiftAmount);
bool operator==(other);
bool operator<(other);
bool operator<=(other);
bool operator>(other);
bool operator>=(other);
bool get isNegative;
bool get isZero;
int get hashCode;
IntX abs();
List<int> toBytes();
int toInt();
Int64 toInt64();
String toString();
String toRadixString(int radix);
}
final Context url = new Context(style: Style.url_A);
final Context context_A = createInternal();
String get current_A {
var uri_A = Uri.base;
if (Style.platform == Style.url_A) {
return uri_A.resolve('.').toString();
} else {
var path_A = uri_A.toFilePath();
int lastIndex = path_A.length - 1;
assert(path_A[lastIndex] == '/' || path_A[lastIndex] == '\\');
return path_A.substring(0, lastIndex);
}
}
String withoutExtension(String path_A) => context_A.withoutExtension_A(path_A);
const SLASH_A = 0x2f;
const COLON_A = 0x3a;
const UPPER_A = 0x41;
const UPPER_Z = 0x5a;
const LOWER_A = 0x61;
const LOWER_Z = 0x7a;
const BACKSLASH_A = 0x5c;
Context createInternal() => new Context._internal_A();
class Context {
factory Context({Style style, String current}) {
if (current == null) {
if (style == null) {
current = current_A;
} else {
current = ".";
}
}
if (style == null) {
style = Style.platform;
} else if (style is! InternalStyle) {
throw new ArgumentError("Only styles defined by the path package are " "allowed.");
}
return new Context.__A(style as InternalStyle, current);
}
Context._internal_A() : style = Style.platform as InternalStyle, _current_A = null;
Context.__A(this.style, this._current_A);
final InternalStyle style;
final String _current_A;
String get current => _current_A != null ? _current_A : current_A;
String get separator => style.separator;
String absolute(String part1, [String part2, String part3, String part4, String part5, String part6, String part7]) {
return join(current, part1, part2, part3, part4, part5, part6, part7);
}
String basenameWithoutExtension(String path_A) => _parse_A(path_A).basenameWithoutExtension;
String dirname(String path_A) {
var parsed = _parse_A(path_A);
parsed.removeTrailingSeparators();
if (parsed.parts.isEmpty) return parsed.root == null ? '.' : parsed.root;
if (parsed.parts.length == 1) {
return parsed.root == null ? '.' : parsed.root;
}
parsed.parts.removeLast();
parsed.separators.removeLast();
parsed.removeTrailingSeparators();
return parsed.toString();
}
String extension(String path_A) => _parse_A(path_A).extension;
String rootPrefix(String path_A) => path_A.substring(0, style.rootLength(path_A));
bool isAbsolute(String path_A) => style.rootLength(path_A) > 0;
bool isRelative(String path_A) => !this.isAbsolute(path_A);
bool isRootRelative(String path_A) => style.isRootRelative(path_A);
String join(String part1, [String part2, String part3, String part4, String part5, String part6, String part7, String part8]) {
var parts = <String>[part1, part2, part3, part4, part5, part6, part7, part8];
_validateArgList("join", parts);
return joinAll(parts.where((part_A) => part_A != null));
}
String joinAll(Iterable<String> parts) {
var buffer_A = new StringBuffer();
var needsSeparator = false;
var isAbsoluteAndNotRootRelative = false;
for (var part_A in parts.where((part_A) => part_A != '')) {
if (this.isRootRelative(part_A) && isAbsoluteAndNotRootRelative) {
var parsed = _parse_A(part_A);
parsed.root = this.rootPrefix(buffer_A.toString());
if (style.needsSeparator(parsed.root)) {
parsed.separators[0] = style.separator;
}
buffer_A.clear();
buffer_A.write(parsed.toString());
} else if (this.isAbsolute(part_A)) {
isAbsoluteAndNotRootRelative = !this.isRootRelative(part_A);
buffer_A.clear();
buffer_A.write(part_A);
} else {
if (part_A.length > 0 && style.containsSeparator(part_A[0])) {} else if (needsSeparator) {
buffer_A.write(separator);
}
buffer_A.write(part_A);
}
needsSeparator = style.needsSeparator(part_A);
}
return buffer_A.toString();
}
List<String> split(String path_A) {
var parsed = _parse_A(path_A);
parsed.parts = parsed.parts.where((part_A) => !part_A.isEmpty).toList();
if (parsed.root != null) parsed.parts.insert(0, parsed.root);
return parsed.parts;
}
String normalize(String path_A) {
var parsed = _parse_A(path_A);
parsed.normalize();
return parsed.toString();
}
String relative(String path_A, {String from}) {
if (from == null) {
from = current;
} else if (this.isRelative(from) || this.isRootRelative(from)) {
from = this.join(current, from);
}
if (this.isRelative(from) && this.isAbsolute(path_A)) {
return this.normalize(path_A);
}
if (this.isRelative(path_A) || this.isRootRelative(path_A)) {
path_A = this.absolute(path_A);
}
if (this.isRelative(path_A) && this.isAbsolute(from)) {
throw new PathException('Unable to find a path to "${path_A}" from "${from}".');
}
var fromParsed = _parse_A(from)
..normalize();
var pathParsed = _parse_A(path_A)
..normalize();
if (fromParsed.parts.length > 0 && fromParsed.parts[0] == '.') {
return pathParsed.toString();
}
if (fromParsed.root != pathParsed.root && ((fromParsed.root == null || pathParsed.root == null) || fromParsed.root.toLowerCase().replaceAll('/', '\\') != pathParsed.root.toLowerCase().replaceAll('/', '\\'))) {
return pathParsed.toString();
}
while (fromParsed.parts.length > 0 && pathParsed.parts.length > 0 && fromParsed.parts[0] == pathParsed.parts[0]) {
fromParsed.parts.removeAt(0);
fromParsed.separators.removeAt(1);
pathParsed.parts.removeAt(0);
pathParsed.separators.removeAt(1);
}
if (fromParsed.parts.length > 0 && fromParsed.parts[0] == '..') {
throw new PathException('Unable to find a path to "${path_A}" from "${from}".');
}
pathParsed.parts.insertAll(0, new List.filled(fromParsed.parts.length, '..'));
pathParsed.separators[0] = '';
pathParsed.separators.insertAll(1, new List.filled(fromParsed.parts.length, style.separator));
if (pathParsed.parts.length == 0) return '.';
if (pathParsed.parts.length > 1 && pathParsed.parts.last == '.') {
pathParsed.parts.removeLast();
pathParsed.separators
..removeLast()
..removeLast()
..add('');
}
pathParsed.root = '';
pathParsed.removeTrailingSeparators();
return pathParsed.toString();
}
String withoutExtension_A(String path_A) {
var parsed = _parse_A(path_A);
for (var i = parsed.parts.length - 1; i >= 0; i--) {
if (!parsed.parts[i].isEmpty) {
parsed.parts[i] = parsed.basenameWithoutExtension;
break;
}
}
return parsed.toString();
}
String fromUri_A(uri_A) {
if (uri_A is String) uri_A = Uri.parse(uri_A);
return style.pathFromUri(uri_A);
}
Uri toUri(String path_A) {
if (isRelative(path_A)) {
return style.relativePathToUri(path_A);
} else {
return style.absolutePathToUri(join(current, path_A));
}
}
ParsedPath _parse_A(String path_A) => new ParsedPath.parse_A(path_A, style);
}
_validateArgList(String method_A, List<String> args) {
for (var i = 1; i < args.length; i++) {
if (args[i] == null || args[i - 1] != null) continue;
var numArgs;
for (numArgs = args.length; numArgs >= 1; numArgs--) {
if (args[numArgs - 1] != null) break;
}
var message_A = new StringBuffer();
message_A.write("${method_A}(");
message_A.write(args.take(numArgs).map((arg) => arg == null ? "null" : '"${arg}"').join(", "));
message_A.write("): part ${i - 1} was null, but part ${i} was not.");
throw new ArgumentError(message_A.toString());
}
}
abstract class InternalStyle extends Style {
String get separator;
bool containsSeparator(String path_A);
bool isSeparator(int codeUnit);
bool needsSeparator(String path_A);
int rootLength(String path_A);
String getRoot(String path_A) {
var length_A = rootLength(path_A);
if (length_A > 0) return path_A.substring(0, length_A);
return isRootRelative(path_A) ? path_A[0] : null;
}
bool isRootRelative(String path_A);
String pathFromUri(Uri uri_A);
Uri relativePathToUri(String path_A) {
var segments = context.split(path_A);
if (isSeparator(path_A.codeUnitAt(path_A.length - 1))) segments.add('');
return new Uri(pathSegments: segments);
}
Uri absolutePathToUri(String path_A);
}
class ParsedPath {
InternalStyle style;
String root;
bool isRootRelative;
List<String> parts;
List<String> separators;
String get extension => _splitExtension()[1];