ObjFW  Diff

Differences From Artifact [c3f91002a4]:

To Artifact [b097e022e5]:


136
137
138
139
140
141
142
143
144


145
146
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
179
180
181
136
137
138
139
140
141
142


143
144
145
146
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

179
180
181
182
183
184
185
186







-
-
+
+



-
-
+
+
+
+



-
+

-
+
+




-
+

-
+

+




-
+

-
+

+


-
+







		buf[i] = 0x80 | (c & 0x3F);
		return 4;
	}

	return 0;
}

of_unichar_t
of_string_utf8_to_unicode(const char *buf_, size_t len)
size_t
of_string_utf8_to_unicode(const char *buf_, size_t len, of_unichar_t *ret)
{
	const uint8_t *buf = (const uint8_t*)buf_;

	if (!(*buf & 0x80))
		return buf[0];
	if (!(*buf & 0x80)) {
		*ret = buf[0];
		return 1;
	}

	if ((*buf & 0xE0) == 0xC0) {
		if (OF_UNLIKELY(len < 2))
			return OF_INVALID_UNICHAR;
			return 0;

		return ((buf[0] & 0x1F) << 6) | (buf[1] & 0x3F);
		*ret = ((buf[0] & 0x1F) << 6) | (buf[1] & 0x3F);
		return 2;
	}

	if ((*buf & 0xF0) == 0xE0) {
		if (OF_UNLIKELY(len < 3))
			return OF_INVALID_UNICHAR;
			return 0;

		return ((buf[0] & 0x0F) << 12) | ((buf[1] & 0x3F) << 6) |
		*ret = ((buf[0] & 0x0F) << 12) | ((buf[1] & 0x3F) << 6) |
		    (buf[2] & 0x3F);
		return 3;
	}

	if ((*buf & 0xF8) == 0xF0) {
		if (OF_UNLIKELY(len < 4))
			return OF_INVALID_UNICHAR;
			return 0;

		return ((buf[0] & 0x07) << 18) | ((buf[1] & 0x3F) << 12) |
		*ret = ((buf[0] & 0x07) << 18) | ((buf[1] & 0x3F) << 12) |
		    ((buf[2] & 0x3F) << 6) | (buf[3] & 0x3F);
		return 4;
	}

	return OF_INVALID_UNICHAR;
	return 0;
}

size_t
of_string_position_to_index(const char *str, size_t pos)
{
	size_t i, idx = pos;

611
612
613
614
615
616
617
618

619
620
621
622
623
624
625
626
616
617
618
619
620
621
622

623

624
625
626
627
628
629
630







-
+
-







	of_unichar_t c;

	index = of_string_index_to_position(string, index, length);

	if (index >= length)
		@throw [OFOutOfRangeException newWithClass: isa];

	if ((c = of_string_utf8_to_unicode(string + index, length - index)) ==
	if (!of_string_utf8_to_unicode(string + index, length - index, &c))
	    OF_INVALID_UNICHAR)
		@throw [OFInvalidEncodingException newWithClass: isa];

	return c;
}

- (size_t)indexOfFirstOccurrenceOfString: (OFString*)str
{