This repository was archived by the owner on Mar 24, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy patharUnMHTExtractor.m
More file actions
2456 lines (2284 loc) · 62.3 KB
/
Copy patharUnMHTExtractor.m
File metadata and controls
2456 lines (2284 loc) · 62.3 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
/* -*- Mode: ObjC; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is UnMHT for QuickLook.
*
* The Initial Developer of the Original Code is arai.
* Portions created by the Initial Developer are Copyright (C) 2007
* the Initial Developer. All Rights Reserved.
*
* Contributor(s): arai <arai@mail.unmht.org>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#import "arUnMHTExtractor.h"
#include "stdlib.h"
#include "ctype.h"
@implementation arUnMHTExtractorFile
/**
* 初期化
*
* @return id
* 自分自身
*/
- (id) init {
self = [super init];
self->charset = @"";
self->cid = @"";
self->location = @"";
self->baseDir = @"";
self->referredBaseDir = @"";
self->leafName = @"";
self->extension = @"";
self->disposition = @"";
self->dispositionType = @"";
self->encoding = 0;
self->content = @"";
self->binContent
= [NSData
dataWithBytes: ""
length: 0];
self->deleted = false;
self->nativeFilename = @"";
self->size = 0;
return self;
}
/**
* 開放
*/
- (void) release {
[super release];
}
@end
@implementation arUnMHTExtractor
/**
* 初期化
*
* @return id
* 自分自身
*/
- (id) init {
self = [super init];
if (self == nil) {
return nil;
}
self->boundary = @"";
self->boundaryStack = nil;
self->subject = @"";
self->start = @"";
self->rootFile = nil;
self->alternative = false;
self->files = nil;
return self;
}
/**
* 開放
*/
- (void) release {
if (self->boundaryStack != nil) {
[self->boundaryStack release];
self->boundaryStack = nil;
}
if (self->rootFile != nil) {
/* 参照だけなので開放はしない */
self->rootFile = nil;
}
if (self->files != nil) {
[self->files release];
self->files = nil;
}
[super release];
}
/**
* Base64 をデコードする
*
* @param NSString *text
* デコードする文字列
* @return NSData *
* デコードしたデータ
*
*/
- (NSData *) atob: (NSString *)text {
int i, j;
int length;
const char *ascii;
char *binary;
char *b;
char *c;
char part1, part2, part3, part4;
NSData *data;
length = [text length];
ascii
= [text
cStringUsingEncoding: NSASCIIStringEncoding];
binary = (char *)malloc (length + 1);
b = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
for (i = 0, j = 0; i < length; i += 4) {
c = strchr (b, ascii [i]);
if (c != NULL) {
part1 = (char)(c - b);
}
else {
part1 = -1;
}
c = strchr (b, ascii [i + 1]);
if (c != NULL) {
part2 = (char)(c - b);
}
else {
part2 = -1;
}
c = strchr (b, ascii [i + 2]);
if (c != NULL) {
part3 = (char)(c - b);
}
else {
part3 = -1;
}
c = strchr (b, ascii [i + 3]);
if (c != NULL) {
part4 = (char)(c - b);
}
else {
part4 = -1;
}
if (part1 != -1 && part2 != -1) {
binary [j] = (part1 << 2) | (part2 >> 4);
j ++;
}
if (part2 != -1 && part3 != -1 && part3 != 64) {
binary [j] = ((part2 & 0x0f) << 4) | (part3 >> 2);
j ++;
}
if (part3 != -1 && part4 != -1 && part4 != 64) {
binary [j] = ((part3 & 0x03) << 6) | (part4);
j ++;
}
}
data
= [NSData
dataWithBytes: binary
length: j];
free (binary);
return data;
}
/**
* Base64 にエンコードする
*
* @param NSData *data
* エンコードするデータ
* @return NSString *
* エンコードした文字列
*/
- (NSString *) btoa: (NSData *)data {
int i, j;
int length;
char *ascii;
const char *binary;
char *b;
int c;
int part1, part2, part3, part4;
NSString *text;
length = [data length];
ascii = (char *)malloc (length * 2 + 1);
binary = (const char *)[data bytes];
b = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
for (i = 0, j = 0; i < length; i += 3) {
c = (unsigned char)binary [i];
part1 = c >> 2;
part2 = (c & 0x3) << 4;
if (i + 1 == length) {
part3 = 64;
part4 = 64;
}
else {
c = binary [i + 1];
part2 |= (c & 0xf0) >> 4;
part3 = (c & 0x0f) << 2;
if (i + 2 == length) {
part4 = 64;
}
else {
c = binary [i + 2];
part3 |= (c & 0xc0) >> 6;
part4 = c & 0x3f;
}
}
ascii [j] = b [part1];
j ++;
ascii [j] = b [part2];
j ++;
ascii [j] = b [part3];
j ++;
ascii [j] = b [part4];
j ++;
}
text
= [[NSString alloc]
initWithBytes: ascii
length: j
encoding: NSASCIIStringEncoding];
free (ascii);
return text;
}
/**
* quoted-pritable をデコードする
*
* @param NSString *text
* デコードする文字列
* @return NSData *
* デコードしたデータ
*/
- (NSData *) decodeQuotedPrintable: (NSString *)text {
int i, j;
int length;
const char *ascii;
char *binary;
char tmp [3];
NSData *data;
ascii
= [text
cStringUsingEncoding: NSASCIIStringEncoding];
length = [text length];
binary = (char *)malloc (length + 1);
for (i = 0, j = 0; i < length;) {
if (i < length - 2 && ascii [i] == '=') {
if (isxdigit (ascii [i + 1])
&& isxdigit (ascii [i + 2])) {
tmp [0] = ascii [i + 1];
tmp [1] = ascii [i + 2];
tmp [2] = '\0';
binary [j] = (char)(unsigned char)strtol (tmp, NULL, 16);
i += 3;
j ++;
}
else {
binary [j] = ascii [i];
i ++;
j ++;
}
}
else {
binary [j] = ascii [i];
i ++;
j ++;
}
}
data
= [NSData
dataWithBytes: binary
length: j];
free (binary);
return data;
}
/**
* URL エンコーディングをデコードする
*
* @param NSString *text
* デコードする文字列
* @return NSData *
* デコードしたデータ
*/
- (NSData *) unescape: (NSString *)text {
int i, j;
int length;
const char *ascii;
char *binary;
char tmp [3];
NSData *data;
ascii
= [text
cStringUsingEncoding: NSASCIIStringEncoding];
length = [text length];
binary = (char *)malloc (length + 1);
for (i = 0, j = 0; i < length;) {
if (i < length - 2 && ascii [i] == '%') {
if (isxdigit (ascii [i + 1])
&& isxdigit (ascii [i + 2])) {
tmp [0] = ascii [i + 1];
tmp [1] = ascii [i + 2];
tmp [2] = '\0';
binary [j] = (char)(unsigned char)strtol (tmp, NULL, 16);
i += 3;
j ++;
}
else {
binary [j] = ascii [i];
i ++;
j ++;
}
}
else {
binary [j] = ascii [i];
i ++;
j ++;
}
}
data
= [NSData
dataWithBytes: binary
length: j];
free (binary);
return data;
}
/**
* encoded word をデコードする
*
* @param NSString *text
* デコードする文字列
* @return NSString *
* デコードした文字列
*/
- (NSString *) decodeEW: (NSString *)text {
int length;
NSRange range;
NSRange range2;
NSStringEncoding encoding;
NSString *encodedCharset;
NSString *encodedType;
NSString *encodedText;
NSData *encodedData;
length = [text length];
range
= [text
rangeOfString: @"=?"
options: NSLiteralSearch];
if (range.location != 0) {
/* =? が 先頭に無い */
return text;
}
range2
= [text
rangeOfString: @"?"
options: NSLiteralSearch
range: NSMakeRange (range.location + range.length,
length - range.location - range.length)];
if (range.location == NSNotFound) {
/* ? が無い */
return text;
}
encodedCharset
= [text
substringWithRange: NSMakeRange (range.location + range.length,
range2.location
- range.location - range.length)];
range = range2;
range2
= [text
rangeOfString: @"?"
options: NSLiteralSearch
range: NSMakeRange (range.location + range.length,
length - range.location - range.length)];
if (range.location == NSNotFound) {
/* ? が無い */
return text;
}
encodedType
= [text
substringWithRange: NSMakeRange (range.location + range.length,
range2.location
- range.location - range.length)];
range = range2;
range2
= [text
rangeOfString: @"?="
options: NSLiteralSearch
range: NSMakeRange (range.location + range.length,
length - range.location - range.length)];
if (range.location == NSNotFound) {
/* ?= が無い */
return text;
}
encodedText
= [text
substringWithRange: NSMakeRange (range.location + range.length,
range2.location
- range.location - range.length)];
if ([encodedType
isEqualToString: @"Q"]) {
encodedData
= [self
decodeQuotedPrintable: encodedText];
}
else if ([encodedType
isEqualToString: @"B"]) {
encodedData
= [self
atob: encodedText];
}
else {
encodedData
= [encodedText
dataUsingEncoding: NSASCIIStringEncoding];
}
encoding
= CFStringConvertEncodingToNSStringEncoding
(CFStringConvertIANACharSetNameToEncoding ((CFStringRef)encodedCharset));
text
= [[NSString alloc]
initWithData: encodedData
encoding: encoding];
return text;
}
/**
* MIME ヘッダを各名前と値に分割する
*
* @param NSString *header
* MIME ヘッダ
* @return NSMutableDictionary *
* ヘッダの内容を示す辞書
* <NSString *名前, NSString *値>
*
*/
- (NSMutableDictionary *) splitHeader: (NSString *)header {
char c;
int length;
NSRange range;
NSRange restRange;
NSRange lineRange;
NSCharacterSet *characterSet;
NSString *line;
NSString *name;
NSString *value;
NSMutableDictionary *headerMap;
headerMap = [[NSMutableDictionary alloc] init];
restRange = NSMakeRange (0, [header length]);
name = nil;
value = nil;
while (restRange.length > 0) {
lineRange
= [header
lineRangeForRange: NSMakeRange (restRange.location, 0)];
if (lineRange.location == NSNotFound) {
break;
}
line
= [header
substringWithRange: lineRange];
length = [line length];
if (length >= 1) {
c
= [line
characterAtIndex: length - 1];
if (c == '\n') {
line = [line
substringToIndex: length - 1];
length --;
}
}
if (length >= 1) {
c
= [line
characterAtIndex: length - 1];
if (c == '\r') {
line = [line
substringToIndex: length - 1];
length --;
}
}
if (length == 0) {
/* 終了 */
break;
}
c
= [line
characterAtIndex: 0];
if (c == ' ' || c == '\t') {
/* 2 行目以降 */
characterSet
= [[NSCharacterSet
characterSetWithCharactersInString: @" \t"]
invertedSet];
range
= [line
rangeOfCharacterFromSet: characterSet
options: NSLiteralSearch];
if (range.location != NSNotFound) {
value
= [NSString stringWithFormat: @"%@%@",
value,
[line
substringFromIndex: range.location]];
}
}
else {
/* 1 行目 */
if (name != nil) {
[headerMap
setValue: [self
decodeEW: value]
forKey: [name lowercaseString]];
}
range
= [line
rangeOfString: @":"
options: NSLiteralSearch];
if (range.location == NSNotFound) {
/* : が無い */
[headerMap release];
return nil;
}
name
= [line
substringToIndex: range.location];
characterSet
= [[NSCharacterSet
characterSetWithCharactersInString: @" "]
invertedSet];
range
= [line
rangeOfCharacterFromSet: characterSet
options: NSLiteralSearch
range: NSMakeRange (range.location + range.length,
length - range.location - range.length)];
if (range.location == NSNotFound) {
value = @"";
}
else {
value
= [line
substringFromIndex: range.location];
}
}
restRange
= NSMakeRange (lineRange.location + lineRange.length,
[header length]
- lineRange.location - lineRange.length);
}
if (name != nil) {
[headerMap
setValue: [self
decodeEW: value]
forKey: [name lowercaseString]];
}
return headerMap;
}
/**
* RFC2231 をデコードする
*
* @param NSString *text
* デコードする文字列
* @return NSString *
* デコードした文字列
*/
- (NSString *) decodeRFC2231: (NSString *)text {
NSRange range;
NSRange range2;
NSStringEncoding encoding;
NSData *data;
NSString *encode;
NSString *language;
range
= [text
rangeOfString: @"\'"
options: NSLiteralSearch];
if (range.location != NSNotFound
&& range.location > 0) {
encode
= [text
substringToIndex: range.location];
range2
= [text
rangeOfString: @"\'"
options: NSLiteralSearch
range: NSMakeRange (range.location + range.length,
[text length]
- range.location - range.length)];
if (range2.location != NSNotFound
&& range2.location + range2.length != [text length]) {
language
= [text
substringWithRange: NSMakeRange (range.location
+ range.length,
range2.location
- range.location
- range.length)];
text
= [text
substringFromIndex: range2.location + range2.length];
data
= [self
unescape: text];
encoding
= CFStringConvertEncodingToNSStringEncoding
(CFStringConvertIANACharSetNameToEncoding ((CFStringRef)encode));
text
= [[NSString alloc]
initWithData: data
encoding: encoding];
}
}
return text;
}
/**
* Content-Type/Content-Disposition の値を解析する
*
* @param NSString *value
* Content-Type/Content-Disposition の値
* @param bool mimeType
* 値のみのフィールドは MIME Type か
* @return NSMutableDictionary *
* 解析した値の辞書
* <NSString *名前, NSString *値>
*/
- (NSMutableDictionary *) parseValue: (NSString *)value
mimeType: (bool)mimeType {
int i;
NSRange restRange;
NSRange range;
NSRange range2;
NSString *index;
NSString *current;
NSString *name2;
NSString *value2;
NSString *realName;
NSString *realValue;
NSCharacterSet *separatorSet;
NSCharacterSet *notSeparatorSet;
NSMutableDictionary *map;
NSMutableDictionary *map2;
map = [[NSMutableDictionary alloc] init];
map2 = [[NSMutableDictionary alloc] init];
restRange = NSMakeRange (0, [value length]);
separatorSet
= [NSCharacterSet
characterSetWithCharactersInString: @" \t;"];
notSeparatorSet = [separatorSet invertedSet];
while (restRange.length > 0) {
range
= [value
rangeOfCharacterFromSet: separatorSet
options: NSLiteralSearch
range: restRange];
if (range.location != NSNotFound) {
current
= [value
substringWithRange: NSMakeRange (restRange.location,
range.location
- restRange.location)];
restRange
= NSMakeRange (range.location + range.length,
[value length]
- range.location - range.length);
range
= [value
rangeOfCharacterFromSet: notSeparatorSet
options: NSLiteralSearch
range: restRange];
if (range.location != NSNotFound) {
restRange = NSMakeRange (range.location,
[value length] - range.location);
}
else {
restRange = NSMakeRange (0, 0);
}
}
else {
current
= [value
substringWithRange: restRange];
restRange = NSMakeRange (0, 0);
}
range2
= [current
rangeOfString: @"="
options: NSLiteralSearch];
if (range2.location != NSNotFound) {
name2
= [current
substringToIndex: range2.location];
value2
= [current
substringFromIndex: range2.location + range2.length];
if ([value2 length] >= 2) {
if ([value2
characterAtIndex: 0] == '\"'
&& [value2
characterAtIndex: [value2 length] - 1] == '\"') {
value2
= [value2
substringWithRange: NSMakeRange (1, [value2 length] - 2)];
}
else if ([value2
characterAtIndex: 0] == '\''
&& [value2
characterAtIndex: [value2 length] - 1] == '\'') {
value2
= [value2
substringWithRange: NSMakeRange (1, [value2 length] - 2)];
}
}
[map
setValue: value2
forKey: name2];
}
else {
range2
= [current
rangeOfString: @"/"
options: NSLiteralSearch];
if (range2.location != NSNotFound
|| !mimeType) {
[map
setValue: current
forKey: @"_"];
}
}
}
for (name2 in map) {
range
= [name2
rangeOfString: @"*"
options: NSLiteralSearch];
if (range.location != NSNotFound) {
/* RFC2231 */
if (range.location + range.length == [name2 length]) {
/* 単体でエンコードあり */
realName
= [name2
substringToIndex: [name2 length] - 1];
value2
= [map
valueForKey: name2];
realValue
= [self
decodeRFC2231: value2];
[map2
setValue: realValue
forKey: realName];
}
else {
i = range.location + range.length;
while (i < [name2 length]
&& isdigit ([name2
characterAtIndex: i])) {
i ++;
}
if (i == [name2 length]) {
/* 複数でエンコードなし */
index
= [name2
substringFromIndex: range.location + range.length];
}
else if ([name2
characterAtIndex: i] == '*') {
/* 複数でエンコードあり */
index
= [name2
substringWithRange: NSMakeRange (range.location
+ range.length,
i
- range.location
- range.length)];
}
else {
continue;
}
if ([index
isEqualToString: @"0"]) {
/* 最初の値 */
realName
= [name2
substringToIndex: range.location];
realValue = @"";
i = 0;
for (;;) {
name2
= [NSString stringWithFormat: @"%@*%d",
realName, i];
if ([map
objectForKey: name2] != nil) {
/* エンコードなし */
value2
= [map
valueForKey: name2];
realValue
= [NSString stringWithFormat: @"%@%@",
realValue, value2];
}
else {
name2
= [NSString stringWithFormat: @"%@*%d*",
realName, i];
if ([map
objectForKey: name2] != nil) {
/* エンコードあり */
value2
= [map
valueForKey: name2];
value2
= [self
decodeRFC2231: value2];
realValue
= [NSString stringWithFormat: @"%@%@",
realValue, value2];
}
else {
break;
}
}
i ++;
}
[map2
setValue: realValue
forKey: realName];
}
}
}
}
for (name2 in map2) {
value2
= [map2
valueForKey: name2];
[map
setValue: value2
forKey: name2];
}
[map2 release];
return map;
}
/**
* Content-Location を親ディレクトリとファイル名に分割する
*
* @param UnMHTExtractorFile *file
* 対象のファイル情報
* @return int
* 成功したか
* 0: 失敗
* 1: 成功
*/
- (int) splitLocation: (arUnMHTExtractorFile *)file {
int i;
NSRange range;
range
= [file->location
rangeOfString: @"mhtml:"
options: NSCaseInsensitiveSearch];
if (range.location != NSNotFound) {
/* mhtml で始まる場合 (IE のプロトコル ?) */
/* ! の前後に分割する */
i = [file->location length] - 1;
while (i >= 0
&& [file->location
characterAtIndex: i] != '!') {
i --;
}
if (i >= 0 && i != [file->location length] - 1) {
/* ファイル名がある場合 */
file->baseDir
= [file->location
substringToIndex: i];
file->leafName
= [file->location
substringFromIndex: i + 1];
}
else {
/* ファイル名がない場合 */
file->baseDir = file->location;
file->leafName = @"";
}
}
else {
range
= [file->location
rangeOfString: @"\\"
options: NSLiteralSearch];
if (range.location != NSNotFound) {
/* Windows のパスの場合 */
i = [file->location length] - 1;
while (i >= 0
&& [file->location
characterAtIndex: i] != '\\') {
i --;
}
if (i >= 0 && i != [file->location length] - 1) {
/* ファイル名がある場合 */
file->baseDir
= [file->location
substringToIndex: i];
file->leafName
= [file->location
substringFromIndex: i + 1];
}
else {
/* ファイル名がない場合 */
file->baseDir = file->location;
file->leafName = @"";
}
}
else {