mirror of
https://github.com/justinethier/cyclone.git
synced 2025-07-12 15:27:36 +02:00
Added bin/oct/hex string->integer conversions
This commit is contained in:
parent
3ce0ff6936
commit
46e15ceffc
2 changed files with 40 additions and 0 deletions
|
@ -154,6 +154,9 @@ object Cyc_symbol2string(void *d, object cont, object sym) ;
|
||||||
object Cyc_string2symbol(void *d, object str);
|
object Cyc_string2symbol(void *d, object str);
|
||||||
object Cyc_list2string(void *d, object cont, object lst);
|
object Cyc_list2string(void *d, object cont, object lst);
|
||||||
common_type Cyc_string2number(void *d, object str);
|
common_type Cyc_string2number(void *d, object str);
|
||||||
|
int binstr2int(const char *str);
|
||||||
|
int octstr2int(const char *str);
|
||||||
|
int hexstr2int(const char *str);
|
||||||
object Cyc_string_append(void *data, object cont, int argc, object str1, ...);
|
object Cyc_string_append(void *data, object cont, int argc, object str1, ...);
|
||||||
integer_type Cyc_string_length(void *data, object str);
|
integer_type Cyc_string_length(void *data, object str);
|
||||||
object Cyc_substring(void *data, object cont, object str, object start, object end);
|
object Cyc_substring(void *data, object cont, object str, object start, object end);
|
||||||
|
|
37
runtime.c
37
runtime.c
|
@ -1057,6 +1057,43 @@ common_type Cyc_string2number(void *data, object str){
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int binstr2int(const char *str)
|
||||||
|
{
|
||||||
|
int num = 0;
|
||||||
|
while (*str) {
|
||||||
|
num <<= 1;
|
||||||
|
if (*str++ == '1') num++;
|
||||||
|
}
|
||||||
|
return num;
|
||||||
|
}
|
||||||
|
|
||||||
|
int octstr2int(const char *str)
|
||||||
|
{
|
||||||
|
int num = 0;
|
||||||
|
while (*str) {
|
||||||
|
num <<= 3;
|
||||||
|
num += ((*str++) - '0');
|
||||||
|
}
|
||||||
|
return num;
|
||||||
|
}
|
||||||
|
|
||||||
|
int hexstr2int(const char *str)
|
||||||
|
{
|
||||||
|
int num = 0;
|
||||||
|
while (*str) {
|
||||||
|
num <<= 4;
|
||||||
|
if (*str >= 'A' && *str <= 'F'){
|
||||||
|
num += (((*str) - 'A') + 10);
|
||||||
|
} else if (*str >= 'a' && *str <= 'f'){
|
||||||
|
num += (((*str) - 'a') + 10);
|
||||||
|
} else {
|
||||||
|
num += ((*str) - '0');
|
||||||
|
}
|
||||||
|
*str++;
|
||||||
|
}
|
||||||
|
return num;
|
||||||
|
}
|
||||||
|
|
||||||
integer_type Cyc_string_cmp(void *data, object str1, object str2) {
|
integer_type Cyc_string_cmp(void *data, object str1, object str2) {
|
||||||
Cyc_check_str(data, str1);
|
Cyc_check_str(data, str1);
|
||||||
Cyc_check_str(data, str2);
|
Cyc_check_str(data, str2);
|
||||||
|
|
Loading…
Add table
Reference in a new issue