Commit a103cbce authored by hpi1's avatar hpi1

Moved string_to_uint32 to strutl.c

parent b33b0fc2
......@@ -1543,37 +1543,16 @@ int bd_set_player_setting(BLURAY *bd, uint32_t idx, uint32_t value)
return 0;
}
static uint32_t _string_to_uint32(const char *s, int n)
{
uint32_t val = 0;
if (n > 4)
n = 4;
if (!s || !*s) {
return (INT64_C(1) << (8*n)) - 1; /* default: all bits one */
}
while (n--) {
val = (val << 8) | *s;
if (*s) {
s++;
}
}
return val;
}
int bd_set_player_setting_str(BLURAY *bd, uint32_t idx, const char *s)
{
switch (idx) {
case BLURAY_PLAYER_SETTING_AUDIO_LANG:
case BLURAY_PLAYER_SETTING_PG_LANG:
case BLURAY_PLAYER_SETTING_MENU_LANG:
return bd_set_player_setting(bd, idx, _string_to_uint32(s, 3));
return bd_set_player_setting(bd, idx, str_to_uint32(s, 3));
case BLURAY_PLAYER_SETTING_COUNTRY_CODE:
return bd_set_player_setting(bd, idx, _string_to_uint32(s, 2));
return bd_set_player_setting(bd, idx, str_to_uint32(s, 2));
default:
return 0;
......
......@@ -58,3 +58,23 @@ char * str_printf(const char *fmt, ...)
}
}
uint32_t str_to_uint32(const char *s, int n)
{
uint32_t val = 0;
if (n > 4)
n = 4;
if (!s || !*s) {
return (INT64_C(1) << (8*n)) - 1; /* default: all bits one */
}
while (n--) {
val = (val << 8) | *s;
if (*s) {
s++;
}
}
return val;
}
......@@ -22,6 +22,10 @@
#include "attributes.h"
#include <stdint.h>
BD_PRIVATE char * str_printf(const char *fmt, ...) BD_ATTR_FORMAT_PRINTF(1,2) BD_ATTR_MALLOC;
BD_PRIVATE uint32_t str_to_uint32(const char *s, int n);
#endif // STRUTL_H_
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment