| 431 | |
| 432 | |
| 433 | String ArrayBase::joinArray(Array_obj<String> *inArray, String inSeparator) |
| 434 | { |
| 435 | int length = inArray->length; |
| 436 | if (length==0) |
| 437 | return HX_CSTRING(""); |
| 438 | |
| 439 | int len = 0; |
| 440 | bool isWChar = false; |
| 441 | for(int i=0;i<length;i++) |
| 442 | { |
| 443 | String strI = inArray->__unsafe_get(i); |
| 444 | if (strI.raw_ptr()) |
| 445 | { |
| 446 | len += strI.length; |
| 447 | #ifdef HX_SMART_STRINGS |
| 448 | if (strI.isUTF16Encoded()) |
| 449 | isWChar = true; |
| 450 | #endif |
| 451 | } |
| 452 | else |
| 453 | len += 4; |
| 454 | } |
| 455 | |
| 456 | len += (length-1) * inSeparator.length; |
| 457 | #ifdef HX_SMART_STRINGS |
| 458 | bool sepIsWide = inSeparator.isUTF16Encoded(); |
| 459 | if (isWChar || sepIsWide) |
| 460 | { |
| 461 | char16_t *buf = String::allocChar16Ptr(len); |
| 462 | int pos = 0; |
| 463 | bool separated = inSeparator.length>0; |
| 464 | |
| 465 | for(int i=0;i<length;i++) |
| 466 | { |
| 467 | String strI = inArray->__unsafe_get(i); |
| 468 | if (!strI.raw_ptr()) |
| 469 | { |
| 470 | memcpy(buf+pos,u"null",8); |
| 471 | pos+=4; |
| 472 | } |
| 473 | else if(strI.length==0) |
| 474 | { |
| 475 | // ignore |
| 476 | } |
| 477 | else if (strI.isUTF16Encoded()) |
| 478 | { |
| 479 | memcpy(buf+pos,strI.raw_wptr(),strI.length*sizeof(char16_t)); |
| 480 | pos += strI.length; |
| 481 | } |
| 482 | else |
| 483 | { |
| 484 | const char *ptr = strI.raw_ptr(); |
| 485 | for(int c=0;c<strI.length;c++) |
| 486 | buf[pos++] = ptr[c]; |
| 487 | } |
| 488 | |
| 489 | if (separated && (i+1<length) ) |
| 490 | { |
nothing calls this directly
no test coverage detected