X-Git-Url: http://nitlanguage.org diff --git a/c_src/string_nit.c b/c_src/string_nit.c index d29de0c..050ab95 100644 --- a/c_src/string_nit.c +++ b/c_src/string_nit.c @@ -1,7 +1,5 @@ /* This file is part of NIT ( http://www.nitlanguage.org ). * - * Copyright 2012 Alexis Laferrière - * * This file is free software, which comes along with NIT. This software is * distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A @@ -13,27 +11,22 @@ #include "string_nit.h" -/* -C implementation of string::String::to_f - -Imported methods signatures: - char * String_to_cstring( String recv ) for string::String::to_cstring -*/ -float String_to_f___impl( String recv ) -{ - float value; - char *str; - int read; - - str = String_to_cstring( recv ); +// Returns the length of `recv` as a `char*` (excluding the null character) +long native_int_length_str(long recv){ + return snprintf(NULL, 0, "%ld", recv); +} - read = sscanf( str, "%f", &value ); +// Integer to NativeString method +void native_int_to_s(long recv, char* str, long buflen){ + snprintf(str, buflen, "%ld", recv); +} - if ( read <= 0 ) - { - fprintf( stderr, "Failed to convert string \"\" to float." ); - abort(); - } +// Returns the length of `recv` as a `char*` (excluding the null character) +long native_byte_length_str(unsigned char recv){ + return snprintf(NULL, 0, "0x%02x", recv); +} - return value; +// Byte to NativeString method +void native_byte_to_s(unsigned char recv, char* str, long buflen){ + snprintf(str, buflen, "0x%02x", recv); }