ObjFW  Diff

Differences From Artifact [712053e8f6]:

To Artifact [10b3048cbe]:


686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
{
	char *tmp;
	struct stat st;

	@try {
		OFFile *file;

		if (stat([path cStringWithEncoding: OF_STRING_ENCODING_NATIVE],
		    &st) == -1)
			@throw [OFOpenFileFailedException
			    exceptionWithClass: [self class]
					  path: path
					  mode: @"rb"];

		if (st.st_size > SIZE_MAX)







|







686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
{
	char *tmp;
	struct stat st;

	@try {
		OFFile *file;

		if (stat([path cStringUsingEncoding: OF_STRING_ENCODING_NATIVE],
		    &st) == -1)
			@throw [OFOpenFileFailedException
			    exceptionWithClass: [self class]
					  path: path
					  mode: @"rb"];

		if (st.st_size > SIZE_MAX)
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834








835
836

837
838
839
840
841
842
843
		[self release];
		@throw e;
	}

	return self;
}

- (const char*)UTF8String
{
	const of_unichar_t *unicodeString = [self unicodeString];
	char *UTF8String;
	size_t i, j = 0, length = [self length];
	size_t UTF8StringLength = length;
	OFObject *object;









	object = [[[OFObject alloc] init] autorelease];
	UTF8String = [object allocMemoryWithSize: (length * 4) + 1];


	for (i = 0; i < length; i++) {
		char buffer[4];
		size_t len = of_string_utf8_encode(unicodeString[i], buffer);

		switch (len) {
		case 1:







|



|
<


>
>
>
>
>
>
>
>


>







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
		[self release];
		@throw e;
	}

	return self;
}

- (const char*)cStringUsingEncoding: (of_string_encoding_t)encoding
{
	const of_unichar_t *unicodeString = [self unicodeString];
	char *UTF8String;
	size_t i, j = 0, length, UTF8StringLength;

	OFObject *object;

	if (encoding != OF_STRING_ENCODING_UTF_8)
		/* TODO: Implement! */
		@throw [OFNotImplementedException
		    exceptionWithClass: [self class]
			      selector: _cmd];

	unicodeString = [self unicodeString];
	length = [self length];
	object = [[[OFObject alloc] init] autorelease];
	UTF8String = [object allocMemoryWithSize: (length * 4) + 1];
	UTF8StringLength = length;

	for (i = 0; i < length; i++) {
		char buffer[4];
		size_t len = of_string_utf8_encode(unicodeString[i], buffer);

		switch (len) {
		case 1:
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
	} @catch (OFOutOfMemoryException *e) {
		/* We don't care, as we only tried to make it smaller */
	}

	return UTF8String;
}

- (const char*)cStringWithEncoding: (of_string_encoding_t)encoding
{
	if (encoding == OF_STRING_ENCODING_UTF_8)
		return [self UTF8String];

	/* TODO: Implement! */
	@throw [OFNotImplementedException exceptionWithClass: [self class]
						    selector: _cmd];
}

- (size_t)length
{
	@throw [OFNotImplementedException exceptionWithClass: [self class]
						    selector: _cmd];
}




- (size_t)UTF8StringLength
{






	const of_unichar_t *unicodeString = [self unicodeString];
	size_t length = [self length];
	size_t i, UTF8StringLength = 0;

	for (i = 0; i < length; i++) {
		char buffer[4];
		size_t len = of_string_utf8_encode(unicodeString[i], buffer);

		if (len == 0)
			@throw [OFInvalidEncodingException
			    exceptionWithClass: [self class]];

		UTF8StringLength += len;
	}

	return UTF8StringLength;
}

- (size_t)cStringLengthWithEncoding: (of_string_encoding_t)encoding
{
	if (encoding == OF_STRING_ENCODING_UTF_8)
		return [self UTF8StringLength];

	/* TODO: Implement! */
	@throw [OFNotImplementedException exceptionWithClass: [self class]
						    selector: _cmd];
}

- (of_unichar_t)characterAtIndex: (size_t)index
{
	@throw [OFNotImplementedException exceptionWithClass: [self class]
						    selector: _cmd];
}







|

|
<
<
<
<
<








>
>
>
|
|
>
>
>
>
>
>
|
|
<















|

|
<
<
<
<
<







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
	} @catch (OFOutOfMemoryException *e) {
		/* We don't care, as we only tried to make it smaller */
	}

	return UTF8String;
}

- (const char*)UTF8String
{
	return [self cStringUsingEncoding: OF_STRING_ENCODING_UTF_8];





}

- (size_t)length
{
	@throw [OFNotImplementedException exceptionWithClass: [self class]
						    selector: _cmd];
}

- (size_t)lengthOfBytesUsingEncoding: (of_string_encoding_t)encoding
{
	const of_unichar_t *unicodeString;
	size_t i, length, UTF8StringLength = 0;

	if (encoding != OF_STRING_ENCODING_UTF_8)
		/* TODO: Implement! */
		@throw [OFNotImplementedException
		    exceptionWithClass: [self class]
			      selector: _cmd];

	unicodeString = [self unicodeString];
	length = [self length];


	for (i = 0; i < length; i++) {
		char buffer[4];
		size_t len = of_string_utf8_encode(unicodeString[i], buffer);

		if (len == 0)
			@throw [OFInvalidEncodingException
			    exceptionWithClass: [self class]];

		UTF8StringLength += len;
	}

	return UTF8StringLength;
}

- (size_t)UTF8StringLength
{
	return [self lengthOfBytesUsingEncoding: OF_STRING_ENCODING_UTF_8];





}

- (of_unichar_t)characterAtIndex: (size_t)index
{
	@throw [OFNotImplementedException exceptionWithClass: [self class]
						    selector: _cmd];
}