ni: use macro NONITCNI to disable nitni in extern files
[nit.git] / lib / standard / string_nit.c
1 /* This file is part of NIT ( http://www.nitlanguage.org ).
2 *
3 * Copyright 2012 Alexis Laferrière <alexis.laf@xymus.net>
4 *
5 * This file is free software, which comes along with NIT. This software is
6 * distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
7 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
8 * PARTICULAR PURPOSE. You can modify it is you want, provided this header
9 * is kept unaltered, and a notification of the changes is added.
10 * You are allowed to redistribute it and sell it, alone or is a part of
11 * another product.
12 */
13
14 #include "string_nit.h"
15
16 #ifndef NONITCNI
17 /*
18 C implementation of string::String::to_f
19
20 Imported methods signatures:
21 char * String_to_cstring( String recv ) for string::String::to_cstring
22 */
23 float String_to_f___impl( String recv )
24 {
25 float value;
26 char *str;
27 int read;
28
29 str = String_to_cstring( recv );
30
31 read = sscanf( str, "%f", &value );
32
33 if ( read <= 0 )
34 {
35 fprintf( stderr, "Failed to convert string \"\" to float." );
36 abort();
37 }
38
39 return value;
40 }
41 #endif