ObjFW  Diff

Differences From Artifact [5a8a220443]:

  • File src/OFString.m — part of check-in [50916b8dbe] at 2013-01-11 12:41:54 on branch trunk — OFString: Improve API for characters / UTF-32.

    With this change, there is a clear separation between characters and
    UTF-32 strings now. Characters are just an array of characters in the
    native endianess, with no BOM prepended. UTF-32 on the other hand may
    have a BOM and can be swapped and is optionally zero-terminated.

    This also fixes a few missing UTF-16 init methods in OFMutableString. (user: js, size: 50023) [annotate] [blame] [check-ins using]

To Artifact [cb1b20524f]:


851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
{
	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)







|







851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
{
	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)
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
		[self release];
		@throw e;
	}

	return self;
}

- (const char*)cStringUsingEncoding: (of_string_encoding_t)encoding
{
	const of_unichar_t *characters = [self characters];
	size_t i, length = [self length];
	OFObject *object = [[[OFObject alloc] init] autorelease];
	char *cString;

	switch (encoding) {







|







985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
		[self release];
		@throw e;
	}

	return self;
}

- (const char*)cStringWithEncoding: (of_string_encoding_t)encoding
{
	const of_unichar_t *characters = [self characters];
	size_t i, length = [self length];
	OFObject *object = [[[OFObject alloc] init] autorelease];
	char *cString;

	switch (encoding) {
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
	}

	return cString;
}

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

- (size_t)length
{
	[self doesNotRecognizeSelector: _cmd];
	abort();
}

- (size_t)lengthOfBytesUsingEncoding: (of_string_encoding_t)encoding
{
	switch (encoding) {
	case OF_STRING_ENCODING_UTF_8:;
		const of_unichar_t *characters;
		size_t i, length, UTF8StringLength = 0;

		characters = [self characters];







|








|







1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
	}

	return cString;
}

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

- (size_t)length
{
	[self doesNotRecognizeSelector: _cmd];
	abort();
}

- (size_t)cStringLengthWithEncoding: (of_string_encoding_t)encoding
{
	switch (encoding) {
	case OF_STRING_ENCODING_UTF_8:;
		const of_unichar_t *characters;
		size_t i, length, UTF8StringLength = 0;

		characters = [self characters];
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
		    exceptionWithClass: [self class]
			      selector: _cmd];
	}
}

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

- (of_unichar_t)characterAtIndex: (size_t)index
{
	[self doesNotRecognizeSelector: _cmd];
	abort();
}







|







1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
		    exceptionWithClass: [self class]
			      selector: _cmd];
	}
}

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

- (of_unichar_t)characterAtIndex: (size_t)index
{
	[self doesNotRecognizeSelector: _cmd];
	abort();
}