1
2
3
4
5
6
7
8
9
|
/*
* Copyright (c) 2008-2022 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.
*
|
|
|
1
2
3
4
5
6
7
8
9
|
/*
* Copyright (c) 2008-2023 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
|
#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)
# 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 "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"
|
|
>
>
<
<
<
|
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) || 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 "OFUTF8String.h"
#import "OFUTF8String+Private.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
|
# define INFINITY __builtin_inf()
#endif
static struct {
Class isa;
} placeholder;
#if defined(HAVE_STRTOF_L) || defined(HAVE_STRTOD_L)
static locale_t cLocale;
#endif
@interface OFString ()
- (size_t)of_getCString: (char *)cString
maxLength: (size_t)maxLength
encoding: (OFStringEncoding)encoding
|
|
|
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
|
# define INFINITY __builtin_inf()
#endif
static struct {
Class isa;
} placeholder;
#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
|
︙ | | | ︙ | |
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
|
_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)
{
|
<
|
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_XMLEscaping_reference = 1;
_OFString_XMLUnescaping_reference = 1;
}
void
_reference_to_OFConstantString(void)
{
|
︙ | | | ︙ | |
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
|
encoding: (OFStringEncoding)encoding
{
return (id)[[OFUTF8String alloc] initWithContentsOfFile: path
encoding: encoding];
}
#endif
- (instancetype)initWithContentsOfURI: (OFURI *)URI
{
return (id)[[OFUTF8String alloc] initWithContentsOfURI: URI];
}
- (instancetype)initWithContentsOfURI: (OFURI *)URI
encoding: (OFStringEncoding)encoding
{
return (id)[[OFUTF8String alloc] initWithContentsOfURI: URI
encoding: encoding];
}
- (instancetype)initWithSerialization: (OFXMLElement *)element
{
return (id)[[OFUTF8String alloc] initWithSerialization: element];
}
- (instancetype)retain
{
return self;
}
- (instancetype)autorelease
{
|
|
|
|
|
<
<
<
<
<
|
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
|
encoding: (OFStringEncoding)encoding
{
return (id)[[OFUTF8String alloc] initWithContentsOfFile: path
encoding: encoding];
}
#endif
- (instancetype)initWithContentsOfIRI: (OFIRI *)IRI
{
return (id)[[OFUTF8String alloc] initWithContentsOfIRI: IRI];
}
- (instancetype)initWithContentsOfIRI: (OFIRI *)IRI
encoding: (OFStringEncoding)encoding
{
return (id)[[OFUTF8String alloc] initWithContentsOfIRI: IRI
encoding: encoding];
}
- (instancetype)retain
{
return self;
}
- (instancetype)autorelease
{
|
︙ | | | ︙ | |
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
|
+ (void)initialize
{
if (self != [OFString class])
return;
placeholder.isa = [OFStringPlaceholder class];
#if defined(HAVE_STRTOF_L) || defined(HAVE_STRTOD_L)
if ((cLocale = newlocale(LC_ALL_MASK, "C", NULL)) == NULL)
@throw [OFInitializationFailedException
exceptionWithClass: self];
#endif
}
+ (instancetype)alloc
|
|
|
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
|
+ (void)initialize
{
if (self != [OFString class])
return;
placeholder.isa = [OFStringPlaceholder class];
#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
|
encoding: (OFStringEncoding)encoding
{
return [[[self alloc] initWithContentsOfFile: path
encoding: encoding] autorelease];
}
#endif
+ (instancetype)stringWithContentsOfURI: (OFURI *)URI
{
return [[[self alloc] initWithContentsOfURI: URI] autorelease];
}
+ (instancetype)stringWithContentsOfURI: (OFURI *)URI
encoding: (OFStringEncoding)encoding
{
return [[[self alloc] initWithContentsOfURI: URI
encoding: encoding] autorelease];
}
- (instancetype)init
{
if ([self isMemberOfClass: [OFString class]]) {
@try {
|
|
|
|
|
|
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
|
encoding: (OFStringEncoding)encoding
{
return [[[self alloc] initWithContentsOfFile: path
encoding: encoding] autorelease];
}
#endif
+ (instancetype)stringWithContentsOfIRI: (OFIRI *)IRI
{
return [[[self alloc] initWithContentsOfIRI: IRI] autorelease];
}
+ (instancetype)stringWithContentsOfIRI: (OFIRI *)IRI
encoding: (OFStringEncoding)encoding
{
return [[[self alloc] initWithContentsOfIRI: IRI
encoding: encoding] autorelease];
}
- (instancetype)init
{
if ([self isMemberOfClass: [OFString class]]) {
@try {
|
︙ | | | ︙ | |
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
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
|
return [self initWithContentsOfFile: path
encoding: OFStringEncodingUTF8];
}
- (instancetype)initWithContentsOfFile: (OFString *)path
encoding: (OFStringEncoding)encoding
{
char *tmp;
unsigned long long fileSize;
@try {
void *pool = objc_autoreleasePoolPush();
OFFile *file = nil;
@try {
fileSize = [[OFFileManager defaultManager]
attributesOfItemAtPath: path].fileSize;
} @catch (OFGetItemAttributesFailedException *e) {
@throw [OFOpenItemFailedException
exceptionWithPath: path
mode: @"r"
errNo: e.errNo];
}
objc_autoreleasePoolPop(pool);
# if ULLONG_MAX > SIZE_MAX
if (fileSize > SIZE_MAX)
@throw [OFOutOfRangeException exception];
#endif
/*
* 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];
tmp = OFAllocMemory((size_t)fileSize + 1, 1);
@try {
file = [[OFFile alloc] initWithPath: path mode: @"r"];
[file readIntoBuffer: tmp
exactLength: (size_t)fileSize];
} @catch (id e) {
OFFreeMemory(tmp);
@throw e;
} @finally {
[file release];
}
tmp[(size_t)fileSize] = '\0';
} @catch (id e) {
[self release];
@throw e;
}
if (encoding == OFStringEncodingUTF8) {
@try {
self = [self initWithUTF8StringNoCopy: tmp
length: (size_t)fileSize
freeWhenDone: true];
} @catch (id e) {
OFFreeMemory(tmp);
@throw e;
}
} else {
@try {
self = [self initWithCString: tmp
encoding: encoding
length: (size_t)fileSize];
} @finally {
OFFreeMemory(tmp);
}
}
return self;
}
#endif
- (instancetype)initWithContentsOfURI: (OFURI *)URI
{
return [self initWithContentsOfURI: URI
encoding: OFStringEncodingAutodetect];
}
- (instancetype)initWithContentsOfURI: (OFURI *)URI
encoding: (OFStringEncoding)encoding
{
void *pool = objc_autoreleasePoolPush();
OFData *data;
@try {
data = [OFData dataWithContentsOfURI: URI];
} @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
|
|
|
|
|
<
<
<
<
<
<
<
<
|
<
<
<
<
|
<
>
>
|
<
<
|
|
>
>
|
|
<
<
|
|
<
<
<
<
|
|
|
|
|
|
|
|
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
|
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
|
return [self initWithContentsOfFile: path
encoding: OFStringEncodingUTF8];
}
- (instancetype)initWithContentsOfFile: (OFString *)path
encoding: (OFStringEncoding)encoding
{
char *buffer = NULL;
OFStreamOffset fileSize;
@try {
void *pool = objc_autoreleasePoolPush();
OFFile *file = [OFFile fileWithPath: path mode: @"r"];
fileSize = [file seekToOffset: 0 whence: OFSeekEnd];
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];
[file seekToOffset: 0 whence: OFSeekSet];
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
encoding: encoding
length: (size_t)fileSize];
} @finally {
OFFreeMemory(buffer);
}
}
return self;
}
#endif
- (instancetype)initWithContentsOfIRI: (OFIRI *)IRI
{
return [self initWithContentsOfIRI: IRI
encoding: OFStringEncodingAutodetect];
}
- (instancetype)initWithContentsOfIRI: (OFIRI *)IRI
encoding: (OFStringEncoding)encoding
{
void *pool = objc_autoreleasePoolPush();
OFData *data;
@try {
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;
}
- (size_t)of_getCString: (char *)cString
maxLength: (size_t)maxLength
|
︙ | | | ︙ | |
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
|
}
- (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
|
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
|
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
|
}
- (OFString *)description
{
return [[self copy] autorelease];
}
- (OFString *)JSONRepresentation
{
return [self of_JSONRepresentationWithOptions: 0 depth: 0];
}
- (OFString *)JSONRepresentationWithOptions:
(OFJSONRepresentationOptions)options
|
︙ | | | ︙ | |
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
|
[stripped caseInsensitiveCompare: @"-INFINITY"] == OFOrderedSame)
return -INFINITY;
if ([stripped caseInsensitiveCompare: @"NAN"] == OFOrderedSame)
return NAN;
if ([stripped caseInsensitiveCompare: @"-NAN"] == OFOrderedSame)
return -NAN;
#ifdef HAVE_STRTOF_L
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
value = strtof_l(UTF8String, &endPtr, cLocale);
#else
value = strtof(UTF8String, &endPtr);
#endif
if (value == HUGE_VALF && errno == ERANGE)
@throw [OFOutOfRangeException exception];
|
|
|
>
>
>
>
|
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
|
[stripped caseInsensitiveCompare: @"-INFINITY"] == OFOrderedSame)
return -INFINITY;
if ([stripped caseInsensitiveCompare: @"NAN"] == OFOrderedSame)
return NAN;
if ([stripped caseInsensitiveCompare: @"-NAN"] == OFOrderedSame)
return -NAN;
#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;
#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];
|
︙ | | | ︙ | |
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
|
[stripped caseInsensitiveCompare: @"-INFINITY"] == OFOrderedSame)
return -INFINITY;
if ([stripped caseInsensitiveCompare: @"NAN"] == OFOrderedSame)
return NAN;
if ([stripped caseInsensitiveCompare: @"-NAN"] == OFOrderedSame)
return -NAN;
#ifdef HAVE_STRTOD_L
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
value = strtod_l(UTF8String, &endPtr, cLocale);
#else
value = strtod(UTF8String, &endPtr);
#endif
if (value == HUGE_VAL && errno == ERANGE)
@throw [OFOutOfRangeException exception];
|
|
|
>
>
>
>
|
2420
2421
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
2454
2455
|
[stripped caseInsensitiveCompare: @"-INFINITY"] == OFOrderedSame)
return -INFINITY;
if ([stripped caseInsensitiveCompare: @"NAN"] == OFOrderedSame)
return NAN;
if ([stripped caseInsensitiveCompare: @"-NAN"] == OFOrderedSame)
return -NAN;
#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;
#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];
|
︙ | | | ︙ | |
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
|
void *pool = objc_autoreleasePoolPush();
OFFile *file = [OFFile fileWithPath: path mode: @"w"];
[file writeString: self encoding: encoding];
objc_autoreleasePoolPop(pool);
}
#endif
- (void)writeToURI: (OFURI *)URI
{
[self writeToURI: URI encoding: OFStringEncodingUTF8];
}
- (void)writeToURI: (OFURI *)URI encoding: (OFStringEncoding)encoding
{
void *pool = objc_autoreleasePoolPush();
OFStream *stream;
stream = [OFURIHandler openItemAtURI: URI mode: @"w"];
[stream writeString: self encoding: encoding];
objc_autoreleasePoolPop(pool);
}
#ifdef OF_HAVE_BLOCKS
- (void)enumerateLinesUsingBlock: (OFStringLineEnumerationBlock)block
|
|
|
|
|
|
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
|
void *pool = objc_autoreleasePoolPush();
OFFile *file = [OFFile fileWithPath: path mode: @"w"];
[file writeString: self encoding: encoding];
objc_autoreleasePoolPop(pool);
}
#endif
- (void)writeToIRI: (OFIRI *)IRI
{
[self writeToIRI: IRI encoding: OFStringEncodingUTF8];
}
- (void)writeToIRI: (OFIRI *)IRI encoding: (OFStringEncoding)encoding
{
void *pool = objc_autoreleasePoolPush();
OFStream *stream;
stream = [OFIRIHandler openItemAtIRI: IRI mode: @"w"];
[stream writeString: self encoding: encoding];
objc_autoreleasePoolPop(pool);
}
#ifdef OF_HAVE_BLOCKS
- (void)enumerateLinesUsingBlock: (OFStringLineEnumerationBlock)block
|
︙ | | | ︙ | |