| 2557 | } |
| 2558 | |
| 2559 | static hb_buffer_t * merge_ssa(hb_buffer_t *a, hb_buffer_t *b) |
| 2560 | { |
| 2561 | int len, ii; |
| 2562 | char *text; |
| 2563 | hb_buffer_t *buf; |
| 2564 | |
| 2565 | if (a == NULL && b == NULL) |
| 2566 | { |
| 2567 | return NULL; |
| 2568 | } |
| 2569 | if (a == NULL) |
| 2570 | { |
| 2571 | return hb_buffer_dup(b); |
| 2572 | } |
| 2573 | if (b == NULL) |
| 2574 | { |
| 2575 | return hb_buffer_dup(a); |
| 2576 | } |
| 2577 | |
| 2578 | buf = hb_buffer_init(a->size + b->size); |
| 2579 | buf->s = a->s; |
| 2580 | |
| 2581 | // Find the text in the second SSA sub |
| 2582 | text = (char*)b->data; |
| 2583 | for (ii = 0; ii < 8; ii++) |
| 2584 | { |
| 2585 | text = strchr(text, ','); |
| 2586 | if (text == NULL) |
| 2587 | break; |
| 2588 | text++; |
| 2589 | } |
| 2590 | if (text != NULL) |
| 2591 | { |
| 2592 | // Strip trailing CR and/or LF |
| 2593 | len = strlen((char*)a->data); |
| 2594 | if (len > 0 && a->data[len - 1] == '\n') |
| 2595 | { |
| 2596 | a->data[len - 1] = 0; |
| 2597 | len--; |
| 2598 | if (len > 0 && a->data[len - 1] == '\r') |
| 2599 | { |
| 2600 | a->data[len - 1] = 0; |
| 2601 | } |
| 2602 | } |
| 2603 | // Text subtitles are SSA internally. Use SSA newline code |
| 2604 | // and force style reset at beginning of new line. |
| 2605 | len = snprintf((char*)buf->data, buf->size, "%s\\N{\\r}%s", a->data, text); |
| 2606 | if (len >= 0) |
| 2607 | buf->size = len + 1; |
| 2608 | } |
| 2609 | else |
| 2610 | { |
| 2611 | memcpy(buf->data, a->data, a->size); |
| 2612 | buf->size = a->size; |
| 2613 | } |
| 2614 | |
| 2615 | return buf; |
| 2616 | } |
no test coverage detected