Etk
Main Page Object Hierarchy Data Structures Related Pages
Etk

Etk_String


Detailed Description

An object that offers convenient methods to manipulate a string.

TODOC

Object Hierarchy:
  • Etk_Object
    • Etk_String
Properties:
  • "string": the value of the string
    • Type: String (char *)
    • Access: Read/Write
    • Default Value: NULL


Data Structures

struct  Etk_String
 [Widget] Etk_String is an object that offers convenient methods to manipulate a string More...

Defines

#define ETK_STRING_TYPE   (etk_string_type_get())
#define ETK_STRING(obj)   (ETK_OBJECT_CAST((obj), ETK_STRING_TYPE, Etk_String))
#define ETK_IS_STRING(obj)   (ETK_OBJECT_CHECK_TYPE((obj), ETK_STRING_TYPE))

Functions

Etk_String * etk_string_new (const char *value)
 Creates a new string.
Etk_String * etk_string_new_sized (const char *value, int size)
 Creates a new string, with a specific size.
Etk_String * etk_string_new_printf (const char *format,...)
 Creates a new string, and sets its default value from the given format and arguments.
Etk_String * etk_string_new_vprintf (const char *format, va_list args)
 Creates a new string, and sets its default value from the given format and arguments.
Etk_String * etk_string_copy (const Etk_String *string)
 Creates a new string and copies the text from string.
const char * etk_string_get (Etk_String *string)
 Gets the string as an array of chars.
int etk_string_length_get (Etk_String *string)
 Gets the length of the string.
Etk_String * etk_string_truncate (Etk_String *string, int length)
 Truncates the string.
Etk_String * etk_string_delete (Etk_String *string, int pos, int size)
 Removes from the string a segment of size chars from the position pos.
Etk_String * etk_string_clear (Etk_String *string)
 Clears the string: all the allocated memory will be freed, and the length of the string will be set to 0.
Etk_String * etk_string_set (Etk_String *string, const char *value)
 Sets the value of a string.
Etk_String * etk_string_set_sized (Etk_String *string, const char *value, int size)
 Sets the value of a string, with a specific size.
Etk_String * etk_string_set_printf (Etk_String *string, const char *format,...)
 Sets the value of the string from the given format and arguments.
Etk_String * etk_string_set_vprintf (Etk_String *string, const char *format, va_list args)
 Sets the value of the string from the format and the arguments.
Etk_String * etk_string_prepend (Etk_String *string, const char *text)
 Prepends a text to a string.
Etk_String * etk_string_prepend_sized (Etk_String *string, const char *text, int length)
 Prepends a text with a specific length to a string.
Etk_String * etk_string_prepend_char (Etk_String *string, char c)
 Prepends a character to a string.
Etk_String * etk_string_prepend_printf (Etk_String *string, const char *format,...)
 Prepends a text to the string, from the given format and arguments.
Etk_String * etk_string_prepend_vprintf (Etk_String *string, const char *format, va_list args)
 Prepends a text to the string, from the given format and arguments.
Etk_String * etk_string_append (Etk_String *string, const char *text)
 Appends a text to a string.
Etk_String * etk_string_append_sized (Etk_String *string, const char *text, int length)
 Appends a text with a specific length to a string.
Etk_String * etk_string_append_char (Etk_String *string, char c)
 Appends a character to a string.
Etk_String * etk_string_append_printf (Etk_String *string, const char *format,...)
 Appends a text to the string, from the given format and arguments.
Etk_String * etk_string_append_vprintf (Etk_String *string, const char *format, va_list args)
 Appends a text to the string, from the given format and arguments.
Etk_String * etk_string_insert (Etk_String *string, int pos, const char *text)
 Inserts a text into a string, at a given position.
Etk_String * etk_string_insert_sized (Etk_String *string, int pos, const char *text, int length)
 Inserts a text with a specific length into a string, at a given position.
Etk_String * etk_string_insert_char (Etk_String *string, int pos, char c)
 Inserts a character into a string, at a given position.
Etk_String * etk_string_insert_printf (Etk_String *string, int pos, const char *format,...)
 Inserts a text into a string, from the given format and arguments, at a given position.
Etk_String * etk_string_insert_vprintf (Etk_String *string, int pos, const char *format, va_list args)
 Inserts a text into a string, from the given format and arguments, at a given position.


Define Documentation

#define ETK_STRING_TYPE   (etk_string_type_get())

Gets the type of a string

Referenced by etk_string_new(), etk_string_new_printf(), etk_string_new_sized(), and etk_string_new_vprintf().

#define ETK_STRING ( obj   )     (ETK_OBJECT_CAST((obj), ETK_STRING_TYPE, Etk_String))

Casts the object to an Etk_String

Referenced by etk_string_new(), etk_string_new_printf(), etk_string_new_sized(), and etk_string_new_vprintf().

#define ETK_IS_STRING ( obj   )     (ETK_OBJECT_CHECK_TYPE((obj), ETK_STRING_TYPE))

Checks if the object is an Etk_String


Function Documentation

Etk_String * etk_string_new ( const char *  value  ) 

Creates a new string.

Parameters:
value the default value of the string. It can be NULL
Returns:
Returns the new string

References etk_object_new(), ETK_STRING, etk_string_set(), and ETK_STRING_TYPE.

Referenced by etk_string_copy(), etk_string_insert_char(), etk_textblock2_insert_markup(), etk_textblock_range_text_get(), and etk_textblock_text_get().

Etk_String * etk_string_new_sized ( const char *  value,
int  size 
)

Creates a new string, with a specific size.

Parameters:
value the default value of the string. It can be NULL
size If size is lower than the length of value, the value will be truncated. Otherwise, if size is greater than the length of value, extra memory will be allocated. It may be useful if you plan to often insert text and want to avoid too many reallocations.
Returns:
Returns the new string

References etk_object_new(), ETK_STRING, etk_string_set_sized(), and ETK_STRING_TYPE.

Referenced by etk_string_copy(), etk_string_insert_sized(), and etk_string_set_sized().

Etk_String * etk_string_new_printf ( const char *  format,
  ... 
)

Creates a new string, and sets its default value from the given format and arguments.

Parameters:
format the format to set to the string. It uses the same arguments as printf()
... the arguments corresponding to the format
Returns:
Returns the new string

References etk_object_new(), ETK_STRING, etk_string_set_vprintf(), and ETK_STRING_TYPE.

Etk_String * etk_string_new_vprintf ( const char *  format,
va_list  args 
)

Creates a new string, and sets its default value from the given format and arguments.

Parameters:
format the format to set to the string. It uses the same arguments as printf()
args the arguments corresponding to the format
Returns:
Returns the new string

References etk_object_new(), ETK_STRING, etk_string_set_vprintf(), and ETK_STRING_TYPE.

Etk_String * etk_string_copy ( const Etk_String *  string  ) 

Creates a new string and copies the text from string.

Parameters:
string the string to copy
Returns:
Returns the new copied string

References allocated_length, etk_string_new(), etk_string_new_sized(), and string.

const char * etk_string_get ( Etk_String *  string  ) 

Gets the string as an array of chars.

Parameters:
string a string
Returns the string as an array of chars (i.e a pointer on the first character)

References string.

Referenced by etk_editable_text_get(), etk_editable_text_range_get(), etk_textblock2_insert_markup(), etk_textblock2_printf(), etk_textblock_iter_backward_char(), etk_textblock_iter_forward_char(), and etk_textblock_printf().

int etk_string_length_get ( Etk_String *  string  ) 

Gets the length of the string.

Parameters:
string a string
Returns:
Returns the length of the string

Referenced by etk_textblock2_insert_markup(), etk_textblock2_iter_forward_end(), etk_textblock2_line_delete(), etk_textblock2_node_delete(), etk_textblock2_paragraph_delete(), etk_textblock_delete_range(), etk_textblock_iter_backward_char(), and etk_textblock_iter_forward_end().

Etk_String * etk_string_truncate ( Etk_String *  string,
int  length 
)

Truncates the string.

Parameters:
string a string
length the new length of the string. If length is greater than the current length of the string, the function does nothing
Returns:
Returns the truncated string

References ETK_OBJECT, etk_object_notify(), and string.

Referenced by etk_string_delete(), and etk_string_insert_char().

Etk_String * etk_string_delete ( Etk_String *  string,
int  pos,
int  size 
)

Removes from the string a segment of size chars from the position pos.

Parameters:
string a string
pos the position where to start the deletion (starting from 0)
size the number of chars to remove
Returns:
Returns the string

References etk_string_truncate(), length, and string.

Referenced by etk_textblock_delete_range().

Etk_String * etk_string_clear ( Etk_String *  string  ) 

Clears the string: all the allocated memory will be freed, and the length of the string will be set to 0.

Parameters:
string the string to clear
Returns:
Returns the cleared string

References string.

Referenced by etk_editable_text_set(), etk_string_set_sized(), and etk_textblock_delete_range().

Etk_String * etk_string_set ( Etk_String *  string,
const char *  value 
)

Sets the value of a string.

Parameters:
string a string. If string is NULL, a new string is created
value the value to assign to the string
Returns:
Returns the string

References etk_string_set_sized().

Referenced by etk_string_new(), and etk_string_set_vprintf().

Etk_String * etk_string_set_sized ( Etk_String *  string,
const char *  value,
int  size 
)

Sets the value of a string, with a specific size.

Parameters:
string a string. If string is NULL, a new string is created
value the value to assign to the string
size If size is lower than the length of value, the value will be truncated. Otherwise, if size is greater than the length of value, extra memory will be allocated. It may be useful if you plan to often insert text and want to avoid too many reallocations.
Returns:
Returns the string

References allocated_length, ETK_OBJECT, etk_object_notify(), etk_string_clear(), etk_string_new_sized(), length, and string.

Referenced by etk_string_new_sized(), etk_string_set(), and etk_textblock2_insert_markup().

Etk_String * etk_string_set_printf ( Etk_String *  string,
const char *  format,
  ... 
)

Sets the value of the string from the given format and arguments.

Parameters:
string a string. If string is NULL, a new string is created
format the format to set to the string. It uses the same arguments as printf()
... the arguments corresponding to the format
Returns:
Returns the string

References etk_string_set_vprintf().

Etk_String * etk_string_set_vprintf ( Etk_String *  string,
const char *  format,
va_list  args 
)

Sets the value of the string from the format and the arguments.

Parameters:
string a string. If string is NULL, a new string is created
format the format to set to the string. It uses the same arguments than printf()
args the arguments corresponding to the format
Returns:
Returns the string

References etk_string_set().

Referenced by etk_string_new_printf(), etk_string_new_vprintf(), and etk_string_set_printf().

Etk_String * etk_string_prepend ( Etk_String *  string,
const char *  text 
)

Prepends a text to a string.

Parameters:
string a string. If string is NULL, a new string is created
text the text to prepend to the string
Returns:
Returns the string

References etk_string_insert().

Etk_String * etk_string_prepend_sized ( Etk_String *  string,
const char *  text,
int  length 
)

Prepends a text with a specific length to a string.

Parameters:
string a string. If string is NULL, a new string is created
text the text to prepend to the string
length the length of the text to prepend
Returns:
Returns the string

References etk_string_insert_sized().

Etk_String * etk_string_prepend_char ( Etk_String *  string,
char  c 
)

Prepends a character to a string.

Parameters:
string a string. If string is NULL, a new string is created
c the character to prepend to the string
Returns:
Returns the string

References etk_string_insert_char().

Etk_String * etk_string_prepend_printf ( Etk_String *  string,
const char *  format,
  ... 
)

Prepends a text to the string, from the given format and arguments.

Parameters:
string a string. If string is NULL, a new string is created
format the format of the text to prepend to the string. It uses the same arguments than printf()
... the arguments corresponding to the format
Returns:
Returns the string

References etk_string_prepend_vprintf().

Etk_String * etk_string_prepend_vprintf ( Etk_String *  string,
const char *  format,
va_list  args 
)

Prepends a text to the string, from the given format and arguments.

Parameters:
string a string. If string is NULL, a new string is created
format the format of the text to prepend to the string. It uses the same arguments than printf()
args the arguments corresponding to the format
Returns:
Returns the string

References etk_string_insert_vprintf().

Referenced by etk_string_prepend_printf().

Etk_String * etk_string_append ( Etk_String *  string,
const char *  text 
)

Appends a text to a string.

Parameters:
string a string. If string is NULL, a new string is created
text the text to append to the string
Returns:
Returns the string

References etk_string_insert(), and length.

Etk_String * etk_string_append_sized ( Etk_String *  string,
const char *  text,
int  length 
)

Appends a text with a specific length to a string.

Parameters:
string a string. If string is NULL, a new string is created
text the text to append to the string
length the length of the text to append
Returns:
Returns the string

References etk_string_insert_sized(), and length.

Etk_String * etk_string_append_char ( Etk_String *  string,
char  c 
)

Appends a character to a string.

Parameters:
string a string. If string is NULL, a new string is created
c the character to append to the string
Returns:
Returns the string

References etk_string_insert_char(), and length.

Etk_String * etk_string_append_printf ( Etk_String *  string,
const char *  format,
  ... 
)

Appends a text to the string, from the given format and arguments.

Parameters:
string a string. If string is NULL, a new string is created
format the format of the text to append to the string. It uses the same arguments than printf()
... the arguments corresponding to the format
Returns:
Returns the string

References etk_string_append_vprintf().

Etk_String * etk_string_append_vprintf ( Etk_String *  string,
const char *  format,
va_list  args 
)

Appends a text to the string, from the given format and arguments.

Parameters:
string a string. If string is NULL, a new string is created
format the format of the text to append to the string. It uses the same arguments than printf()
args the arguments corresponding to the format
Returns:
Returns the string

References etk_string_insert_vprintf(), and length.

Referenced by etk_string_append_printf().

Etk_String * etk_string_insert ( Etk_String *  string,
int  pos,
const char *  text 
)

Inserts a text into a string, at a given position.

Parameters:
string a string. If string is NULL, a new string is created
pos the position where to insert the text (starting from 0)
text the text to insert into the string
Returns:
Returns the string

References etk_string_insert_sized().

Referenced by etk_string_append(), etk_string_insert_vprintf(), and etk_string_prepend().

Etk_String * etk_string_insert_sized ( Etk_String *  string,
int  pos,
const char *  text,
int  length 
)

Inserts a text with a specific length into a string, at a given position.

Parameters:
string a string. If string is NULL, a new string is created
pos the position where to insert the text (starting from 0)
text the text to insert into the string
length the maximum length of the text to insert
Returns:
Returns the string

References allocated_length, ETK_CLAMP, ETK_OBJECT, etk_object_notify(), etk_string_new_sized(), length, and string.

Referenced by etk_string_append_sized(), etk_string_insert(), etk_string_prepend_sized(), etk_textblock2_insert(), and etk_textblock_insert().

Etk_String * etk_string_insert_char ( Etk_String *  string,
int  pos,
char  c 
)

Inserts a character into a string, at a given position.

Parameters:
string a string. If string is NULL, a new string is created
pos the position where to insert the char
c the character to insert into the string
Returns:
Returns the string

References allocated_length, ETK_CLAMP, ETK_OBJECT, etk_object_notify(), etk_string_new(), etk_string_truncate(), length, and string.

Referenced by etk_string_append_char(), and etk_string_prepend_char().

Etk_String * etk_string_insert_printf ( Etk_String *  string,
int  pos,
const char *  format,
  ... 
)

Inserts a text into a string, from the given format and arguments, at a given position.

Parameters:
string a string. If string is NULL, a new string is created
pos the position where to insert the text
format the format to insert into the string. It uses the same arguments than printf()
... the arguments corresponding to the format
Returns:
Returns the string

References etk_string_insert_vprintf().

Etk_String * etk_string_insert_vprintf ( Etk_String *  string,
int  pos,
const char *  format,
va_list  args 
)

Inserts a text into a string, from the given format and arguments, at a given position.

Parameters:
string a string. If string is NULL, a new string is created
pos the position where to insert the text
format the format to insert into the string. It uses the same arguments than printf()
args the arguments corresponding to the format
Returns:
Returns the string

References etk_string_insert().

Referenced by etk_string_append_vprintf(), etk_string_insert_printf(), and etk_string_prepend_vprintf().