String/sprintf alternative specifically for Arduino.

Docedison:
Will I need to copy the files to all the Arduino installations?.

Not a dumb question, for the printf functionality, yes you will need to install it into the core.

I'm going to do up a new GString.h which will include all the functionality except the built in Print::printf ( not possible without inclusion into the core ).

The string sprintf, GString, PString & EString will all be available for reading and writing where applicable using printf.

I'm going to make the new include Due compatible as well. Maybe I can modify the printf functionality so it can pipe the output down any Print enabled class, so you can use something like this ( only an idea ):

//In setup.
SetPrintTarget( Serial );

//Later on in code.
printf( "Test number: %d", 1234 ); //Gets spit down serial.

This is a very viable option which I'll implement soon, I however do prefer the object orientated approach ( Serial.printf(); ),
whereas this method may help the c-style programmers feel more at home.

However the built in methods ( can have both ), can be tailored to use the smallest footprint. One example is the String library, it uses itoa, ltoa and such. These can be rewritten to use GString, so there is potentially less code to compile, and the String lib uses them automatically. Even memory handling can rewritten using the GStirng.

Here is a small selection of re-implementations for:

  • memset
  • memcpy
  • strcpy
  • strcat
  • ftoa
  • itoa
  • utoa
  • ltoa
  • ultoa
	inline void *memset( void *ptr, int value, size_t num )
		{
			GString( ptr ).repeat( value, num );
			return ptr;
		}
		
	inline void *memcpy( void * destination, const void * source, size_t num )
		{
			GString( destination ).write( ( uint8_t* ) source, num );
			return destination;
		}	
		
	inline char *strcpy( char *destination, const char *source )
		{
			GString( destination ).print( source );
			return destination;
		}

	inline char *strcat( char *destination, const char *source )
		{
			GString( strchr( destination, 0x00 ) ).print( source );
			return destination;
		}		
		
	inline char *ftoa( float value, char * str )
		{
			GString( str ).print( value );
			return str;
		}

	inline char *itoa( int value, char * str, int base )
		{
			GString( str ).print( ( long ) value, base );
			return str;
		}
		
	inline char *utoa( unsigned int value, char * str, int base )
		{
			GString( str ).print( ( unsigned long ) value, base );
			return str;
		}		
		
	inline char *ltoa( long value, char * str, int base )
		{
			GString( str ).print( value, base );
			return str;
		}
		
	inline char *ultoa( unsigned long value, char * str, int base )
		{
			GString( str ).print( value, base );
			return str;
		}