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
|
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
|
-
-
-
-
-
-
-
+
-
-
-
-
+
-
-
-
-
-
-
+
+
-
-
-
-
-
-
|
}
- initWithString: (OFString*)string
{
self = [super init];
@try {
const char *cString;
s = [self allocMemoryWithSize: sizeof(*s)];
memset(s, 0, sizeof(*s));
cString = [string cString];
s->cStringLength = [string cStringLength];
switch (of_string_check_utf8(cString, s->cStringLength)) {
case 1:
s->isUTF8 = YES;
s->isUTF8 = string->s->isUTF8;
break;
case -1:;
@throw [OFInvalidEncodingException newWithClass: isa];
}
if ((s->cString = strdup(cString)) == NULL)
@throw [OFOutOfMemoryException
newWithClass: isa
requestedSize: s->cStringLength + 1];
s->cString = [self allocMemoryWithSize: s->cStringLength + 1];
memcpy(s->cString, [string cString], s->cStringLength + 1);
@try {
[self addMemoryToPool: s->cString];
} @catch (id e) {
free(s->cString);
@throw e;
}
} @catch (id e) {
[self release];
@throw e;
}
return self;
}
|