Skip to content

Commit a45bd41

Browse files
committed
fix(bink): Implement subtitle time string parser for ICU code path.
1 parent b331580 commit a45bd41

File tree

1 file changed

+6
-55
lines changed

1 file changed

+6
-55
lines changed

Code/BinkMovie/subtitleparser.cpp

Lines changed: 6 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -450,46 +450,15 @@ unsigned int Decode_Time_String(unichar_t* string)
450450

451451
WWASSERT(string != NULL);
452452

453-
unichar_t buffer[12];
454-
u_strncpy(buffer, string, 12);
455-
buffer[11] = 0;
456-
457-
unichar_t* ptr = &buffer[0];
458-
459-
#ifndef W3D_USING_ICU
460-
// Isolate hours part
461-
unichar_t* separator = u_strchr(ptr, U_CHAR(':'));
462-
WWASSERT(separator != NULL);
463-
*separator++ = 0;
464-
unsigned int hours = wcstoul(ptr, NULL, 10);
465-
466-
// Isolate minutes part
467-
ptr = separator;
468-
separator = u_strchr(ptr, U_CHAR(':'));
469-
WWASSERT(separator != NULL);
470-
*separator++ = 0;
471-
unsigned int minutes = wcstoul(ptr, NULL, 10);
472-
473-
// Isolate seconds part
474-
ptr = separator;
475-
separator = u_strchr(ptr, U_CHAR(':'));
476-
WWASSERT(separator != NULL);
477-
*separator++ = 0;
478-
unsigned int seconds = wcstoul(ptr, NULL, 10);
479-
480-
// Isolate hundredth part (1/100th of a second)
481-
ptr = separator;
482-
unsigned int hundredth = wcstoul(ptr, NULL, 10);
453+
unsigned hours = 0, minutes = 0, seconds = 0, hundredth = 0;
454+
u_sscanf_u(string, U_CHAR("%u:%u:%u:%u"), &hours, &minutes, &seconds, &hundredth);
483455

484456
unsigned int time = (hours * TICKS_PER_HOUR);
485457
time += (minutes * TICKS_PER_MINUTE);
486458
time += (seconds * TICKS_PER_SECOND);
487459
time += ((hundredth * TICKS_PER_SECOND) / 100);
488460

489461
return time;
490-
#else
491-
return 0; // TODO, ICU implementation
492-
#endif
493462
}
494463

495464

@@ -537,12 +506,8 @@ void Parse_Position(unichar_t* param, SubTitleClass* subTitle)
537506

538507
if (separator != NULL) {
539508
*separator++ = 0;
540-
#ifndef W3D_USING_ICU
541-
int linePos = wcstol(ptr, NULL, 0);
542-
#else
543-
// TODO ICU implementation.
544509
int linePos = 0;
545-
#endif
510+
u_sscanf_u(ptr, U_CHAR("%d"), &linePos);
546511
subTitle->Set_Line_Position(linePos);
547512
ptr = separator;
548513
}
@@ -569,24 +534,10 @@ void Parse_Color(unichar_t* param, SubTitleClass* subTitle)
569534
WWASSERT(param != NULL);
570535
WWASSERT(subTitle != NULL);
571536

572-
// TODO ICU implementation
573-
#ifndef W3D_USING_ICU
574-
unichar_t* ptr = param;
575-
576-
unichar_t* separator = u_strchr(ptr, U_CHAR(':'));
577-
*separator++ = 0;
578-
unsigned char red = (unsigned char)wcstoul(ptr, NULL, 10);
579-
580-
ptr = separator;
581-
separator = u_strchr(ptr, U_CHAR(':'));
582-
*separator++ = 0;
583-
unsigned char green = (unsigned char)wcstoul(ptr, NULL, 10);
584-
585-
ptr = separator;
586-
unsigned char blue = (unsigned char)wcstoul(ptr, NULL, 10);
587-
537+
unsigned char red = 0, green = 0, blue = 0;
538+
u_sscanf_u(param, U_CHAR("%hhu:%hhu:%hhu"), &red, &green, &blue);
588539
subTitle->Set_RGB_Color(red, green, blue);
589-
#endif
540+
590541
}
591542

592543

0 commit comments

Comments
 (0)