2
0
Mark Sibly 7 жил өмнө
parent
commit
fa97e33235

+ 13 - 0
modules/monkey/native/bbstring.cpp

@@ -195,49 +195,62 @@ int bbString::utf8Length()const{
 	return n;
 	return n;
 }
 }
 
 
+bbString::bbString( bool b ){
+
+	_rep=Rep::create( b ? "True" : "False" );
+}
+
 bbString::bbString( int n ){
 bbString::bbString( int n ){
+
 	char data[64];
 	char data[64];
 	sprintf( data,"%d",n );
 	sprintf( data,"%d",n );
 	_rep=Rep::create( data );
 	_rep=Rep::create( data );
 }
 }
 
 
 bbString::bbString( unsigned int n ){
 bbString::bbString( unsigned int n ){
+
 	char data[64];
 	char data[64];
 	sprintf( data,"%u",n );
 	sprintf( data,"%u",n );
 	_rep=Rep::create( data );
 	_rep=Rep::create( data );
 }
 }
 
 
 bbString::bbString( long n ){
 bbString::bbString( long n ){
+
 	char data[64];
 	char data[64];
 	sprintf( data,"%ld",n );
 	sprintf( data,"%ld",n );
 	_rep=Rep::create( data );
 	_rep=Rep::create( data );
 }
 }
 
 
 bbString::bbString( unsigned long n ){
 bbString::bbString( unsigned long n ){
+
 	char data[64];
 	char data[64];
 	sprintf( data,"%lu",n );
 	sprintf( data,"%lu",n );
 	_rep=Rep::create( data );
 	_rep=Rep::create( data );
 }
 }
 
 
 bbString::bbString( long long n ){
 bbString::bbString( long long n ){
+
 	char data[64];
 	char data[64];
 	sprintf( data,"%lld",n );
 	sprintf( data,"%lld",n );
 	_rep=Rep::create( data );
 	_rep=Rep::create( data );
 }
 }
 
 
 bbString::bbString( unsigned long long n ){
 bbString::bbString( unsigned long long n ){
+
 	char data[64];
 	char data[64];
 	sprintf( data,"%llu",n );
 	sprintf( data,"%llu",n );
 	_rep=Rep::create( data );
 	_rep=Rep::create( data );
 }
 }
 
 
 bbString::bbString( float n ){
 bbString::bbString( float n ){
+
 	char data[64];
 	char data[64];
 	sprintf( data,"%.9g",n );
 	sprintf( data,"%.9g",n );
 	_rep=Rep::create( data );
 	_rep=Rep::create( data );
 }
 }
 
 
 bbString::bbString( double n ){
 bbString::bbString( double n ){
+
 	char data[64];
 	char data[64];
 	sprintf( data,"%.17g",n );
 	sprintf( data,"%.17g",n );
 	_rep=Rep::create( data );
 	_rep=Rep::create( data );

+ 2 - 0
modules/monkey/native/bbstring.h

@@ -78,6 +78,8 @@ class bbString{
 	bbString( const NSString *str );
 	bbString( const NSString *str );
 #endif
 #endif
 
 
+	explicit bbString( bool b );
+
 	explicit bbString( int n );
 	explicit bbString( int n );
 	
 	
 	explicit bbString( unsigned int n );
 	explicit bbString( unsigned int n );

+ 1 - 1
modules/monkey/native/bbstring.mm

@@ -1,7 +1,7 @@
 
 
 #include "bbstring.h"
 #include "bbstring.h"
 
 
-bbString::bbString( const NSString *str ):_rep( Rep::create( str.UTF8String ) ){
+bbString::bbString( const NSString *str ):_rep( Rep::create( str ? str.UTF8String : "" ) ){
 }
 }
 
 
 NSString *bbString::ToNSString()const{
 NSString *bbString::ToNSString()const{

+ 3 - 1
modules/monkey/newdocs/language/types.md

@@ -45,7 +45,7 @@ These type conversions are performed automatically:
 | String or array type 			| `Bool`
 | String or array type 			| `Bool`
 | Class or interface type	 	| `Bool`
 | Class or interface type	 	| `Bool`
 | Any numeric type				| Any numeric type
 | Any numeric type				| Any numeric type
-| Any numeric type				| `String`
+| Any numeric type or `Bool`	| `String`
 | Any pointer type				| `Void Ptr`
 | Any pointer type				| `Void Ptr`
 | Any enum type					| Any integral type
 | Any enum type					| Any integral type
 | Class or interface type		| Base class type or implemented interface type
 | Class or interface type		| Base class type or implemented interface type
@@ -61,6 +61,8 @@ When struct values are converted, the result will be true if the struct value is
 
 
 When floating point values are converted to integral values, the fractional part of the floating point value is simply chopped off - no rounding is performed.
 When floating point values are converted to integral values, the fractional part of the floating point value is simply chopped off - no rounding is performed.
 
 
+When Bools are converted to strings, the result will be either "True" or "False".
+
 
 
 @#### Explicit type conversions
 @#### Explicit type conversions
 
 

+ 14 - 0
modules/std/misc/stringio.monkey2

@@ -119,23 +119,37 @@ End
 #rem monkeydoc Converts a ulong value to a binary string.
 #rem monkeydoc Converts a ulong value to a binary string.
 #end
 #end
 Function Bin:String( value:ULong )
 Function Bin:String( value:ULong )
+	
 	Return ULongToString( value,2 )
 	Return ULongToString( value,2 )
 End
 End
 
 
 #rem monkeydoc Converts a binary string to a ulong value.
 #rem monkeydoc Converts a binary string to a ulong value.
 #end
 #end
 Function ParseBin:ULong( str:String )
 Function ParseBin:ULong( str:String )
+	
 	Return StringToULong( str,2 )
 	Return StringToULong( str,2 )
 End
 End
 
 
 #rem monkeydoc Converts a ulong value to a hexadecimal string.
 #rem monkeydoc Converts a ulong value to a hexadecimal string.
 #end
 #end
 Function Hex:String( value:ULong )
 Function Hex:String( value:ULong )
+	
 	Return ULongToString( value,16 )
 	Return ULongToString( value,16 )
 End
 End
 
 
 #rem monkeydoc Converts a hexadecimal string to a ulong value.
 #rem monkeydoc Converts a hexadecimal string to a ulong value.
 #end
 #end
 Function ParseHex:ULong( str:String )
 Function ParseHex:ULong( str:String )
+	
 	Return StringToULong( str,16 )
 	Return StringToULong( str,16 )
 End
 End
+
+#rem monkeydoc Parse a boolean string.
+
+Returns true if `str` equals "True", ignoring case. Otherwise, returns false.
+
+#end
+Function ParseBool:Bool( str:String )
+	
+	Return str.ToLower()="true"
+End