1
2
3
4
5
6
7
8
9
|
1
2
3
4
5
6
7
8
9
|
-
+
|
/*
* Copyright (c) 2008-2022 Jonathan Schleifer <js@nil.im>
* Copyright (c) 2008-2024 Jonathan Schleifer <js@nil.im>
*
* All rights reserved.
*
* This file is part of ObjFW. It may be distributed under the terms of the
* Q Public License 1.0, which can be found in the file LICENSE.QPL included in
* the packaging of this file.
*
|
| ︙ | | |
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
|
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
|
-
+
+
+
-
-
-
|
#include <ctype.h>
#include <errno.h>
#include <math.h>
#include <stdarg.h>
#include <stdlib.h>
#include <string.h>
#if defined(HAVE_STRTOF_L) || defined(HAVE_STRTOD_L)
#if defined(HAVE_STRTOF_L) || defined(HAVE_STRTOD_L) || defined(HAVE_USELOCALE)
# include <locale.h>
#endif
#ifdef HAVE_XLOCALE_H
# include <xlocale.h>
#endif
#import "OFString.h"
#import "OFASPrintF.h"
#import "OFArray.h"
#import "OFCharacterSet.h"
#import "OFData.h"
#import "OFDictionary.h"
#ifdef OF_HAVE_FILES
# import "OFFile.h"
# import "OFFileManager.h"
#endif
#import "OFIRI.h"
#import "OFIRIHandler.h"
#import "OFLocale.h"
#import "OFStream.h"
#import "OFSystemInfo.h"
#import "OFURI.h"
#import "OFURIHandler.h"
#import "OFUTF8String.h"
#import "OFUTF8String+Private.h"
#import "OFXMLElement.h"
#import "OFGetItemAttributesFailedException.h"
#import "OFInitializationFailedException.h"
#import "OFInvalidArgumentException.h"
#import "OFInvalidEncodingException.h"
#import "OFInvalidFormatException.h"
#import "OFNotImplementedException.h"
|
| ︙ | | |
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
|
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
|
-
+
-
+
|
# define INFINITY __builtin_inf()
#endif
static struct {
Class isa;
} placeholder;
#if defined(HAVE_STRTOF_L) || defined(HAVE_STRTOD_L)
#if defined(HAVE_STRTOF_L) || defined(HAVE_STRTOD_L) || defined(HAVE_USELOCALE)
static locale_t cLocale;
#endif
@interface OFString ()
- (size_t)of_getCString: (char *)cString
maxLength: (size_t)maxLength
encoding: (OFStringEncoding)encoding
lossy: (bool)lossy OF_DIRECT;
- (const char *)of_cStringWithEncoding: (OFStringEncoding)encoding
lossy: (bool)lossy OF_DIRECT;
- (OFString *)
of_JSONRepresentationWithOptions: (OFJSONRepresentationOptions)options
depth: (size_t)depth;
@end
@interface OFStringPlaceholder: OFString
@interface OFPlaceholderString: OFString
@end
extern bool OFUnicodeToISO8859_2(const OFUnichar *, unsigned char *,
size_t, bool);
extern bool OFUnicodeToISO8859_3(const OFUnichar *, unsigned char *,
size_t, bool);
extern bool OFUnicodeToISO8859_15(const OFUnichar *, unsigned char *,
|
| ︙ | | |
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
|
130
131
132
133
134
135
136
137
138
139
140
141
142
143
|
-
|
_OFString_CryptographicHashing_reference = 1;
_OFString_JSONParsing_reference = 1;
#ifdef OF_HAVE_FILES
_OFString_PathAdditions_reference = 1;
#endif
_OFString_PercentEncoding_reference = 1;
_OFString_PropertyListParsing_reference = 1;
_OFString_Serialization_reference = 1;
_OFString_XMLEscaping_reference = 1;
_OFString_XMLUnescaping_reference = 1;
}
void
_reference_to_OFConstantString(void)
{
|
| ︙ | | |
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
|
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
|
-
-
+
-
-
-
-
-
-
-
+
-
-
-
-
+
-
-
-
-
-
+
-
-
-
-
-
-
-
+
-
-
+
-
-
-
-
|
size_t length = strlen(string);
char *copy = (char *)OFAllocMemory(1, length + 1);
memcpy(copy, string, length + 1);
return copy;
}
#ifdef OF_HAVE_UNICODE_TABLES
static OFString *
@implementation OFPlaceholderString
decomposedString(OFString *self, const char *const *const *table, size_t size)
{
OFMutableString *ret = [OFMutableString string];
void *pool = objc_autoreleasePoolPush();
const OFUnichar *characters = self.characters;
size_t length = self.length;
#ifdef __clang__
for (size_t i = 0; i < length; i++) {
OFUnichar c = characters[i];
const char *const *page;
/* We intentionally don't call into super, so silence the warning. */
if (c >= size) {
[ret appendCharacters: &c length: 1];
continue;
}
# pragma clang diagnostic push
page = table[c >> 8];
if (page != NULL && page[c & 0xFF] != NULL)
[ret appendUTF8String: page[c & 0xFF]];
else
[ret appendCharacters: &c length: 1];
}
# pragma clang diagnostic ignored "-Wunknown-pragmas"
objc_autoreleasePoolPop(pool);
# pragma clang diagnostic ignored "-Wobjc-designated-initializers"
return ret;
}
#endif
@implementation OFStringPlaceholder
- (instancetype)init
{
return (id)[[OFUTF8String alloc] init];
}
- (instancetype)initWithUTF8String: (const char *)UTF8String
{
|
| ︙ | | |
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
|
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
|
-
+
-
+
-
+
-
+
-
+
-
-
-
-
-
+
-
-
-
-
-
+
-
-
+
-
-
-
+
-
-
-
-
-
-
-
-
-
+
-
+
|
encoding: (OFStringEncoding)encoding
{
return (id)[[OFUTF8String alloc] initWithContentsOfFile: path
encoding: encoding];
}
#endif
- (instancetype)initWithContentsOfURI: (OFURI *)URI
- (instancetype)initWithContentsOfIRI: (OFIRI *)IRI
{
return (id)[[OFUTF8String alloc] initWithContentsOfURI: URI];
return (id)[[OFUTF8String alloc] initWithContentsOfIRI: IRI];
}
- (instancetype)initWithContentsOfURI: (OFURI *)URI
- (instancetype)initWithContentsOfIRI: (OFIRI *)IRI
encoding: (OFStringEncoding)encoding
{
return (id)[[OFUTF8String alloc] initWithContentsOfURI: URI
return (id)[[OFUTF8String alloc] initWithContentsOfIRI: IRI
encoding: encoding];
}
#ifdef __clang__
- (instancetype)initWithSerialization: (OFXMLElement *)element
{
return (id)[[OFUTF8String alloc] initWithSerialization: element];
}
# pragma clang diagnostic pop
- (instancetype)retain
{
return self;
}
#endif
- (instancetype)autorelease
{
return self;
}
OF_SINGLETON_METHODS
- (void)release
{
}
- (void)dealloc
{
OF_DEALLOC_UNSUPPORTED
}
@end
@implementation OFString
+ (void)initialize
{
if (self != [OFString class])
return;
placeholder.isa = [OFStringPlaceholder class];
object_setClass((id)&placeholder, [OFPlaceholderString class]);
#if defined(HAVE_STRTOF_L) || defined(HAVE_STRTOD_L)
#if defined(HAVE_STRTOF_L) || defined(HAVE_STRTOD_L) || defined(HAVE_USELOCALE)
if ((cLocale = newlocale(LC_ALL_MASK, "C", NULL)) == NULL)
@throw [OFInitializationFailedException
exceptionWithClass: self];
#endif
}
+ (instancetype)alloc
|
| ︙ | | |
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
|
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
|
-
+
-
+
-
+
-
+
-
+
+
|
encoding: (OFStringEncoding)encoding
{
return [[[self alloc] initWithContentsOfFile: path
encoding: encoding] autorelease];
}
#endif
+ (instancetype)stringWithContentsOfURI: (OFURI *)URI
+ (instancetype)stringWithContentsOfIRI: (OFIRI *)IRI
{
return [[[self alloc] initWithContentsOfURI: URI] autorelease];
return [[[self alloc] initWithContentsOfIRI: IRI] autorelease];
}
+ (instancetype)stringWithContentsOfURI: (OFURI *)URI
+ (instancetype)stringWithContentsOfIRI: (OFIRI *)IRI
encoding: (OFStringEncoding)encoding
{
return [[[self alloc] initWithContentsOfURI: URI
return [[[self alloc] initWithContentsOfIRI: IRI
encoding: encoding] autorelease];
}
- (instancetype)init
{
if ([self isMemberOfClass: [OFString class]]) {
if ([self isMemberOfClass: [OFString class]] ||
[self isMemberOfClass: [OFMutableString class]]) {
@try {
[self doesNotRecognizeSelector: _cmd];
} @catch (id e) {
[self release];
@throw e;
}
|
| ︙ | | |
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
|
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
|
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
|
encoding: (OFStringEncoding)encoding
{
return [self initWithCString: cString
encoding: encoding
length: strlen(cString)];
}
#ifdef __clang__
/* We intentionally don't call into super, so silence the warning. */
# pragma clang diagnostic push
# pragma clang diagnostic ignored "-Wunknown-pragmas"
# pragma clang diagnostic ignored "-Wobjc-designated-initializers"
#endif
- (instancetype)initWithCString: (const char *)cString
encoding: (OFStringEncoding)encoding
length: (size_t)cStringLength
{
OF_INVALID_INIT_METHOD
}
#ifdef __clang__
# pragma clang diagnostic pop
#endif
- (instancetype)initWithData: (OFData *)data
encoding: (OFStringEncoding)encoding
{
@try {
if (data.itemSize != 1)
@throw [OFInvalidArgumentException exception];
} @catch (id e) {
[self release];
@throw e;
}
self = [self initWithCString: data.items
encoding: encoding
length: data.count];
return self;
}
#ifdef __clang__
/* We intentionally don't call into super, so silence the warning. */
# pragma clang diagnostic push
# pragma clang diagnostic ignored "-Wunknown-pragmas"
# pragma clang diagnostic ignored "-Wobjc-designated-initializers"
#endif
- (instancetype)initWithString: (OFString *)string
{
OF_INVALID_INIT_METHOD
}
- (instancetype)initWithCharacters: (const OFUnichar *)string
length: (size_t)length
{
OF_INVALID_INIT_METHOD
}
#ifdef __clang__
# pragma clang diagnostic pop
#endif
- (instancetype)initWithUTF16String: (const OFChar16 *)string
{
return [self initWithUTF16String: string
length: OFUTF16StringLength(string)
byteOrder: OFByteOrderNative];
}
|
| ︙ | | |
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
|
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
|
+
+
+
+
+
+
+
+
+
|
byteOrder: (OFByteOrder)byteOrder
{
return [self initWithUTF16String: string
length: OFUTF16StringLength(string)
byteOrder: byteOrder];
}
#ifdef __clang__
/* We intentionally don't call into super, so silence the warning. */
# pragma clang diagnostic push
# pragma clang diagnostic ignored "-Wunknown-pragmas"
# pragma clang diagnostic ignored "-Wobjc-designated-initializers"
#endif
- (instancetype)initWithUTF16String: (const OFChar16 *)string
length: (size_t)length
byteOrder: (OFByteOrder)byteOrder
{
OF_INVALID_INIT_METHOD
}
#ifdef __clang__
# pragma clang diagnostic pop
#endif
- (instancetype)initWithUTF32String: (const OFChar32 *)string
{
return [self initWithUTF32String: string
length: OFUTF32StringLength(string)
byteOrder: OFByteOrderNative];
}
|
| ︙ | | |
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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
|
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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
|
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
+
-
-
-
+
-
-
-
-
-
-
-
-
-
+
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
-
-
-
-
+
+
+
-
-
+
-
+
-
+
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
|
byteOrder: (OFByteOrder)byteOrder
{
return [self initWithUTF32String: string
length: OFUTF32StringLength(string)
byteOrder: byteOrder];
}
#ifdef __clang__
/* We intentionally don't call into super, so silence the warning. */
# pragma clang diagnostic push
# pragma clang diagnostic ignored "-Wunknown-pragmas"
# pragma clang diagnostic ignored "-Wobjc-designated-initializers"
#endif
- (instancetype)initWithUTF32String: (const OFChar32 *)string
length: (size_t)length
byteOrder: (OFByteOrder)byteOrder
{
OF_INVALID_INIT_METHOD
}
#ifdef __clang__
# pragma clang diagnostic pop
#endif
- (instancetype)initWithFormat: (OFConstantString *)format, ...
{
id ret;
va_list arguments;
va_start(arguments, format);
ret = [self initWithFormat: format arguments: arguments];
va_end(arguments);
return ret;
}
#ifdef __clang__
/* We intentionally don't call into super, so silence the warning. */
# pragma clang diagnostic push
# pragma clang diagnostic ignored "-Wunknown-pragmas"
# pragma clang diagnostic ignored "-Wobjc-designated-initializers"
#endif
- (instancetype)initWithFormat: (OFConstantString *)format
arguments: (va_list)arguments
{
OF_INVALID_INIT_METHOD
}
#ifdef __clang__
# pragma clang diagnostic pop
#endif
#ifdef OF_HAVE_FILES
- (instancetype)initWithContentsOfFile: (OFString *)path
{
return [self initWithContentsOfFile: path
encoding: OFStringEncodingUTF8];
}
- (instancetype)initWithContentsOfFile: (OFString *)path
encoding: (OFStringEncoding)encoding
{
char *buffer = NULL;
OFStreamOffset fileSize;
@try {
void *pool = objc_autoreleasePoolPush();
void *pool = objc_autoreleasePoolPush();
OFFile *file = [OFFile fileWithPath: path mode: @"r"];
fileSize = [file seekToOffset: 0 whence: OFSeekEnd];
OFIRI *IRI;
if (fileSize < 0 || (unsigned long long)fileSize > SIZE_MAX)
@throw [OFOutOfRangeException exception];
/*
* We need one extra byte for the terminating zero if we want
* to use -[initWithUTF8StringNoCopy:length:freeWhenDone:].
*/
if (SIZE_MAX - (size_t)fileSize < 1)
@throw [OFOutOfRangeException exception];
@try {
[file seekToOffset: 0 whence: OFSeekSet];
IRI = [OFIRI fileIRIWithPath: path];
buffer = OFAllocMemory((size_t)fileSize + 1, 1);
[file readIntoBuffer: buffer exactLength: (size_t)fileSize];
buffer[(size_t)fileSize] = '\0';
objc_autoreleasePoolPop(pool);
} @catch (id e) {
OFFreeMemory(buffer);
[self release];
@throw e;
}
if (encoding == OFStringEncodingUTF8) {
@try {
self = [self initWithUTF8StringNoCopy: buffer
length: (size_t)fileSize
freeWhenDone: true];
} @catch (id e) {
OFFreeMemory(buffer);
@throw e;
}
} else {
@try {
self = [self initWithCString: buffer
self = [self initWithContentsOfIRI: IRI encoding: encoding];
encoding: encoding
length: (size_t)fileSize];
} @finally {
OFFreeMemory(buffer);
}
}
objc_autoreleasePoolPop(pool);
return self;
}
#endif
- (instancetype)initWithContentsOfURI: (OFURI *)URI
- (instancetype)initWithContentsOfIRI: (OFIRI *)IRI
{
return [self initWithContentsOfURI: URI
return [self initWithContentsOfIRI: IRI
encoding: OFStringEncodingAutodetect];
}
- (instancetype)initWithContentsOfURI: (OFURI *)URI
- (instancetype)initWithContentsOfIRI: (OFIRI *)IRI
encoding: (OFStringEncoding)encoding
{
void *pool = objc_autoreleasePoolPush();
OFData *data;
@try {
data = [OFData dataWithContentsOfURI: URI];
data = [OFData dataWithContentsOfIRI: IRI];
} @catch (id e) {
[self release];
@throw e;
}
/* FIXME: Detect encoding where we can. */
if (encoding == OFStringEncodingAutodetect)
encoding = OFStringEncodingUTF8;
self = [self initWithCString: data.items
encoding: encoding
length: data.count * data.itemSize];
objc_autoreleasePoolPop(pool);
return self;
}
- (instancetype)initWithSerialization: (OFXMLElement *)element
{
void *pool = objc_autoreleasePoolPush();
OFString *stringValue;
@try {
if (![element.namespace isEqual: OFSerializationNS])
@throw [OFInvalidArgumentException exception];
if ([self isKindOfClass: [OFMutableString class]]) {
if (![element.name isEqual: @"OFMutableString"])
@throw [OFInvalidArgumentException exception];
} else {
if (![element.name isEqual: @"OFString"])
@throw [OFInvalidArgumentException exception];
}
stringValue = element.stringValue;
} @catch (id e) {
[self release];
@throw e;
}
self = [self initWithString: stringValue];
objc_autoreleasePoolPop(pool);
return self;
}
- (size_t)of_getCString: (char *)cString
maxLength: (size_t)maxLength
|
| ︙ | | |
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
|
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
|
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
|
}
- (OFString *)description
{
return [[self copy] autorelease];
}
- (OFXMLElement *)XMLElementBySerializing
{
void *pool = objc_autoreleasePoolPush();
OFXMLElement *element;
OFString *className;
if ([self isKindOfClass: [OFMutableString class]])
className = @"OFMutableString";
else
className = @"OFString";
element = [OFXMLElement elementWithName: className
namespace: OFSerializationNS
stringValue: self];
[element retain];
objc_autoreleasePoolPop(pool);
return [element autorelease];
}
- (OFString *)JSONRepresentation
{
return [self of_JSONRepresentationWithOptions: 0 depth: 0];
}
- (OFString *)JSONRepresentationWithOptions:
(OFJSONRepresentationOptions)options
|
| ︙ | | |
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
|
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
|
-
+
-
+
+
+
+
+
|
[stripped caseInsensitiveCompare: @"-INFINITY"] == OFOrderedSame)
return -INFINITY;
if ([stripped caseInsensitiveCompare: @"NAN"] == OFOrderedSame)
return NAN;
if ([stripped caseInsensitiveCompare: @"-NAN"] == OFOrderedSame)
return -NAN;
#ifdef HAVE_STRTOF_L
#if defined(HAVE_STRTOF_L) || defined(HAVE_USELOCALE)
const char *UTF8String = self.UTF8String;
#else
/*
* If we have no strtof_l, we have no other choice but to replace "."
* with the locale's decimal point.
*/
OFString *decimalSeparator = [OFLocale decimalSeparator];
const char *UTF8String = [self
stringByReplacingOccurrencesOfString: @"."
withString: decimalSeparator].UTF8String;
#endif
char *endPtr = NULL;
float value;
errno = 0;
#ifdef HAVE_STRTOF_L
#if defined(HAVE_STRTOF_L)
value = strtof_l(UTF8String, &endPtr, cLocale);
#elif defined(HAVE_USELOCALE)
locale_t previousLocale = uselocale(cLocale);
value = strtof(UTF8String, &endPtr);
uselocale(previousLocale);
#else
value = strtof(UTF8String, &endPtr);
#endif
if (value == HUGE_VALF && errno == ERANGE)
@throw [OFOutOfRangeException exception];
|
| ︙ | | |
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
|
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
|
-
+
-
+
+
+
+
+
|
[stripped caseInsensitiveCompare: @"-INFINITY"] == OFOrderedSame)
return -INFINITY;
if ([stripped caseInsensitiveCompare: @"NAN"] == OFOrderedSame)
return NAN;
if ([stripped caseInsensitiveCompare: @"-NAN"] == OFOrderedSame)
return -NAN;
#ifdef HAVE_STRTOD_L
#if defined(HAVE_STRTOD_L) || defined(HAVE_USELOCALE)
const char *UTF8String = self.UTF8String;
#else
/*
* If we have no strtod_l, we have no other choice but to replace "."
* with the locale's decimal point.
*/
OFString *decimalSeparator = [OFLocale decimalSeparator];
const char *UTF8String = [self
stringByReplacingOccurrencesOfString: @"."
withString: decimalSeparator].UTF8String;
#endif
char *endPtr = NULL;
double value;
errno = 0;
#ifdef HAVE_STRTOD_L
#if defined(HAVE_STRTOD_L)
value = strtod_l(UTF8String, &endPtr, cLocale);
#elif defined(HAVE_USELOCALE)
locale_t previousLocale = uselocale(cLocale);
value = strtod(UTF8String, &endPtr);
uselocale(previousLocale);
#else
value = strtod(UTF8String, &endPtr);
#endif
if (value == HUGE_VAL && errno == ERANGE)
@throw [OFOutOfRangeException exception];
|
| ︙ | | |
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
|
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
|
-
-
-
-
-
-
-
-
-
-
-
-
-
-
|
[data retain];
objc_autoreleasePoolPop(pool);
return [data autorelease];
}
#ifdef OF_HAVE_UNICODE_TABLES
- (OFString *)decomposedStringWithCanonicalMapping
{
return decomposedString(self, OFUnicodeDecompositionTable,
OFUnicodeDecompositionTableSize);
}
- (OFString *)decomposedStringWithCompatibilityMapping
{
return decomposedString(self, OFUnicodeDecompositionCompatTable,
OFUnicodeDecompositionCompatTableSize);
}
#endif
#ifdef OF_WINDOWS
- (OFString *)stringByExpandingWindowsEnvironmentStrings
{
if ([OFSystemInfo isWindowsNT]) {
wchar_t buffer[512];
size_t length;
|
| ︙ | | |
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
|
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
|
-
+
-
+
-
+
-
+
|
void *pool = objc_autoreleasePoolPush();
OFFile *file = [OFFile fileWithPath: path mode: @"w"];
[file writeString: self encoding: encoding];
objc_autoreleasePoolPop(pool);
}
#endif
- (void)writeToURI: (OFURI *)URI
- (void)writeToIRI: (OFIRI *)IRI
{
[self writeToURI: URI encoding: OFStringEncodingUTF8];
[self writeToIRI: IRI encoding: OFStringEncodingUTF8];
}
- (void)writeToURI: (OFURI *)URI encoding: (OFStringEncoding)encoding
- (void)writeToIRI: (OFIRI *)IRI encoding: (OFStringEncoding)encoding
{
void *pool = objc_autoreleasePoolPush();
OFStream *stream;
stream = [OFURIHandler openItemAtURI: URI mode: @"w"];
stream = [OFIRIHandler openItemAtIRI: IRI mode: @"w"];
[stream writeString: self encoding: encoding];
objc_autoreleasePoolPop(pool);
}
#ifdef OF_HAVE_BLOCKS
- (void)enumerateLinesUsingBlock: (OFStringLineEnumerationBlock)block
|
| ︙ | | |