Browse Source

Streamlined CString system - UTF8String gone, CString encoding now autodetected.

Mark Sibly 8 years ago
parent
commit
b5b7a90bfc

+ 2 - 2
modules/hoedown/hoedown.monkey2

@@ -105,9 +105,9 @@ End
 
 Function hoedown_document_new:hoedown_document Ptr( renderer:hoedown_renderer Ptr,extensions:hoedown_extensions,max_nesting:Int )
 
-Function hoedown_document_render( doc:hoedown_document Ptr,ob:hoedown_buffer Ptr,data:Utf8String,size:Int )
+Function hoedown_document_render( doc:hoedown_document Ptr,ob:hoedown_buffer Ptr,data:CString,size:Int )
 
-Function hoedown_document_render_inline( doc:hoedown_document Ptr,ob:hoedown_buffer Ptr,data:Utf8String,size:Int )
+Function hoedown_document_render_inline( doc:hoedown_document Ptr,ob:hoedown_buffer Ptr,data:CString,size:Int )
 
 Function hoedown_document_free( doc:hoedown_document Ptr )
 

+ 1 - 10
modules/litehtml/native/litehtml_glue.cpp

@@ -153,16 +153,7 @@ void bb_litehtml_context::load_master_stylesheet( bbString master_css ){
 
 bb_litehtml_document::bb_litehtml_document( bbString source,bb_litehtml_document_container *container,bb_litehtml_context *context ){
 
-	_document=litehtml::document::createFromUTF8( bbUtf8String( source ),container,context );
-	
-//	const char *utf8=source.toUtf8String();
-//	_document=litehtml::document::createFromUTF8( utf8,container,context );
-	
-//	char *utf8=new char[source.utf8Length()+1];
-//	source.toUtf8( (bbByte*)utf8 );
-//	utf8[source.utf8Length()]=0;
-//	_document=litehtml::document::createFromUTF8( utf8,container,context );
-//	delete[] utf8;
+	_document=litehtml::document::createFromUTF8( bbCString( source ),container,context );
 	
 	_container=container;
 	_context=context;

+ 2 - 2
modules/mojo/app/app.monkey2

@@ -210,7 +210,7 @@ Class AppInstance
 	
 		Local p:=SDL_GetClipboardText()
 		
-		Local str:=String.FromUtf8String( p )
+		Local str:=String.FromCString( p )
 
 		'fix windows eols		
 		str=str.Replace( "~r~n","~n" )
@@ -714,7 +714,7 @@ Class AppInstance
 			_window=Window.WindowForID( tevent->windowID )
 			If Not _window Return
 			
-			_keyChar=String.FromUtf8String( tevent->text )
+			_keyChar=String.FromCString( tevent->text )
 			
 			SendKeyEvent( EventType.KeyChar )
 			

+ 1 - 1
modules/mojo/app/window.monkey2

@@ -44,7 +44,7 @@ Class Window Extends View
 	#end
 	Property Title:String()
 	
-		Return String.FromUtf8String( SDL_GetWindowTitle( _sdlWindow ) )
+		Return String.FromCString( SDL_GetWindowTitle( _sdlWindow ) )
 	
 	Setter( title:String )
 	

+ 2 - 2
modules/monkey/native/bbmonkey.cpp

@@ -15,7 +15,7 @@ void bbMain();
 #include <android/log.h>
 
 void bb_print( bbString str ){
-	__android_log_print( ANDROID_LOG_INFO,"MX2","%s",str.utf8_str() );
+	__android_log_print( ANDROID_LOG_INFO,"MX2","%s",str.c_str() );
 }
 
 void bb_printf( const char *fmt,... ){
@@ -28,7 +28,7 @@ void bb_printf( const char *fmt,... ){
 #else
 
 void bb_print( bbString str ){
-	puts( str.utf8_str() );fflush( stdout );
+	puts( str.c_str() );fflush( stdout );
 }
 
 void bb_printf( const char *fmt,... ){

+ 142 - 173
modules/monkey/native/bbstring.cpp

@@ -4,6 +4,103 @@
 
 bbString::Rep bbString::_nullRep;
 
+namespace{
+
+	int countUtf8Chars( const char *p,int sz ){
+	
+		const char *e=p+sz;
+	
+		int n=0;
+	
+		while( p!=e ){
+			int c=*p++;
+			
+			if( c & 0x80 ){
+				if( (c & 0xe0)==0xc0 ){
+					if( p==e || (p[0] & 0xc0)!=0x80 ) return -1;
+					p+=1;
+				}else if( (c & 0xf0)==0xe0 ){
+					if( p==e || p+1==e || (p[0] & 0xc0)!=0x80 || (p[1] & 0xc0)!=0x80 ) return -1;
+					p+=2;
+				}else{
+					return -1;
+				}
+			}
+			n+=1;
+		}
+		return n;
+	}
+	
+	int countNullTerminatedUtf8Chars( const char *p,int sz ){
+	
+		const char *e=p+sz;
+	
+		int n=0;
+	
+		while( p!=e && *p ){
+			int c=*p++;
+			
+			if( c & 0x80 ){
+				if( (c & 0xe0)==0xc0 ){
+					if( p==e || (p[0] & 0xc0)!=0x80 ) return -1;
+					p+=1;
+				}else if( (c & 0xf0)==0xe0 ){
+					if( p==e || p+1==e || (p[0] & 0xc0)!=0x80 || (p[1] & 0xc0)!=0x80 ) return -1;
+					p+=2;
+				}else{
+					return -1;
+				}
+			}
+			n+=1;
+		}
+		return n;
+	}
+	
+	void charsToUtf8( const bbChar *p,int n,char *dst,int size ){
+	
+		char *end=dst+size;
+		
+		const bbChar *e=p+n;
+		
+		while( p<e && dst<end ){
+			bbChar c=*p++;
+			if( c<0x80 ){
+				*dst++=c;
+			}else if( c<0x800 ){
+				if( dst+2>end ) break;
+				*dst++=0xc0 | (c>>6);
+				*dst++=0x80 | (c & 0x3f);
+			}else{
+				if( dst+3>end ) break;
+				*dst++=0xe0 | (c>>12);
+				*dst++=0x80 | ((c>>6) & 0x3f);
+				*dst++=0x80 | (c & 0x3f);
+			}
+		}
+		if( dst<end ) *dst++=0;
+	}
+	
+	void utf8ToChars( const char *p,bbChar *dst,int n ){
+	
+		while( n-- ){
+			int c=*p++;
+			
+			if( c & 0x80 ){
+				if( (c & 0xe0)==0xc0 ){
+					c=((c & 0x1f)<<6) | (p[0] & 0x3f);
+					p+=1;
+				}else if( (c & 0xf0)==0xe0 ){
+					c=((c & 0x0f)<<12) | ((p[0] & 0x3f)<<6) | (p[1] & 0x3f);
+					p+=2;
+				}
+			}
+			*dst++=c;
+		}
+
+	}
+	
+}
+
 int bbString::utf8Length()const{
 
 	const bbChar *p=data();
@@ -25,15 +122,49 @@ int bbString::utf8Length()const{
 	return n;
 }
 
+bbString::bbString( const void *p ){
+
+	const char *cp=(const char*)p;
+
+	if( !cp ){
+		_rep=&_nullRep;
+		return;
+	}
+
+	int sz=strlen( cp );
+
+	int n=countNullTerminatedUtf8Chars( cp,sz );
+
+	if( n==-1 || n==sz ){
+		_rep=Rep::create( cp,sz );
+		return;
+	}
+	_rep=Rep::alloc( n );
+	utf8ToChars( cp,_rep->data,n );
+}
+
+bbString::bbString( const void *p,int sz ){
+
+	const char *cp=(const char*)p;
+
+	if( !cp ){
+		_rep=&_nullRep;
+		return;
+	}
+
+	int n=countUtf8Chars( cp,sz );
+
+	if( n==-1 || n==sz ){
+		_rep=Rep::create( cp,sz );
+		return;
+	}
+	_rep=Rep::alloc( n );
+	utf8ToChars( cp,_rep->data,n );
+}
+
 void bbString::toCString( void *buf,int size )const{
-	if( size<=0 ) return;
-	
-	int sz=length();
-	if( sz>size ) sz=size;
-	
-	for( int i=0;i<sz;++i ) ((char*)buf)[i]=data()[i];
-	
-	if( sz<size ) ((char*)buf)[sz]=0;
+
+	charsToUtf8( _rep->data,_rep->length,(char*)buf,size );
 }
 
 void bbString::toWString( void *buf,int size )const{
@@ -49,187 +180,25 @@ void bbString::toWString( void *buf,int size )const{
 	if( sz<size ) ((wchar_t*)buf)[sz]=0;
 }
 
-void bbString::toUtf8String( void *buf,int size )const{
-
-	char *dst=(char*)buf;
-	char *end=dst+size;
-	
-	const bbChar *p=data();
-	const bbChar *e=p+length();
-	
-	while( p<e && dst<end ){
-		bbChar c=*p++;
-		if( c<0x80 ){
-			*dst++=c;
-		}else if( c<0x800 ){
-			if( dst+2>end ) break;
-			*dst++=0xc0 | (c>>6);
-			*dst++=0x80 | (c & 0x3f);
-		}else{
-			if( dst+3>end ) break;
-			*dst++=0xe0 | (c>>12);
-			*dst++=0x80 | ((c>>6) & 0x3f);
-			*dst++=0x80 | (c & 0x3f);
-		}
-	}
-	if( dst<end ) *dst++=0;
-}
-
 const char *bbString::c_str()const{
 
 	static int _sz;
 	static char *_tmp;
 	
-	int sz=length()+1;
-	if( sz>_sz ){
-		free( _tmp );
-		_tmp=(char*)malloc( _sz=sz );
-	}
-	toCString( _tmp,sz );
-	return _tmp;
-}
-
-const char *bbString::utf8_str()const{
-
-	static int _sz;
-	static char *_tmp;
-	
 	int sz=utf8Length()+1;
 	if( sz>_sz ){
 		free( _tmp );
 		_tmp=(char*)malloc( _sz=sz );
 	}
-	toUtf8String( _tmp,sz );
+	toCString( _tmp,sz );
 	return _tmp;
 }
 
 bbString bbString::fromChar( int chr ){
-	bbChar buf[]={(bbChar)chr,0};
-	return bbString( buf,1 );
-}
-
-bbString bbString::fromCString( const void *data,int size ){
-	if( !data ) return bbString();
-	const char *p=(const char*)data;
-	const char *e=p;
-	while( e!=p+size && *e ) ++e;
-	return bbString( p,e-p );
-}
-
-bbString bbString::fromWString( const void *data,int size ){
-	if( !data ) return bbString();
-	size/=sizeof(wchar_t);
-	const wchar_t *p=(const wchar_t*)data;
-	const wchar_t *e=p;
-	while( e!=p+size && *e ) ++e;
-	return bbString( p,e-p );
+	wchar_t chrs[]={ chr };
+	return bbString( chrs,1 );
 }
 
-bbString bbString::fromUtf8String( const void *data,int size ){
-	if( !data ) return bbString();
-
-	const char *p=(const char*)data;
-	const char *e=p+size;
-
-	int len=0;
-		
-	while( p!=e && *p ){
-		int c=*p++;
-		
-		if( c & 0x80 ){
-			if( (c & 0xe0)==0xc0 ){
-				if( p==e || (p[0] & 0xc0)!=0x80 ) break;
-				p+=1;
-			}else if( (c & 0xf0)==0xe0 ){
-				if( p==e || p+1==e || (p[0] & 0xc0)!=0x80 || (p[1] & 0xc0)!=0x80 ) break;
-				p+=2;
-			}else{
-				break;
-			}
-		}
-		len+=1;
-	}
-	
-	p=(const char*)data;
-	
-	Rep *rep=Rep::alloc( len );
-	bbChar *d=rep->data;
-	
-	while( len-- ){
-		int c=*p++;
-		
-		if( c & 0x80 ){
-			if( (c & 0xe0)==0xc0 ){
-				c=((c & 0x1f)<<6) | (p[0] & 0x3f);
-				p+=1;
-			}else if( (c & 0xf0)==0xe0 ){
-				c=((c & 0x0f)<<12) | ((p[0] & 0x3f)<<6) | (p[1] & 0x3f);
-				p+=2;
-			}
-		}
-		*d++=c;
-	}
-	
-	return rep;
-}
-
-bbString bbString::fromAsciiData( const void *data,int size ){
-
-	if( !data || size<=0 ) return bbString();
-	
-	return bbString( (const char*)data,size );
-}
-
-bbString bbString::fromUtf8Data( const void *data,int size ){
-
-	if( !data || size<=0 ) return bbString();
-
-	const char *p=(const char*)data;
-	const char *e=p+size;
-
-	int len=0;
-		
-	while( p!=e ){
-		int c=*p++;
-		
-		if( c & 0x80 ){
-			if( (c & 0xe0)==0xc0 ){
-				if( p==e || (p[0] & 0xc0)!=0x80 ) break;
-				p+=1;
-			}else if( (c & 0xf0)==0xe0 ){
-				if( p==e || p+1==e || (p[0] & 0xc0)!=0x80 || (p[1] & 0xc0)!=0x80 ) break;
-				p+=2;
-			}else{
-				break;
-			}
-		}
-		len+=1;
-	}
-	
-	p=(const char*)data;
-	
-	Rep *rep=Rep::alloc( len );
-	bbChar *d=rep->data;
-	
-	while( len-- ){
-		int c=*p++;
-		
-		if( c & 0x80 ){
-			if( (c & 0xe0)==0xc0 ){
-				c=((c & 0x1f)<<6) | (p[0] & 0x3f);
-				p+=1;
-			}else if( (c & 0xf0)==0xe0 ){
-				c=((c & 0x0f)<<12) | ((p[0] & 0x3f)<<6) | (p[1] & 0x3f);
-				p+=2;
-			}
-		}
-		*d++=c;
-	}
-	
-	return rep;
-}
-
-
 bbArray<bbString> bbString::split( bbString sep )const{
 
 	if( !sep.length() ){

+ 35 - 122
modules/monkey/native/bbstring.h

@@ -64,8 +64,6 @@ class bbString{
 	
 	const char *c_str()const;
 	
-	const char *utf8_str()const;
-	
 	bbString():_rep( &_nullRep ){
 	}
 	
@@ -73,12 +71,22 @@ class bbString{
 		retain();
 	}
 	
-	template<class C> bbString( const C *data ):_rep( Rep::create( data ) ){
+	bbString( const void *data );
+	
+	bbString( const void *data,int length );
+	
+	bbString( const bbChar *data ):_rep( Rep::create( data ) ){
+	}
+	
+	bbString( const bbChar *data,int length ):_rep( Rep::create( data,length ) ){
 	}
 
-	template<class C> bbString( const C *data,int length ):_rep( Rep::create( data,length ) ){
+	bbString( const wchar_t *data ):_rep( Rep::create( data ) ){
 	}
 	
+	bbString( const wchar_t *data,int length ):_rep( Rep::create( data,length ) ){
+	}
+
 	bbString( bbInt n ){
 		char data[64];
 		sprintf( data,"%i",n );
@@ -444,166 +452,71 @@ class bbString{
 
 	void toWString( void *buf,int size )const;
 	
-	void toUtf8String( void *buf,int size )const;
-	
 	static bbString fromChar( int chr );
 	
-	static bbString fromCString( const void *data,int size=-1 );
-
-	static bbString fromWString( const void *data,int size=-1 );
+	static bbString fromCString( const void *data ){ return bbString( data ); }
 	
-	static bbString fromUtf8String( const void *data,int size=-1 );
+	static bbString fromCString( const void *data,int size ){ return bbString( data,size ); }
 	
-	static bbString fromAsciiData( const void *data,int size );
-
-	static bbString fromUtf8Data( const void *data,int size );
+	static bbString fromWString( const void *data ){ return bbString( (const wchar_t*)data ); }
 	
-	static bbString fromTString( const void *data,int size=-1 ){
-#if _WIN32
-		return fromCString( data,size );
-#else
-		return fromUtf8String( data,size );
-#endif
-	}
-
+	static bbString fromWString( const void *data,int size ){ return bbString( (const wchar_t*)data,size ); }
 };
 
 class bbCString{
-	bbString _str;
-	mutable char *_data=nullptr;
+	char *_data;
 	
 	public:
-	
-	bbCString( const bbString &str ):_str( str ){
-	}
-	
-	bbCString( const bbCString &str ):_str( str._str ){
+
+	bbCString( const bbString &str ){
+		int size=str.utf8Length()+1;
+		_data=(char*)malloc( size );
+		str.toCString( _data,size );
 	}
 	
 	~bbCString(){
 		free( _data );
 	}
 	
-	operator bbString()const{
-		return _str;
-	}
-	
-	bbCString &operator=( const bbCString &str ){
-		free( _data );
-		_data=nullptr;
-		_str=str._str;
-		return *this;
+	operator char*()const{
+		return _data;
 	}
 	
-	char *data()const{
-		if( _data ) return _data;
-		int size=_str.length()+1;
-		_data=(char*)malloc( size );
-		_str.toCString( _data,size );
-		return _data;
+	operator signed char*()const{
+		return (signed char*)_data;
 	}
 	
-	operator char*()const{
-		return data();
+	operator unsigned char*()const{
+		return (unsigned char*)_data;
 	}
 };
 
 class bbWString{
-	bbString _str;
-	mutable wchar_t *_data=nullptr;
+	wchar_t *_data;
 	
 	public:
 	
-	bbWString( const bbString &str ):_str( str ){
-	}
-	
-	bbWString( const bbWString &str ):_str( str._str ){
+	bbWString( const bbString &str ){
+		int size=(str.length()+1)*sizeof(wchar_t);
+		_data=(wchar_t*)malloc( size );
+		str.toWString( _data,size );
 	}
 	
 	~bbWString(){
 		free( _data );
 	}
 	
-	operator bbString()const{
-		return _str;
-	}
-	
-	bbWString &operator=( const bbWString &str ){
-		free( _data );
-		_data=nullptr;
-		_str=str._str;
-		return *this;
-	}
-	
-	wchar_t *data()const{
-		if( _data ) return _data;
-		int size=(_str.length()+1)*sizeof(wchar_t);
-		_data=(wchar_t*)malloc( size );
-		_str.toWString( _data,size );
-		return _data;
-	}
-	
 	operator wchar_t*()const{
-		return data();
-	}
-};
-
-class bbUtf8String{
-	bbString _str;
-	mutable unsigned char *_data=nullptr;
-	
-	public:
-	
-	bbUtf8String( const bbString &str ):_str( str ){
-	}
-	
-	bbUtf8String( const bbUtf8String &str ):_str( str._str ){
-	}
-	
-	~bbUtf8String(){
-		free( _data );
-	}
-	
-	bbUtf8String &operator=( const bbUtf8String &str ){
-		free( _data );
-		_data=nullptr;
-		_str=str._str;
-		return *this;
-	}
-	
-	operator bbString()const{
-		return _str;
-	}
-	
-	unsigned char *data()const{
-		if( _data ) return _data;
-		int size=_str.utf8Length()+1;
-		_data=(unsigned char*)malloc( size );
-		_str.toUtf8String( _data,size );
 		return _data;
 	}
-	
-	operator char*()const{
-		return (char*)data();
-	}
-	
-	operator unsigned char*()const{
-		return data();
-	}
 };
 
-#if _WIN32
-typedef bbCString bbTString;
-#else
-typedef bbUtf8String bbTString;
-#endif
-
 template<class C> bbString operator+( const C *str,const bbString &str2 ){
-	return bbString( str )+str2;
+	return bbString::fromCString( str )+str2;
 }
 
 inline bbString BB_T( const char *p ){
-	return bbString::fromUtf8String( p );
+	return bbString::fromCString( p );
 }
 
 inline void bbGCMark( const bbString &t ){

+ 105 - 66
modules/monkey/types.monkey2

@@ -3,18 +3,24 @@ Namespace monkey.types
 
 Extern
 
+#rem monkeydoc Implemented by numeric types.
+#end
 Interface INumeric
 End
 
+#rem monkeydoc Implemented by integral numeric types.
+#end
 Interface IIntegral Extends INumeric
 End
 
+#rem monkeydoc Implemented by real numeric types.
+#end
 Interface IReal Extends INumeric
 End
 
 #rem monkeydoc Primitive bool type.
 #end
-Struct @Bool Implements IIntegral ="bbBool"
+Struct @Bool ="bbBool"
 End
 
 #rem monkeydoc Primitive 8 bit byte type.
@@ -78,12 +84,22 @@ Struct @String ="bbString"
 	#end
 	Property Length:Int()="length"
 	
+	
 	#rem monkeydoc Gets the utf8 length of the string.
 	
 	@return The size of the buffer required to store a utf8 representation of the string.
 	
 	#end
 	Property Utf8Length:Int()="utf8Length"
+
+	
+	#rem monkeydoc Gets the CString length of the string.
+	
+	@return The size of the buffer required to store a cstring representation of the string.
+	
+	#end
+	Property CStringLength:Int()="utf8Length"
+
 	
 	#rem monkeydoc Finds a substring in the string.
 	
@@ -156,14 +172,57 @@ Struct @String ="bbString"
 	
 	Method Slice:String( from:Int,tail:Int )="slice"
 	
+	#rem monkeydoc Gets a substring from the start of the string.
+	
+	Returns a string consisting of the first `count` characters of this string.
+	
+	If `count` is less than or equal to 0, an empty string is returned.
+	
+	If `count` is greater than the length of this string, this string is returned.
+	
+	@param count The number of characters to return.
+
+	@return A string consisting of the first `count` characters of this string.
+	
+	#end
 	Method Left:String( count:Int )="left"
 	
+	#rem monkeydoc Gets a substring from the end of the string.
+
+	Returns a string consisting of the last `count` characters of this string.
+
+	If `count` is less than or equal to 0, an empty string is returned.
+	
+	If `count` is greater than the length of this string, this string is returned.
+	
+	@param count The number of characters to return.
+
+	@return A string consisting of the last `count` characters of this string.
+	
+	#end
 	Method Right:String( count:Int )="right"
 	
+	#rem monkeydoc Gets a substring from the middle of the string.
+	
+	Returns a string consisting of `count` characters starting from index `from`.
+	
+	If `count` is less than or equal to 0, an empty string is returned.
+	
+	If `from`+`count` is greater than the length of the string, the returned string is truncated.
+
+	@param from The index of the first character to return.
+
+	@param count The number of characters to return.
+
+	@return A string consisting of `count` characters starting from index `from`.
+	
+	#end
 	Method Mid:String( from:Int,count:Int )="mid"
 	
 	#rem monkeydoc Convert the string to uppercase.
 	
+	Return the string converted to uppercase.
+	
 	@return The string converted to uppercase.
 	
 	#end
@@ -171,6 +230,8 @@ Struct @String ="bbString"
 	
 	#rem monkeydoc Convert the string to lowercase.
 	
+	Returns the string converted to lowercase.
+	
 	@return The string converted to lowercase.
 	
 	#end
@@ -178,6 +239,8 @@ Struct @String ="bbString"
 
 	#rem monkeydoc Capitalizes the string.
 	
+	Returns the string with the first character converted to uppercase and the remaining characters unmodified.
+
 	@return The string with the first character converted to uppercase and the remaining characters unmodified.
 	
 	#end	
@@ -185,6 +248,8 @@ Struct @String ="bbString"
 	
 	#rem monkeydoc Trim whitespace from a string.
 	
+	Returns the string with leading and trailing whitespace removed.
+	
 	@return The string with leading and trailing whitespace removed.
 	
 	#end
@@ -192,6 +257,8 @@ Struct @String ="bbString"
 	
 	#rem monkeydoc Trim whitespace from the start a string.
 	
+	Returns the string with any leading whitespace removed.
+	
 	@return The string with any leading whitespace removed.
 	
 	#end
@@ -199,6 +266,8 @@ Struct @String ="bbString"
 	
 	#rem monkeydoc Trim whitespace from the end of a string.
 	
+	Returns the string with any trailing whitespace removed.
+
 	@return The string with any trailing whitespace removed.
 	
 	#end
@@ -206,18 +275,22 @@ Struct @String ="bbString"
 	
 	#rem monkeydoc Duplicates a string.
 	
+	Returns the string duplicated `count` times.
+	
 	@return The string duplicated `count` times.
 	
 	#end
 	Method Dup:String( count:Int )="dup"
 	
 	#rem monkeydoc Replace all occurances of a substring with another string.
+
+	Returns the string with all occurances of `find` replaced with `replace`.
 	
 	@param find The string to search for.
 	
 	@param replace The string to replace with.
 	
-	@return The string with `find` replaced with `replace`.
+	@return The string with all occurances of `find` replaced with `replace`.
 	
 	#end
 	Method Replace:String( find:String,replace:String )="replace"
@@ -244,6 +317,7 @@ Struct @String ="bbString"
 	#end
 	Method Join:String( bits:String[] )="join"
 	
+
 	#rem monkeydoc Converts the string to a CString.
 	
 	If there is enough room in the memory buffer, a null terminating '0' is appended to the CString.
@@ -255,7 +329,8 @@ Struct @String ="bbString"
 	#end
 	Method ToCString( buf:Void Ptr,bufSize:Int )="toCString"
 
-	#rem monkeydoc Converts the string to a WString
+
+	#rem monkeydoc Converts the string to a WString.
 	
 	If there is enough room in the memory buffer, a null terminating '0' is appended to the WString.
 	
@@ -266,17 +341,7 @@ Struct @String ="bbString"
 	#end
 	Method ToWString( buf:Void Ptr,bufSize:Int )="toWString"
 	
-	#rem monkeydoc Converts the string to a Utf8String
-	
-	If there is enough room in the memory buffer, a null terminating '0' is appended to the Utf8String.
-	
-	@param buf Memory buffer to write the Utf8String to.
-	
-	@param bufSize Size of the memory buffer in bytes.
-	
-	#end
-	Method ToUtf8String( buf:Void Ptr,bufSize:Int )="toUtf8String"
-	
+
 	#rem monkeydoc Creates a string containing a single character.
 	
 	@param chr The character.
@@ -284,9 +349,10 @@ Struct @String ="bbString"
 	#end
 	Function FromChar:String( chr:Int )="bbString::fromChar"
 	
-	#rem monkeydoc Creates a string from a null terminated CString.
 	
-	If `bufSize` is specified, only `bufsize` bytes at most bytes will be read.
+	#rem monkeydoc Creates a string from a CString.
+	
+	If `bufSize` is specified, the CString may contain null characters which will be included in the string.
 	
 	If `bufsize` is not specified, the CString must be correctly null terminated or Bad Things Will Happen.
 	
@@ -298,10 +364,11 @@ Struct @String ="bbString"
 	Function FromCString:String( buf:Void Ptr,bufSize:Int )="bbString::fromCString"
 
 	Function FromCString:String( buf:Void Ptr )="bbString::fromCString"
+
 	
 	#rem monkeydoc Creates a string from a null terminated WString.
 	
-	If `bufSize` is specified, only `bufsize` bytes at most bytes will be read.
+	If `bufSize` is specified, the WString may contain null characters which will be included in the string.
 	
 	If `bufsize` is not specified, the WString must be correctly null terminated or Bad Things Will Happen.
 	
@@ -314,27 +381,6 @@ Struct @String ="bbString"
 	
 	Function FromWString:String( buf:Void Ptr )="bbString::fromWString"
 	
-
-	#rem monkeydoc Creates a string from a null terminated Utf8String.
-	
-	If `bufSize` is specified, only `bufsize` bytes at most bytes will be read.
-	
-	If `bufsize` is not specified, the Utf8String must be correctly null terminated or Bad Things Will Happen.
-	
-	@param buf The memory buffer containing the Utf8String.
-	
-	@param bufSize The size of the memory buffer in bytes.
-	
-	#end	
-	Function FromUtf8String:String( buf:Void Ptr,bufSize:Int )="bbString::fromUtf8String"
-	
-	Function FromUtf8String:String( buf:Void Ptr )="bbString::fromUtf8String"
-	
-	
-	Function FromAsciiData:String( buf:Void Ptr,bufSize:Int )="bbString::fromAsciiData"
-
-	Function FromUtf8Data:String( buf:Void Ptr,bufSize:Int )="bbString::fromUtf8Data"
-	
 End
 
 #rem monkeydoc Primtive array type.
@@ -358,8 +404,7 @@ Struct @Array<T>
 	
 	#rem monkeydoc Extracts a subarray from the array.
 	
-	Returns an array consisting of all elements from `from` until (but not including) `tail`, or until the end of the string
-	if `tail` is not specified.
+	Returns an array consisting of all elements from `from` until (but not including) `tail`, or until the end of the string if `tail` is not specified.
 	
 	If either `from` or `tail` is negative, it represents an offset from the end of the array.
 	
@@ -377,7 +422,9 @@ Struct @Array<T>
 	
 	#rem monkeydoc Resizes an array.
 	
-	Returns a copy of the array resized to length `newLength'.
+	Returns a copy of the array resized to length `newLength`.
+	
+	Note that this method does not modify this array in any way.
 	
 	@param newLength The length of the new array.
 	
@@ -388,13 +435,28 @@ Struct @Array<T>
 	
 	#rem monkeydoc Gets the size of a single array dimension.
 	
+	Returns The size of the array in the given dimension.
+	
 	@param dimensions The dimension.
 	
-	@return The size of array in the given dimension.
+	@return The size of the array in the given dimension.
 	
 	#end
 	Method GetSize:Int( dimension:Int )="size"
 	
+	#rem monkeydoc Copies a range of elements from this array to another.
+	
+	In debug mode, a runtime error will occur if the copy is outside the range of the array.
+	
+	@param dstArray destination of the copy.
+	
+	@param srcOffset First element to copy from this array.
+	
+	@param dstOffset First element to copy to in destination array.
+	
+	@param count Number of elements to copy.
+	
+	#end
 	Method CopyTo( dstArray:T[],srcOffset:Int,dstOffset:Int,count:Int )="copyTo"
 
 End
@@ -410,26 +472,11 @@ Class @Object="bbObject"
 End
 
 #rem monkeydoc Base class of all throwable objects.
-#end
-Class @Throwable="bbThrowable"
 
-End
-
-#rem
-#rem monkeydoc Base class of all exception objects.
 #end
-Class @Exception Extends Throwable="bbException"
-
-	Method New()
-	
-	Method New( message:String )
-
-	Property Message:String()="message"
+Class @Throwable="bbThrowable"
 
-	Property DebugStack:String[]()="debugStack"
-	
 End
-#end
 
 #rem monkeydoc @hidden
 #end
@@ -450,11 +497,3 @@ This type should only be used when declaring parameters for extern functions.
 #end
 Struct WString="bbWString"
 End
-
-#rem monkeydoc String wrapper type for native utf8 'unsigned char*' strings.
-
-This type should only be used when declaring parameters for extern functions.
-
-#end
-Struct Utf8String="bbUtf8String"
-End

+ 17 - 17
modules/sdl2/sdl2.monkey2

@@ -216,7 +216,7 @@ Const SDL_GL_CONTEXT_RELEASE_BEHAVIOR_NONE:SDL_GLcontextReleaseFlag
 Const SDL_GL_CONTEXT_RELEASE_BEHAVIOR_FLUSH:SDL_GLcontextReleaseFlag
 Function SDL_GetNumVideoDrivers:Int()
 Function SDL_GetVideoDriver:char_t Ptr(index_:Int)
-Function SDL_VideoInit:Int(driver_name_:Utf8String)
+Function SDL_VideoInit:Int(driver_name_:CString)
 Function SDL_VideoQuit:Void()
 Function SDL_GetCurrentVideoDriver:char_t Ptr()
 Function SDL_GetNumVideoDisplays:Int()
@@ -232,16 +232,16 @@ Function SDL_GetWindowDisplayIndex:Int(window_:SDL_Window Ptr)
 Function SDL_SetWindowDisplayMode:Int(window_:SDL_Window Ptr,mode_:SDL_DisplayMode Ptr)
 Function SDL_GetWindowDisplayMode:Int(window_:SDL_Window Ptr,mode_:SDL_DisplayMode Ptr)
 Function SDL_GetWindowPixelFormat:Int(window_:SDL_Window Ptr)
-Function SDL_CreateWindow:SDL_Window Ptr(title_:Utf8String,x_:Int,y_:Int,w_:Int,h_:Int,flags_:Int)
+Function SDL_CreateWindow:SDL_Window Ptr(title_:CString,x_:Int,y_:Int,w_:Int,h_:Int,flags_:Int)
 Function SDL_CreateWindowFrom:SDL_Window Ptr(data_:Void Ptr)
 Function SDL_GetWindowID:Int(window_:SDL_Window Ptr)
 Function SDL_GetWindowFromID:SDL_Window Ptr(id_:Int)
 Function SDL_GetWindowFlags:Int(window_:SDL_Window Ptr)
-Function SDL_SetWindowTitle:Void(window_:SDL_Window Ptr,title_:Utf8String)
+Function SDL_SetWindowTitle:Void(window_:SDL_Window Ptr,title_:CString)
 Function SDL_GetWindowTitle:char_t Ptr(window_:SDL_Window Ptr)
 Function SDL_SetWindowIcon:Void(window_:SDL_Window Ptr,icon_:SDL_Surface Ptr)
-Function SDL_SetWindowData:Void Ptr(window_:SDL_Window Ptr,name_:Utf8String,userdata_:Void Ptr)
-Function SDL_GetWindowData:Void Ptr(window_:SDL_Window Ptr,name_:Utf8String)
+Function SDL_SetWindowData:Void Ptr(window_:SDL_Window Ptr,name_:CString,userdata_:Void Ptr)
+Function SDL_GetWindowData:Void Ptr(window_:SDL_Window Ptr,name_:CString)
 Function SDL_SetWindowPosition:Void(window_:SDL_Window Ptr,x_:Int,y_:Int)
 Function SDL_GetWindowPosition:Void(window_:SDL_Window Ptr,x_:Int Ptr,y_:Int Ptr)
 Function SDL_SetWindowSize:Void(window_:SDL_Window Ptr,w_:Int,h_:Int)
@@ -285,10 +285,10 @@ Function SDL_DestroyWindow:Void(window_:SDL_Window Ptr)
 Function SDL_IsScreenSaverEnabled:SDL_bool()
 Function SDL_EnableScreenSaver:Void()
 Function SDL_DisableScreenSaver:Void()
-Function SDL_GL_LoadLibrary:Int(path_:Utf8String)
-Function SDL_GL_GetProcAddress:Void Ptr(proc_:Utf8String)
+Function SDL_GL_LoadLibrary:Int(path_:CString)
+Function SDL_GL_GetProcAddress:Void Ptr(proc_:CString)
 Function SDL_GL_UnloadLibrary:Void()
-Function SDL_GL_ExtensionSupported:SDL_bool(extension_:Utf8String)
+Function SDL_GL_ExtensionSupported:SDL_bool(extension_:CString)
 Function SDL_GL_ResetAttributes:Void()
 Function SDL_GL_SetAttribute:Int(attr_:SDL_GLattr,value_:Int)
 Function SDL_GL_GetAttribute:Int(attr_:SDL_GLattr,value_:Int Ptr)
@@ -350,7 +350,7 @@ Function SDL_WarpMouseGlobal:Void(x_:Int,y_:Int)
 Function SDL_SetRelativeMouseMode:Int(enabled_:SDL_bool)
 Function SDL_CaptureMouse:Int(enabled_:SDL_bool)
 Function SDL_GetRelativeMouseMode:SDL_bool()
-Function SDL_CreateCursor:SDL_Cursor Ptr(data_:Utf8String,mask_:Utf8String,w_:Int,h_:Int,hot_x_:Int,hot_y_:Int)
+Function SDL_CreateCursor:SDL_Cursor Ptr(data_:CString,mask_:CString,w_:Int,h_:Int,hot_x_:Int,hot_y_:Int)
 Function SDL_CreateColorCursor:SDL_Cursor Ptr(surface_:SDL_Surface Ptr,hot_x_:Int,hot_y_:Int)
 Function SDL_CreateSystemCursor:SDL_Cursor Ptr(id_:SDL_SystemCursor)
 Function SDL_SetCursor:Void(cursor_:SDL_Cursor Ptr)
@@ -384,7 +384,7 @@ Function SDL_JoystickName:char_t Ptr(joystick_:SDL_Joystick Ptr)
 Function SDL_JoystickGetDeviceGUID:SDL_JoystickGUID(device_index_:Int)
 Function SDL_JoystickGetGUID:SDL_JoystickGUID(joystick_:SDL_Joystick Ptr)
 Function SDL_JoystickGetGUIDString:Void(guid_:SDL_JoystickGUID,pszGUID_:char_t Ptr ,cbGUID_:Int)
-Function SDL_JoystickGetGUIDFromString:SDL_JoystickGUID(pchGUID_:Utf8String)
+Function SDL_JoystickGetGUIDFromString:SDL_JoystickGUID(pchGUID_:CString)
 Function SDL_JoystickGetAttached:SDL_bool(joystick_:SDL_Joystick Ptr)
 Function SDL_JoystickInstanceID:SDL_JoystickID(joystick_:SDL_Joystick Ptr)
 Function SDL_JoystickNumAxes:Int(joystick_:SDL_Joystick Ptr)
@@ -692,9 +692,9 @@ Function SDL_SetModState:Void(modstate_:SDL_Keymod)
 Function SDL_GetKeyFromScancode:SDL_Keycode(scancode_:SDL_Scancode)
 Function SDL_GetScancodeFromKey:SDL_Scancode(key_:SDL_Keycode)
 Function SDL_GetScancodeName:char_t Ptr(scancode_:SDL_Scancode)
-Function SDL_GetScancodeFromName:SDL_Scancode(name_:Utf8String)
+Function SDL_GetScancodeFromName:SDL_Scancode(name_:CString)
 Function SDL_GetKeyName:char_t Ptr(key_:SDL_Keycode)
-Function SDL_GetKeyFromName:SDL_Keycode(name_:Utf8String)
+Function SDL_GetKeyFromName:SDL_Keycode(name_:CString)
 Function SDL_StartTextInput:Void()
 Function SDL_IsTextInputActive:SDL_bool()
 Function SDL_StopTextInput:Void()
@@ -1066,14 +1066,14 @@ End
 Alias SDL_AudioFilter:Void(SDL_AudioCVT Ptr,SDL_AudioFormat)
 Function SDL_GetNumAudioDrivers:Int()
 Function SDL_GetAudioDriver:char_t Ptr(index_:Int)
-Function SDL_AudioInit:Int(driver_name_:Utf8String)
+Function SDL_AudioInit:Int(driver_name_:CString)
 Function SDL_AudioQuit:Void()
 Function SDL_GetCurrentAudioDriver:char_t Ptr()
 Function SDL_OpenAudio:Int(desired_:SDL_AudioSpec Ptr,obtained_:SDL_AudioSpec Ptr)
 Alias SDL_AudioDeviceID:Int
 Function SDL_GetNumAudioDevices:Int(iscapture_:Int)
 Function SDL_GetAudioDeviceName:char_t Ptr(index_:Int,iscapture_:Int)
-Function SDL_OpenAudioDevice:SDL_AudioDeviceID(device_:Utf8String,iscapture_:Int,desired_:SDL_AudioSpec Ptr,obtained_:SDL_AudioSpec Ptr,allowed_changes_:Int)
+Function SDL_OpenAudioDevice:SDL_AudioDeviceID(device_:CString,iscapture_:Int,desired_:SDL_AudioSpec Ptr,obtained_:SDL_AudioSpec Ptr,allowed_changes_:Int)
 Enum SDL_AudioStatus
 End
 Const SDL_AUDIO_STOPPED:SDL_AudioStatus
@@ -1089,8 +1089,8 @@ Function SDL_FreeWAV:Void(audio_buf_:Byte Ptr)
 Function SDL_BuildAudioCVT:Int(cvt_:SDL_AudioCVT Ptr,src_format_:SDL_AudioFormat,src_channels_:Byte,src_rate_:Int,dst_format_:SDL_AudioFormat,dst_channels_:Byte,dst_rate_:Int)
 Function SDL_ConvertAudio:Int(cvt_:SDL_AudioCVT Ptr)
 Const SDL_MIX_MAXVOLUME:Int
-Function SDL_MixAudio:Void(dst_:Byte Ptr,src_:Utf8String,len_:Int,volume_:Int)
-Function SDL_MixAudioFormat:Void(dst_:Byte Ptr,src_:Utf8String,format_:SDL_AudioFormat,len_:Int,volume_:Int)
+Function SDL_MixAudio:Void(dst_:Byte Ptr,src_:CString,len_:Int,volume_:Int)
+Function SDL_MixAudioFormat:Void(dst_:Byte Ptr,src_:CString,format_:SDL_AudioFormat,len_:Int,volume_:Int)
 Function SDL_QueueAudio:Int(dev_:SDL_AudioDeviceID,data_:Void Ptr,len_:Int)
 Function SDL_GetQueuedAudioSize:Int(dev_:SDL_AudioDeviceID)
 Function SDL_ClearQueuedAudio:Void(dev_:SDL_AudioDeviceID)
@@ -1103,7 +1103,7 @@ Function SDL_CloseAudioDevice:Void(dev_:SDL_AudioDeviceID)
 
 'FILE="sdl2/SDL_clipboard.h"
 
-Function SDL_SetClipboardText( text:Utf8String )
+Function SDL_SetClipboardText( text:CString )
 
 Function SDL_GetClipboardText:char_t Ptr()
 

+ 4 - 4
modules/std/filesystem/native/filesystem.cpp

@@ -126,11 +126,11 @@ namespace bbFileSystem{
 	
 #if _WIN32
 
-		return CopyFileA( bbTString( srcPath ),bbTString( dstPath ),FALSE );
+		return CopyFileW( bbWString( srcPath ),bbWString( dstPath ),FALSE );
 		
 #elif __APPLE__
 
-		int ret=copyfile( bbTString( srcPath ),bbTString( dstPath ),0,COPYFILE_ALL );
+		int ret=copyfile( bbCString( srcPath ),bbCString( dstPath ),0,COPYFILE_ALL );
 		
 		if( ret>=0 ) return true;
 		
@@ -144,9 +144,9 @@ namespace bbFileSystem{
 		//TODO: use sendfile() here?
 		//
 		int err=-1;
-		if( FILE *srcp=fopen( bbTString( srcPath ),"rb" ) ){
+		if( FILE *srcp=fopen( bbCString( srcPath ),"rb" ) ){
 			err=-2;
-			if( FILE *dstp=fopen( bbTString( dstPath ),"wb" ) ){
+			if( FILE *dstp=fopen( bbCString( dstPath ),"wb" ) ){
 				err=0;
 				char buf[1024];
 				while( int n=fread( buf,1,1024,srcp ) ){

+ 8 - 27
modules/std/memory/databuffer.monkey2

@@ -263,27 +263,21 @@ Class DataBuffer Extends std.resource.Resource
 	
 	If `count` is omitted, all bytes from `offset` until the end of the data buffer are read.
 	
-	`encoding` should be one of "utf8" or "ansi".
-
 	@param offset Byte offset to read the string.
 	
 	@param count Number of bytes to read.
 	
-	@param encoding The encoding to use.
-	
 	#end
-	Method PeekString:String( offset:Int,encoding:String="utf8" )
+	Method PeekString:String( offset:Int )
 		DebugAssert( offset>=0 And offset<=_length )
 		
-		Return PeekString( offset,_length-offset,encoding )
+		Return PeekString( offset,_length-offset )
 	End
 	
-	Method PeekString:String( offset:Int,count:Int,encoding:String="utf8" )
+	Method PeekString:String( offset:Int,count:Int )
 		DebugAssert( offset>=0 And count>=0 And offset+count<=_length )
 
-		If encoding="ansi" Or encoding="ascii" Return String.FromAsciiData( _data+offset,count )
-		
-		Return String.FromUtf8Data( _data+offset,count )
+		Return String.FromCString( _data+offset,count )
 	End
 	
 	#rem monkeydoc Writes a byte to the databuffer
@@ -426,32 +420,19 @@ Class DataBuffer Extends std.resource.Resource
 
 	#rem monkeydoc Write a string to the databuffer.
 
-	`encoding` should be one of "utf8" or "ansi".
-	
 	If there is not enough room in the data buffer, the string data is truncated.
 	
 	@param offset Byte offset to write the string.
 	
 	@param value The string to write.
 	
-	@param encoding The encoding to use.
-	
 	#end	
-	Method PokeString( offset:Int,value:String,encoding:String="utf8" )
+	Method PokeString( offset:Int,value:String )
 		DebugAssert( offset>=0 And offset<=_length )
 		
-		DebugAssert( encoding="utf8" Or encoding="ascii" )
-		
-		If encoding="ansi" Or encoding="ascii"
-			Local count:=value.Length
-			If offset+count>_length count=_length-offset
-			value.ToCString( _data+offset,count )
-		Else
-			Local count:=value.Utf8Length
-			If offset+count>_length count=_length-offset
-			value.ToUtf8String( _data+offset,count )
-		Endif
-
+		Local count:=value.Length
+		If offset+count>_length count=_length-offset
+		value.ToCString( _data+offset,count )
 	End
 
 	#rem monkeydoc Creates a slice of the databuffer.

+ 7 - 24
modules/std/misc/stringio.monkey2

@@ -9,25 +9,17 @@ An empty string will be returned if the file could not be opened.
 
 @param path The path of the file.
 
-@param encoding The string encoding to use, "utf8" or "ansi".
-
-@param fixeols If true, converts eols to UNIX "~n" eols.
+@param fixeols If true, converts eols to UNIX "~n" eols after loading.
 
 @return A String containing the contents of the file. 
 
 #end
-Function LoadString:String( path:String,encoding:String="utf8",fixeols:Bool=False )
+Function LoadString:String( path:String,fixeols:Bool=False )
 
 	Local data:=DataBuffer.Load( path )
 	If Not data Return ""
-
-	Local str:=""
 	
-	If encoding="ansi" Or encoding="ascii"
-		 str=String.FromAsciiData( data.Data,data.Length )
-	Else
-		 str=String.FromUtf8Data( data.Data,data.Length )
-	End
+	Local str:=String.FromCString( data.Data,data.Length )
 	
 	data.Discard()
 	
@@ -45,29 +37,20 @@ End
 
 @param path The path of the file.
 
-@param encoding The string encoding to use, "utf8" or "ansi".
-
-@param fixeols If true, converts eols to UNIX "~n" eols.
+@param fixeols If true, converts eols to UNIX "~n" eols before saving.
 
 @return False if the file could not be opened.
 
 #end
-Function SaveString:Bool( str:String,path:String,encoding:String="utf8",fixeols:Bool=False )
+Function SaveString:Bool( str:String,path:String,fixeols:Bool=False )
 
 	If fixeols
 		str=str.Replace( "~r~n","~n" )
 		str=str.Replace( "~r","~n" )
 	Endif
 	
-	Local data:DataBuffer
-	
-	If encoding="ansi" Or encoding="ascii"
-		data=New DataBuffer( str.Length )
-		str.ToCString( data.Data,data.Length )
-	Else
-		data=New DataBuffer( str.Utf8Length )
-		str.ToUtf8String( data.Data,data.Length )
-	End
+	Local data:=New DataBuffer( str.CStringLength )
+	str.ToCString( data.Data,data.Length )
 	
 	Local ok:=data.Save( path )
 	

+ 1 - 1
modules/std/process/native/process.cpp

@@ -276,7 +276,7 @@ bbString bbProcess::readStdout(){
 
 	if( !_rep || !_rep->stdoutAvail ) return "";
 
-	bbString str=bbString::fromUtf8String( _rep->stdoutGet,_rep->stdoutAvail );
+	bbString str=bbString::fromCString( _rep->stdoutGet,_rep->stdoutAvail );
 	
 	_rep->stdoutAvail=0;
 	

+ 11 - 26
modules/std/stream/stream.monkey2

@@ -292,31 +292,29 @@ Class Stream
 	
 	#rem monkeydoc Reads the entire stream into a string.
 	#end
-	Method ReadString:String( encoding:String="utf8" )
+	Method ReadString:String()
 		Local data:=ReadAll()
-		Local str:=data.PeekString( 0,encoding )
+		Local str:=data.PeekString( 0 )
 		data.Discard()
 		Return str
 	End
 	
 	#rem monkeydoc Reads a null terminated string from the stream.
 	
-	@param encoding The string encoding, "utf8" or "ansi".
-	
 	@return the string read.
 	
 	#end
-	Method ReadCString:String( encoding:String="utf8" )
+	Method ReadNullTerminatedString:String()
+	
 		Local buf:=New Stack<Byte>
+		
 		While Not Eof
 			Local chr:=ReadByte()
 			If Not chr Exit
 			buf.Push( chr )
 		Wend
 		
-		If encoding="ansi" Or encoding="ascii" Return String.FromAsciiData( buf.Data.Data,buf.Length )
-		
-		Return String.FromUtf8Data( buf.Data.Data,buf.Length )
+		Return String.FromCString( buf.Data.Data,buf.Length )
 	End
 	
 	#rem monkeydoc Writes a byte to the stream.
@@ -424,24 +422,11 @@ Class Stream
 	@param str The string to write.
 	
 	#end
-	Method WriteString( str:String,encoding:String="utf8" )
-		Local size:=(encoding="utf8" ? str.Utf8Length Else str.Length)
-		Local buf:=New DataBuffer( size )
-		buf.PokeString( 0,str,encoding )
-		Write( buf,0,size )
-	End
-	
-	#rem monkeydoc Writes a null terminated string to the stream.
-
-	@param str The string to write.
-	
-	#end
-	Method WriteCString( str:String,encoding:String="utf8" )
-		Local size:=(encoding="utf8" ? str.Utf8Length Else str.Length)+1
-		Local buf:=New DataBuffer( size )
-		buf.PokeString( 0,str,encoding )
-		buf.PokeByte( size-1,0 )
-		Write( buf,0,size )
+	Method WriteString( str:String )
+		Local buf:=New DataBuffer( str.CStringLength )
+		buf.PokeString( 0,str )
+		Write( buf,0,buf.Length )
+		buf.Discard()
 	End
 	
 	#rem monkeydoc Opens a stream

+ 7 - 7
modules/tinyxml2/native/glue.cpp

@@ -4,11 +4,11 @@
 namespace tinyxml2{
 
 	bbString bbAttributeName( XMLAttribute *attribute ){
-		return bbString::fromUtf8String( attribute->Name() );
+		return bbString::fromCString( attribute->Name() );
 	}
 	
 	bbString bbAttributeValue( XMLAttribute *attribute ){
-		return bbString::fromUtf8String( attribute->Value() );
+		return bbString::fromCString( attribute->Value() );
 	}
 	
 	XMLAttribute *bbAttributeNext( XMLAttribute *attribute ){
@@ -16,18 +16,18 @@ namespace tinyxml2{
 	}
 	
 	bbString bbNodeValue( XMLNode *node ){
-		return bbString::fromUtf8String( node->Value() );
+		return bbString::fromCString( node->Value() );
 	}
 	
 	bbString bbElementName( XMLElement *element ){
-		return bbString::fromUtf8String( element->Name() );
+		return bbString::fromCString( element->Name() );
 	}
 	
 	bbString bbElementAttribute( XMLElement *element,bbString name,bbString value ){
-		bbUtf8String cstr( value );
+		bbCString cstr( value );
 		const char *p=0;
 		if( value.length() ) p=cstr;
-		return bbString::fromUtf8String( element->Attribute( bbUtf8String( name ),p ) );
+		return bbString::fromCString( element->Attribute( bbCString( name ),p ) );
 	}
 	
 	XMLAttribute *bbElementFirstAttribute( XMLElement *element ){
@@ -35,7 +35,7 @@ namespace tinyxml2{
 	}
 	
 	bbString bbElementGetText( XMLElement *element ){
-		return bbString::fromUtf8String( element->GetText() );
+		return bbString::fromCString( element->GetText() );
 	}
 
 	void bbDocumentDestroy( XMLDocument *doc ){

+ 12 - 12
modules/tinyxml2/tinyxml2.monkey2

@@ -84,7 +84,7 @@ End
 
 Class XMLDocument Extends XMLNode="tinyxml2::XMLDocument"
 
-	Method Parse:XMLError( xml:Utf8String )
+	Method Parse:XMLError( xml:CString )
 	
 	Method PrintDocument()="Print"
 	
@@ -101,27 +101,27 @@ Class XMLElement Extends XMLNode="tinyxml2::XMLElement"
 	
 	Method Attribute:String( name:String,value:String="" ) Extension="tinyxml2::bbElementAttribute"
 	
-	Method IntAttribute:Int( name:Utf8String )
+	Method IntAttribute:Int( name:CString )
 	
-	Method UnsignedAttribute:UInt( name:Utf8String )
+	Method UnsignedAttribute:UInt( name:CString )
 	
-	Method BoolAttribute:Bool( name:Utf8String )
+	Method BoolAttribute:Bool( name:CString )
 	
-	Method DoubleAttribute:Double( name:Utf8String )
+	Method DoubleAttribute:Double( name:CString )
 	
-	Method FloatAttribute:Float( name:Utf8String )
+	Method FloatAttribute:Float( name:CString )
 	
-	Method QueryIntAttribute:XMLError( name:Utf8String,value:Int Ptr )
+	Method QueryIntAttribute:XMLError( name:CString,value:Int Ptr )
 	
-	Method QueryUnsignedAttribute:XMLError( name:Utf8String,value:UInt Ptr )
+	Method QueryUnsignedAttribute:XMLError( name:CString,value:UInt Ptr )
 	
-	Method QueryBoolAttribute:XMLError( name:Utf8String,value:Bool Ptr )
+	Method QueryBoolAttribute:XMLError( name:CString,value:Bool Ptr )
 	
-	Method QueryDoubleAttribute:XMLError( name:Utf8String,value:Double Ptr )
+	Method QueryDoubleAttribute:XMLError( name:CString,value:Double Ptr )
 	
-	Method QueryFloatAttribute:XMLError( name:Utf8String,value:Float Ptr )
+	Method QueryFloatAttribute:XMLError( name:CString,value:Float Ptr )
 	
-	Method QueryAttribute:Int( name:Utf8String,value:Int Ptr )
+	Method QueryAttribute:Int( name:CString,value:Int Ptr )
 	
 	Method FirstAttribute:XMLAttribute() Extension="tinyxml2::bbElementFirstAttribute"