ObjFW  Diff

Differences From Artifact [62af83b584]:

To Artifact [fb6ee6e76b]:


147
148
149
150
151
152
153
154

155
156
157
158

159
160

161
162
163
164

165
166

167
168

169
170
171

172
173
174
175
176
177
178
147
148
149
150
151
152
153

154
155
156
157

158
159

160
161
162
163

164
165

166
167

168
169
170

171
172
173
174
175
176
177
178







-
+



-
+

-
+



-
+

-
+

-
+


-
+








	return isUTF8;
}

size_t
of_string_utf8_get_index(const char *string, size_t position)
{
	size_t index = position;
	size_t idx = position;

	for (size_t i = 0; i < position; i++)
		if OF_UNLIKELY ((string[i] & 0xC0) == 0x80)
			index--;
			idx--;

	return index;
	return idx;
}

size_t
of_string_utf8_get_position(const char *string, size_t index, size_t length)
of_string_utf8_get_position(const char *string, size_t idx, size_t length)
{
	for (size_t i = 0; i <= index; i++)
	for (size_t i = 0; i <= idx; i++)
		if OF_UNLIKELY ((string[i] & 0xC0) == 0x80)
			if (++index > length)
			if (++idx > length)
				return OF_NOT_FOUND;

	return index;
	return idx;
}

@implementation OFString_UTF8
- init
{
	self = [super init];

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
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







-
+



-
+



-
+

-
+
-

-
-
+
+








	_s->hash = hash;
	_s->hashed = true;

	return hash;
}

- (of_unichar_t)characterAtIndex: (size_t)index
- (of_unichar_t)characterAtIndex: (size_t)idx
{
	of_unichar_t character;

	if (index >= _s->length)
	if (idx >= _s->length)
		@throw [OFOutOfRangeException exception];

	if (!_s->isUTF8)
		return _s->cString[index];
		return _s->cString[idx];

	index = of_string_utf8_get_position(_s->cString, index,
	idx = of_string_utf8_get_position(_s->cString, idx, _s->cStringLength);
	    _s->cStringLength);

	if (of_string_utf8_decode(_s->cString + index,
	    _s->cStringLength - index, &character) <= 0)
	if (of_string_utf8_decode(_s->cString + idx,
	    _s->cStringLength - idx, &character) <= 0)
		@throw [OFInvalidEncodingException exception];

	return character;
}

- (void)getCharacters: (of_unichar_t *)buffer
	      inRange: (of_range_t)range