EvEmu  0.8.4
11 September 2021
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
str2conv.cpp
Go to the documentation of this file.
1 /*
2  ------------------------------------------------------------------------------------
3  LICENSE:
4  ------------------------------------------------------------------------------------
5  This file is part of EVEmu: EVE Online Server Emulator
6  Copyright 2006 - 2021 The EVEmu Team
7  For the latest information visit https://evemu.dev
8  ------------------------------------------------------------------------------------
9  This program is free software; you can redistribute it and/or modify it under
10  the terms of the GNU Lesser General Public License as published by the Free Software
11  Foundation; either version 2 of the License, or (at your option) any later
12  version.
13 
14  This program is distributed in the hope that it will be useful, but WITHOUT
15  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16  FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
17 
18  You should have received a copy of the GNU Lesser General Public License along with
19  this program; if not, write to the Free Software Foundation, Inc., 59 Temple
20  Place - Suite 330, Boston, MA 02111-1307, USA, or go to
21  http://www.gnu.org/copyleft/lesser.txt.
22  ------------------------------------------------------------------------------------
23  Author: Bloody.Rabbit
24 */
25 
26 #include "eve-core.h"
27 
28 #include "utils/str2conv.h"
29 
30 template<>
31 bool str2< bool >( const char* str )
32 {
33  if( !::strcasecmp( str, "true" ) )
34  return true;
35  else if( !::strcasecmp( str, "false" ) )
36  return false;
37  else if( !::strcasecmp( str, "yes" ) )
38  return true;
39  else if( !::strcasecmp( str, "no" ) )
40  return false;
41  else if( !::strcasecmp( str, "y" ) )
42  return true;
43  else if( !::strcasecmp( str, "n" ) )
44  return false;
45  else if( !::strcasecmp( str, "on" ) )
46  return true;
47  else if( !::strcasecmp( str, "off" ) )
48  return false;
49  else if( !::strcasecmp( str, "enable" ) )
50  return true;
51  else if( !::strcasecmp( str, "disable" ) )
52  return false;
53  else if( !::strcasecmp( str, "enabled" ) )
54  return true;
55  else if( !::strcasecmp( str, "disabled" ) )
56  return false;
57  else if( str2< int >( str ) )
58  return true;
59  else
60  return false;
61 }
62 
63 #define STR2( type, fmt ) \
64  template<> \
65  type str2< type >( const char* str ) \
66  { \
67  type v = 0; \
68  ::sscanf( str, "%" fmt, &v ); \
69  return v; \
70  }
71 
72 STR2( int8, SCNd8 )
73 STR2( int16, SCNd16 )
74 STR2( int32, SCNd32 )
75 STR2( int64, SCNd64 )
76 
77 STR2( uint8, SCNu8 )
78 STR2( uint16, SCNu16 )
79 STR2( uint32, SCNu32 )
80 //STR2( uint64, SCNu64 )
81 
82 STR2( float, "f" )
83 STR2( double, "lf" )
84 STR2( long double, "Lf" )
85 
86 #undef STR2
#define SCNu8
Definition: eve-compat.h:92
unsigned __int8 uint8
Definition: eve-compat.h:46
#define SCNu32
Definition: eve-compat.h:104
#define SCNu16
Definition: eve-compat.h:98
signed __int8 int8
Definition: eve-compat.h:45
signed __int32 int32
Definition: eve-compat.h:49
#define SCNd64
Definition: eve-compat.h:107
#define SCNd8
Definition: eve-compat.h:89
#define SCNd32
Definition: eve-compat.h:101
#define SCNd16
Definition: eve-compat.h:95
#define STR2(type, fmt)
Definition: str2conv.cpp:63
bool str2< bool >(const char *str)
Converts string to boolean.
Definition: str2conv.cpp:31
unsigned __int32 uint32
Definition: eve-compat.h:50
signed __int64 int64
Definition: eve-compat.h:51
signed __int16 int16
Definition: eve-compat.h:47
unsigned __int16 uint16
Definition: eve-compat.h:48
#define strcasecmp
Definition: eve-compat.h:262