String
public const class
{
@content: char[]
@length: int
}
struct ix_base_String
{
ix_base_Object
parent;
const char*
(*getContent)( const ix_base_String* self );
ix_base_Object*
asObject;
ix_base_String*
(*delete)( ix_base_String** self );
};
struct ix_base_String_Ref
{
ix_base_Object
parent;
const char*
(*getContent)( const ix_base_String_Ref* self );
ix_base_Object*
asObject;
;
};
#endif
struct ix_base_String_private
{
ix_base_String
public;
char*
content;
int
length;
ix_base_Object*
(*ix_base_Object_delete)( ix_base_Object** self );
};
class String : public Object {
public:
char* content;
int length;
static String* New( const char* content = "" );
static String* Delete( const String* self );
const char* getContent() const;
String( const char* content = "" );
~String();
public class String {
string content;
int length;
typedef union UString
{
struct ix_base_Object parent;
struct ix_base_String public;
struct ix_base_String_private private;
} UString;
static UString* Cast( const ix_base_String* self ) { return (UString*) self; }
Constructors
public new( content: char[] )
{
@content = content
@length = content.length
}
ix_base_String* ix_base_String_new( ix_base_String* self, const char* content )
{
if ( !self ) self = calloc( 1, ix_base_String_sz() );
if ( self )
{
ix_base_Object_new( (ix_base_Object*) self );
{
struct ix_base_String_private* _self = (struct ix_base_String_private*) self;
_self->content = stringCopy( content );
_self->length = strlen( _self->content );
_self->ix_base_Object_delete = _self->public.parent.delete;
_self->public.parent.delete = (ix_base_Object*(*)(ix_base_Object**)) ix_base_String_delete;
_self->public.delete = ix_base_String_delete;
_self->public.getContent = ix_base_String_getContent;
}
self->asObject = &self->parent;
}
return self;
}
String*
String::New( const char* content )
{
return new String( content );
}
String::String( const char* content )
{
this->content = stringCopy( content );
this->length = strlen( this->content );
}
public String( string content )
{
this.content = content;
this.length = content.Length;
}
public String( string head, string tail )
{
this.content = head + tail;
this.length = this.content.Length;
}
Destructors
ix_base_String* ix_base_String_delete( ix_base_String** self )
{
struct ix_base_String_private* _self = (struct ix_base_String_private*) *self;
if ( _self )
{
free( _self->content ); _self->content = NULL;
_self->length = 0;
*self = (ix_base_String*) _self->ix_base_Object_delete( (ix_base_Object**) self );
}
return NULL;
}
String*
String::Delete( const String* self )
{
delete self; return NULL;
}
String::~String()
{
free( this->content ); this->content = NULL;
this->length = 0;
}
String delete()
{
this.content = null;
this.length = 0;
return null;
}
Const methods
public const contains( substring: String& ): bool
{
return @content.contains( slice: substring.content )
}
public const getContent( index: int ): char
{
return @content[index]
}
const char* ix_base_String_getContent( const ix_base_String* self )
{
return Cast( self )->private.content;
}
const char*
String::getContent() const
{
return this->content;
}
public string getContent()
{
return this.content;
}
public const append( suffix: String ): String
{
return new String( @content, suffix )
}
public String append( String suffix )
{
return new String( this.content, suffix.getContent() );
}
public const indexOf( substring: String&, after: int = 0 ): int
{
return @content.indexOf( slice: substring.content, after: after )
}
public const substring( startIndex: int, length: int ): String
{
return new( content: @content.slice( startIndex, length ) )
}
char* stringCopy( const char* aString )
{
char* copy = calloc( strlen( aString) + 1, sizeof( char ) );
strcpy( copy, aString );
return copy;
}
char* stringCopy( const char* aString )
{
char* copy = (char*) calloc( strlen( aString) + 1, sizeof( char ) );
strcpy( copy, aString );
return copy;
}
unsigned long ix_base_String_sz()
{
return sizeof( struct ix_base_String_private ) + ix_base_Object_sz();
}
const ix_base_String_Ref*
ix_base_String_const_ref_cast( const ix_base_String* self )
{ return (const ix_base_String_Ref*) self; }
}; // end class
} // end namespace
#endif