MCPcopy Create free account
hub / github.com/IoLanguage/io / UArray_translate

Function UArray_translate

libs/basekit/source/UArray_string.c:456–497  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

454}
455
456void UArray_translate(UArray *self, UArray *fromChars, UArray *toChars) {
457 double max = 4096;
458 double fromMax = UArray_maxAsDouble(fromChars);
459 double toMax = UArray_maxAsDouble(toChars);
460
461 if (UArray_size(fromChars) != UArray_size(toChars)) {
462 printf(
463 "UArray_translate: translation strings must be of the same length");
464 return;
465 }
466
467 if ((0 < fromMax && fromMax < max) && (0 < toMax && toMax < 256)) {
468 size_t i;
469 uint8_t *map = io_calloc(1, fromMax);
470 memset(map, 0x0, fromMax);
471
472 for (i = 0; i < UArray_size(fromChars); i++) {
473 map[UArray_longAt_(fromChars, i)] = UArray_longAt_(toChars, i);
474 }
475
476 for (i = 0; i < UArray_size(self); i++) {
477 self->data[i] = map[self->data[i]];
478 }
479
480 io_free(map);
481 return;
482 }
483
484 /*
485 UARRAY_FOREACH(self, i, currChar,
486 UARRAY_FOREACH(fromChars, j, fromChar,
487 if(currChar == fromChar)
488 {
489 UARRAY_RAWAT_PUT_(self,
490 i, UARRAY_RAWAT_(toChars, j)); break;
491 }
492 );
493 );
494 */
495
496 UArray_error_(self, "UArray_translate unimplemented for this type");
497}
498
499size_t UArray_count_(const UArray *self, const UArray *other) {
500 long i = 0;

Callers 1

IoSeq_mutable.cFile · 0.85

Calls 5

UArray_maxAsDoubleFunction · 0.85
UArray_sizeFunction · 0.85
UArray_longAt_Function · 0.85
io_freeFunction · 0.85
UArray_error_Function · 0.85

Tested by

no test coverage detected