VirtualBox

source: vbox/trunk/src/VBox/Devices/EFI/Firmware/VBoxPkg/VBoxFsDxe/fsw_strfunc.h

Last change on this file was 98103, checked in by vboxsync, 16 months ago

Copyright year updates by scm.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 13.4 KB
Line 
1/* $Id: fsw_strfunc.h 98103 2023-01-17 14:15:46Z vboxsync $ */
2/** @file
3 * fsw_strfunc.h
4 */
5
6/*
7 * Copyright (C) 2010-2023 Oracle and/or its affiliates.
8 *
9 * This file is part of VirtualBox base platform packages, as
10 * available from https://www.virtualbox.org.
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation, in version 3 of the
15 * License.
16 *
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, see <https://www.gnu.org/licenses>.
24 *
25 * The contents of this file may alternatively be used under the terms
26 * of the Common Development and Distribution License Version 1.0
27 * (CDDL), a copy of it is provided in the "COPYING.CDDL" file included
28 * in the VirtualBox distribution, in which case the provisions of the
29 * CDDL are applicable instead of those of the GPL.
30 *
31 * You may elect to license modified versions of this file under the
32 * terms and conditions of either the GPL or the CDDL or both.
33 *
34 * SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0
35 */
36
37/* fsw_strfunc.h generated by mk_fsw_strfunc.py */
38
39static int fsw_streq_ISO88591_UTF8(void *s1data, void *s2data, int len)
40{
41 int i;
42 fsw_u8 *p1 = (fsw_u8 *)s1data;
43 fsw_u8 *p2 = (fsw_u8 *)s2data;
44 fsw_u32 c1, c2;
45
46 for (i = 0; i < len; i++) {
47 c1 = *p1++;
48 c2 = *p2++;
49 if ((c2 & 0xe0) == 0xc0) {
50 c2 = ((c2 & 0x1f) << 6) | (*p2++ & 0x3f);
51 } else if ((c2 & 0xf0) == 0xe0) {
52 c2 = ((c2 & 0x0f) << 12) | ((*p2++ & 0x3f) << 6);
53 c2 |= (*p2++ & 0x3f);
54 } else if ((c2 & 0xf8) == 0xf0) {
55 c2 = ((c2 & 0x07) << 18) | ((*p2++ & 0x3f) << 12);
56 c2 |= ((*p2++ & 0x3f) << 6);
57 c2 |= (*p2++ & 0x3f);
58 }
59 if (c1 != c2)
60 return 0;
61 }
62 return 1;
63}
64
65#ifndef HOST_EFI
66static int fsw_streq_ISO88591_UTF16(void *s1data, void *s2data, int len)
67{
68 int i;
69 fsw_u8 *p1 = (fsw_u8 *)s1data;
70 fsw_u16 *p2 = (fsw_u16 *)s2data;
71 fsw_u32 c1, c2;
72
73 for (i = 0; i < len; i++) {
74 c1 = *p1++;
75 c2 = *p2++;
76 if (c1 != c2)
77 return 0;
78 }
79 return 1;
80}
81#endif
82
83static int fsw_streq_ISO88591_UTF16_SWAPPED(void *s1data, void *s2data, int len)
84{
85 int i;
86 fsw_u8 *p1 = (fsw_u8 *)s1data;
87 fsw_u16 *p2 = (fsw_u16 *)s2data;
88 fsw_u32 c1, c2;
89
90 for (i = 0; i < len; i++) {
91 c1 = *p1++;
92 c2 = *p2++; c2 = FSW_SWAPVALUE_U16(c2);
93 if (c1 != c2)
94 return 0;
95 }
96 return 1;
97}
98
99static int fsw_streq_UTF8_UTF16(void *s1data, void *s2data, int len)
100{
101 int i;
102 fsw_u8 *p1 = (fsw_u8 *)s1data;
103 fsw_u16 *p2 = (fsw_u16 *)s2data;
104 fsw_u32 c1, c2;
105
106 for (i = 0; i < len; i++) {
107 c1 = *p1++;
108 if ((c1 & 0xe0) == 0xc0) {
109 c1 = ((c1 & 0x1f) << 6) | (*p1++ & 0x3f);
110 } else if ((c1 & 0xf0) == 0xe0) {
111 c1 = ((c1 & 0x0f) << 12) | ((*p1++ & 0x3f) << 6);
112 c1 |= (*p1++ & 0x3f);
113 } else if ((c1 & 0xf8) == 0xf0) {
114 c1 = ((c1 & 0x07) << 18) | ((*p1++ & 0x3f) << 12);
115 c1 |= ((*p1++ & 0x3f) << 6);
116 c1 |= (*p1++ & 0x3f);
117 }
118 c2 = *p2++;
119 if (c1 != c2)
120 return 0;
121 }
122 return 1;
123}
124
125static int fsw_streq_UTF8_UTF16_SWAPPED(void *s1data, void *s2data, int len)
126{
127 int i;
128 fsw_u8 *p1 = (fsw_u8 *)s1data;
129 fsw_u16 *p2 = (fsw_u16 *)s2data;
130 fsw_u32 c1, c2;
131
132 for (i = 0; i < len; i++) {
133 c1 = *p1++;
134 if ((c1 & 0xe0) == 0xc0) {
135 c1 = ((c1 & 0x1f) << 6) | (*p1++ & 0x3f);
136 } else if ((c1 & 0xf0) == 0xe0) {
137 c1 = ((c1 & 0x0f) << 12) | ((*p1++ & 0x3f) << 6);
138 c1 |= (*p1++ & 0x3f);
139 } else if ((c1 & 0xf8) == 0xf0) {
140 c1 = ((c1 & 0x07) << 18) | ((*p1++ & 0x3f) << 12);
141 c1 |= ((*p1++ & 0x3f) << 6);
142 c1 |= (*p1++ & 0x3f);
143 }
144 c2 = *p2++; c2 = FSW_SWAPVALUE_U16(c2);
145 if (c1 != c2)
146 return 0;
147 }
148 return 1;
149}
150
151static int fsw_streq_UTF16_UTF16_SWAPPED(void *s1data, void *s2data, int len)
152{
153 int i;
154 fsw_u16 *p1 = (fsw_u16 *)s1data;
155 fsw_u16 *p2 = (fsw_u16 *)s2data;
156 fsw_u32 c1, c2;
157
158 for (i = 0; i < len; i++) {
159 c1 = *p1++;
160 c2 = *p2++; c2 = FSW_SWAPVALUE_U16(c2);
161 if (c1 != c2)
162 return 0;
163 }
164 return 1;
165}
166
167static fsw_status_t fsw_strcoerce_UTF8_ISO88591(void *srcdata, int srclen, struct fsw_string *dest)
168{
169 fsw_status_t status;
170 int i;
171 fsw_u8 *sp;
172 fsw_u8 *dp;
173 fsw_u32 c;
174
175 dest->type = FSW_STRING_TYPE_ISO88591;
176 dest->len = srclen;
177 dest->size = srclen * sizeof(fsw_u8);
178 status = fsw_alloc(dest->size, &dest->data);
179 if (status)
180 return status;
181
182 sp = (fsw_u8 *)srcdata;
183 dp = (fsw_u8 *)dest->data;
184 for (i = 0; i < srclen; i++) {
185 c = *sp++;
186 if ((c & 0xe0) == 0xc0) {
187 c = ((c & 0x1f) << 6) | (*sp++ & 0x3f);
188 } else if ((c & 0xf0) == 0xe0) {
189 c = ((c & 0x0f) << 12) | ((*sp++ & 0x3f) << 6);
190 c |= (*sp++ & 0x3f);
191 } else if ((c & 0xf8) == 0xf0) {
192 c = ((c & 0x07) << 18) | ((*sp++ & 0x3f) << 12);
193 c |= ((*sp++ & 0x3f) << 6);
194 c |= (*sp++ & 0x3f);
195 }
196 *dp++ = (fsw_u8)c;
197 }
198 return FSW_SUCCESS;
199}
200
201static fsw_status_t fsw_strcoerce_UTF16_ISO88591(void *srcdata, int srclen, struct fsw_string *dest)
202{
203 fsw_status_t status;
204 int i;
205 fsw_u16 *sp;
206 fsw_u8 *dp;
207 fsw_u32 c;
208
209 dest->type = FSW_STRING_TYPE_ISO88591;
210 dest->len = srclen;
211 dest->size = srclen * sizeof(fsw_u8);
212 status = fsw_alloc(dest->size, &dest->data);
213 if (status)
214 return status;
215
216 sp = (fsw_u16 *)srcdata;
217 dp = (fsw_u8 *)dest->data;
218 for (i = 0; i < srclen; i++) {
219 c = *sp++;
220 *dp++ = (fsw_u8)c;
221 }
222 return FSW_SUCCESS;
223}
224
225static fsw_status_t fsw_strcoerce_UTF16_SWAPPED_ISO88591(void *srcdata, int srclen, struct fsw_string *dest)
226{
227 fsw_status_t status;
228 int i;
229 fsw_u16 *sp;
230 fsw_u8 *dp;
231 fsw_u32 c;
232
233 dest->type = FSW_STRING_TYPE_ISO88591;
234 dest->len = srclen;
235 dest->size = srclen * sizeof(fsw_u8);
236 status = fsw_alloc(dest->size, &dest->data);
237 if (status)
238 return status;
239
240 sp = (fsw_u16 *)srcdata;
241 dp = (fsw_u8 *)dest->data;
242 for (i = 0; i < srclen; i++) {
243 c = *sp++; c = FSW_SWAPVALUE_U16(c);
244 *dp++ = (fsw_u8)c;
245 }
246 return FSW_SUCCESS;
247}
248
249static fsw_status_t fsw_strcoerce_ISO88591_UTF16(void *srcdata, int srclen, struct fsw_string *dest)
250{
251 fsw_status_t status;
252 int i;
253 fsw_u8 *sp;
254 fsw_u16 *dp;
255 fsw_u32 c;
256
257 dest->type = FSW_STRING_TYPE_UTF16;
258 dest->len = srclen;
259 dest->size = srclen * sizeof(fsw_u16);
260 status = fsw_alloc(dest->size, &dest->data);
261 if (status)
262 return status;
263
264 sp = (fsw_u8 *)srcdata;
265 dp = (fsw_u16 *)dest->data;
266 for (i = 0; i < srclen; i++) {
267 c = *sp++;
268 *dp++ = (fsw_u16)c;
269 }
270 return FSW_SUCCESS;
271}
272
273static fsw_status_t fsw_strcoerce_UTF8_UTF16(void *srcdata, int srclen, struct fsw_string *dest)
274{
275 fsw_status_t status;
276 int i;
277 fsw_u8 *sp;
278 fsw_u16 *dp;
279 fsw_u32 c;
280
281 dest->type = FSW_STRING_TYPE_UTF16;
282 dest->len = srclen;
283 dest->size = srclen * sizeof(fsw_u16);
284 status = fsw_alloc(dest->size, &dest->data);
285 if (status)
286 return status;
287
288 sp = (fsw_u8 *)srcdata;
289 dp = (fsw_u16 *)dest->data;
290 for (i = 0; i < srclen; i++) {
291 c = *sp++;
292 if ((c & 0xe0) == 0xc0) {
293 c = ((c & 0x1f) << 6) | (*sp++ & 0x3f);
294 } else if ((c & 0xf0) == 0xe0) {
295 c = ((c & 0x0f) << 12) | ((*sp++ & 0x3f) << 6);
296 c |= (*sp++ & 0x3f);
297 } else if ((c & 0xf8) == 0xf0) {
298 c = ((c & 0x07) << 18) | ((*sp++ & 0x3f) << 12);
299 c |= ((*sp++ & 0x3f) << 6);
300 c |= (*sp++ & 0x3f);
301 }
302 *dp++ = (fsw_u16)c;
303 }
304 return FSW_SUCCESS;
305}
306
307static fsw_status_t fsw_strcoerce_UTF16_SWAPPED_UTF16(void *srcdata, int srclen, struct fsw_string *dest)
308{
309 fsw_status_t status;
310 int i;
311 fsw_u16 *sp;
312 fsw_u16 *dp;
313 fsw_u32 c;
314
315 dest->type = FSW_STRING_TYPE_UTF16;
316 dest->len = srclen;
317 dest->size = srclen * sizeof(fsw_u16);
318 status = fsw_alloc(dest->size, &dest->data);
319 if (status)
320 return status;
321
322 sp = (fsw_u16 *)srcdata;
323 dp = (fsw_u16 *)dest->data;
324 for (i = 0; i < srclen; i++) {
325 c = *sp++; c = FSW_SWAPVALUE_U16(c);
326 *dp++ = (fsw_u16)c;
327 }
328 return FSW_SUCCESS;
329}
330
331static fsw_status_t fsw_strcoerce_ISO88591_UTF8(void *srcdata, int srclen, struct fsw_string *dest)
332{
333 fsw_status_t status;
334 int i, destsize;
335 fsw_u8 *sp;
336 fsw_u8 *dp;
337 fsw_u32 c;
338
339 sp = (fsw_u8 *)srcdata;
340 destsize = 0;
341 for (i = 0; i < srclen; i++) {
342 c = *sp++;
343
344 if (c < 0x000080)
345 destsize++;
346 else if (c < 0x000800)
347 destsize += 2;
348 else if (c < 0x010000)
349 destsize += 3;
350 else
351 destsize += 4;
352 }
353
354 dest->type = FSW_STRING_TYPE_UTF8;
355 dest->len = srclen;
356 dest->size = destsize;
357 status = fsw_alloc(dest->size, &dest->data);
358 if (status)
359 return status;
360
361 sp = (fsw_u8 *)srcdata;
362 dp = (fsw_u8 *)dest->data;
363 for (i = 0; i < srclen; i++) {
364 c = *sp++;
365
366 if (c < 0x000080) {
367 *dp++ = (fsw_u8)c;
368 } else if (c < 0x000800) {
369 *dp++ = (fsw_u8)(0xc0 | ((c >> 6) & 0x1f));
370 *dp++ = (fsw_u8)(0x80 | (c & 0x3f));
371 } else if (c < 0x010000) {
372 *dp++ = (fsw_u8)(0xe0 | ((c >> 12) & 0x0f));
373 *dp++ = (fsw_u8)(0x80 | ((c >> 6) & 0x3f));
374 *dp++ = (fsw_u8)(0x80 | (c & 0x3f));
375 } else {
376 *dp++ = (fsw_u8)(0xf0 | ((c >> 18) & 0x07));
377 *dp++ = (fsw_u8)(0x80 | ((c >> 12) & 0x3f));
378 *dp++ = (fsw_u8)(0x80 | ((c >> 6) & 0x3f));
379 *dp++ = (fsw_u8)(0x80 | (c & 0x3f));
380 }
381 }
382 return FSW_SUCCESS;
383}
384
385static fsw_status_t fsw_strcoerce_UTF16_UTF8(void *srcdata, int srclen, struct fsw_string *dest)
386{
387 fsw_status_t status;
388 int i, destsize;
389 fsw_u16 *sp;
390 fsw_u8 *dp;
391 fsw_u32 c;
392
393 sp = (fsw_u16 *)srcdata;
394 destsize = 0;
395 for (i = 0; i < srclen; i++) {
396 c = *sp++;
397
398 if (c < 0x000080)
399 destsize++;
400 else if (c < 0x000800)
401 destsize += 2;
402 else if (c < 0x010000)
403 destsize += 3;
404 else
405 destsize += 4;
406 }
407
408 dest->type = FSW_STRING_TYPE_UTF8;
409 dest->len = srclen;
410 dest->size = destsize;
411 status = fsw_alloc(dest->size, &dest->data);
412 if (status)
413 return status;
414
415 sp = (fsw_u16 *)srcdata;
416 dp = (fsw_u8 *)dest->data;
417 for (i = 0; i < srclen; i++) {
418 c = *sp++;
419
420 if (c < 0x000080) {
421 *dp++ = (fsw_u8)c;
422 } else if (c < 0x000800) {
423 *dp++ = (fsw_u8)(0xc0 | ((c >> 6) & 0x1f));
424 *dp++ = (fsw_u8)(0x80 | (c & 0x3f));
425 } else if (c < 0x010000) {
426 *dp++ = (fsw_u8)(0xe0 | ((c >> 12) & 0x0f));
427 *dp++ = (fsw_u8)(0x80 | ((c >> 6) & 0x3f));
428 *dp++ = (fsw_u8)(0x80 | (c & 0x3f));
429 } else {
430 *dp++ = (fsw_u8)(0xf0 | ((c >> 18) & 0x07));
431 *dp++ = (fsw_u8)(0x80 | ((c >> 12) & 0x3f));
432 *dp++ = (fsw_u8)(0x80 | ((c >> 6) & 0x3f));
433 *dp++ = (fsw_u8)(0x80 | (c & 0x3f));
434 }
435 }
436 return FSW_SUCCESS;
437}
438
439static fsw_status_t fsw_strcoerce_UTF16_SWAPPED_UTF8(void *srcdata, int srclen, struct fsw_string *dest)
440{
441 fsw_status_t status;
442 int i, destsize;
443 fsw_u16 *sp;
444 fsw_u8 *dp;
445 fsw_u32 c;
446
447 sp = (fsw_u16 *)srcdata;
448 destsize = 0;
449 for (i = 0; i < srclen; i++) {
450 c = *sp++; c = FSW_SWAPVALUE_U16(c);
451
452 if (c < 0x000080)
453 destsize++;
454 else if (c < 0x000800)
455 destsize += 2;
456 else if (c < 0x010000)
457 destsize += 3;
458 else
459 destsize += 4;
460 }
461
462 dest->type = FSW_STRING_TYPE_UTF8;
463 dest->len = srclen;
464 dest->size = destsize;
465 status = fsw_alloc(dest->size, &dest->data);
466 if (status)
467 return status;
468
469 sp = (fsw_u16 *)srcdata;
470 dp = (fsw_u8 *)dest->data;
471 for (i = 0; i < srclen; i++) {
472 c = *sp++; c = FSW_SWAPVALUE_U16(c);
473
474 if (c < 0x000080) {
475 *dp++ = (fsw_u8)c;
476 } else if (c < 0x000800) {
477 *dp++ = (fsw_u8)(0xc0 | ((c >> 6) & 0x1f));
478 *dp++ = (fsw_u8)(0x80 | (c & 0x3f));
479 } else if (c < 0x010000) {
480 *dp++ = (fsw_u8)(0xe0 | ((c >> 12) & 0x0f));
481 *dp++ = (fsw_u8)(0x80 | ((c >> 6) & 0x3f));
482 *dp++ = (fsw_u8)(0x80 | (c & 0x3f));
483 } else {
484 *dp++ = (fsw_u8)(0xf0 | ((c >> 18) & 0x07));
485 *dp++ = (fsw_u8)(0x80 | ((c >> 12) & 0x3f));
486 *dp++ = (fsw_u8)(0x80 | ((c >> 6) & 0x3f));
487 *dp++ = (fsw_u8)(0x80 | (c & 0x3f));
488 }
489 }
490 return FSW_SUCCESS;
491}
Note: See TracBrowser for help on using the repository browser.

© 2023 Oracle
ContactPrivacy policyTerms of Use