Skip to content

Commit

Permalink
libcaption: cast between char with utf8_char_t appropriate
Browse files Browse the repository at this point in the history
  • Loading branch information
r-value committed Jul 1, 2023
1 parent 485efd5 commit d5b055a
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 11 deletions.
2 changes: 1 addition & 1 deletion deps/libcaption/caption/utf8.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ size_t utf8_char_copy(utf8_char_t* dst, const utf8_char_t* src);
returnes the number of utf8 charcters in a string givne the numbe of bytes
to coutn until the a null terminator, pass 0 for size
*/
utf8_size_t utf8_char_count(const char* data, size_t size);
utf8_size_t utf8_char_count(const utf8_char_t* data, size_t size);
/*! \brief
\param
Expand Down
2 changes: 1 addition & 1 deletion deps/libcaption/src/caption.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ static caption_frame_cell_t* frame_buffer_cell(caption_frame_buffer_t* buff, int
}

uint16_t _eia608_from_utf8(const char* s); // function is in eia608.c.re2c
int caption_frame_write_char(caption_frame_t* frame, int row, int col, eia608_style_t style, int underline, const char* c)
int caption_frame_write_char(caption_frame_t* frame, int row, int col, eia608_style_t style, int underline, const utf8_char_t* c)
{
if (!frame->write || !_eia608_from_utf8(c)) {
return 0;
Expand Down
2 changes: 1 addition & 1 deletion deps/libcaption/src/eia608.c
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ static int eia608_to_index(uint16_t cc_data, int* chan, int* c1, int* c2)
return 0;
}

int eia608_to_utf8(uint16_t c, int* chan, char* str1, char* str2)
int eia608_to_utf8(uint16_t c, int* chan, utf8_char_t* str1, utf8_char_t* str2)
{
int c1, c2;
int size = (int)eia608_to_index(c, chan, &c1, &c2);
Expand Down
6 changes: 3 additions & 3 deletions deps/libcaption/src/mpeg.c
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,7 @@ libcaption_stauts_t sei_from_caption_frame(sei_t* sei, caption_frame_t* frame)
int r, c;
int unl, prev_unl;
cea708_t cea708;
const char* data;
const utf8_char_t* data;
uint16_t prev_cc_data;
eia608_style_t styl, prev_styl;

Expand Down Expand Up @@ -490,7 +490,7 @@ libcaption_stauts_t sei_from_caption_frame(sei_t* sei, caption_frame_t* frame)
sei_encode_eia608(sei, &cea708, eia608_from_basicna(prev_cc_data, cc_data));
} else if (eia608_is_westeu(cc_data)) {
// extended charcters overwrite the previous charcter, so insert a dummy char thren write the extended char
sei_encode_eia608(sei, &cea708, eia608_from_basicna(prev_cc_data, eia608_from_utf8_1(EIA608_CHAR_SPACE, DEFAULT_CHANNEL)));
sei_encode_eia608(sei, &cea708, eia608_from_basicna(prev_cc_data, eia608_from_utf8_1((const utf8_char_t*)EIA608_CHAR_SPACE, DEFAULT_CHANNEL)));
sei_encode_eia608(sei, &cea708, cc_data);
} else {
// previous was basic na, but current isnt; write previous and current
Expand All @@ -502,7 +502,7 @@ libcaption_stauts_t sei_from_caption_frame(sei_t* sei, caption_frame_t* frame)
} else if (eia608_is_westeu(cc_data)) {
// extended chars overwrite the previous chars, so insert a dummy char
// TODO create a map of alternamt chars for eia608_is_westeu instead of using space
sei_encode_eia608(sei, &cea708, eia608_from_utf8_1(EIA608_CHAR_SPACE, DEFAULT_CHANNEL));
sei_encode_eia608(sei, &cea708, eia608_from_utf8_1((const utf8_char_t*)EIA608_CHAR_SPACE, DEFAULT_CHANNEL));
sei_encode_eia608(sei, &cea708, cc_data);
} else if (eia608_is_basicna(cc_data)) {
prev_cc_data = cc_data;
Expand Down
6 changes: 3 additions & 3 deletions deps/libcaption/src/scc.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ size_t scc_to_608(scc_t** scc, const utf8_char_t* data)
}

// skip 'Scenarist_SCC V1.0' header
if (2 == sscanf(data, "Scenarist_SCC V%1d.%1d", &v1, &v2)) {
if (2 == sscanf((const char*)data, "Scenarist_SCC V%1d.%1d", &v1, &v2)) {
data += 18, size += 18;

if (1 != v1 || 0 != v2) {
Expand All @@ -92,7 +92,7 @@ size_t scc_to_608(scc_t** scc, const utf8_char_t* data)
size += llen;
}

if (4 == sscanf(data, "%2d:%2d:%2d%*1[:;]%2d", &hh, &mm, &ss, &ff)) {
if (4 == sscanf((const char*)data, "%2d:%2d:%2d%*1[:;]%2d", &hh, &mm, &ss, &ff)) {
data += 12, size += 12;
// Get length of the remaining charcters
llen = utf8_line_length(data);
Expand All @@ -102,7 +102,7 @@ size_t scc_to_608(scc_t** scc, const utf8_char_t* data)
(*scc)->timestamp = scc_time_to_timestamp(hh, mm, ss, ff);
(*scc)->cc_size = 0;

while ((*scc)->cc_size < max_cc_count && 1 == sscanf(data, "%04x", &cc_data)) {
while ((*scc)->cc_size < max_cc_count && 1 == sscanf((const char*)data, "%04x", &cc_data)) {
(*scc)->cc_data[(*scc)->cc_size] = (uint16_t)cc_data;
(*scc)->cc_size += 1;
data += 5, size += 5;
Expand Down
4 changes: 2 additions & 2 deletions deps/libcaption/src/utf8.c
Original file line number Diff line number Diff line change
Expand Up @@ -99,13 +99,13 @@ size_t utf8_char_copy(utf8_char_t* dst, const utf8_char_t* src)

// returnes the number of utf8 charcters in a string given the number of bytes
// to count until the a null terminator, pass 0 for size
utf8_size_t utf8_char_count(const char* data, size_t size)
utf8_size_t utf8_char_count(const utf8_char_t* data, size_t size)
{
size_t i, bytes = 0;
utf8_size_t count = 0;

if (0 == size) {
size = strlen(data);
size = strlen((const char*)data);
}

for (i = 0; i < size; ++count, i += bytes) {
Expand Down

0 comments on commit d5b055a

Please sign in to comment.