Zen API

- Home
- Help Topics
- Types by Category
- All Types
- Files

All Classes Files Functions Variables Typedefs Macros Groups Pages
Public Member Functions
kString Class Reference
kApi/Data

## Description

Represents a character string.

kString represents a variable-length, null-terminated sequence of kChar elements.

Inheritance diagram for kString:

## Public Member Functions
kAlloc | kObject_Alloc (kObject object)
| Gets the memory allocator associated with this object. More...
kStatus | kObject_Clone (kObject *object, kObject source, kAlloc allocator)
| Constructs a new object by copying an existing object, including any aggregated child elements. More...
kStatus | kObject_Destroy (kObject object)
| Destroys the object. More...
kStatus | kObject_Dispose (kObject object)
| Destroys the object and any aggregated child elements. More...
kBool | kObject_Equals (kObject object, kObject other)
| Determines whether the object is equal to another object. More...
kSize | kObject_HashCode (kObject object)
| Gets a hash code representing the state of this object. More...
kBool | kObject_Is (kObject object, kType type)
| Determines whether this object is an instance of the specified type. More...
kBool | kObject_IsShared (kObject object)
| Reports whether the object is currently shared (reference count greater than one). More...
kStatus | kObject_SetPool (kObject object, kObjectPool pool)
| Sets the object pool associated with this object. More...
kStatus | kObject_Share (kObject object)
| Increments the reference count associated with this object. More...
kSize | kObject_Size (kObject object)
| Estimates the memory consumed by this object, including any aggregated child elements. More...
kType | kObject_Type (kObject object)
| Returns the type of the object. More...
kStatus | kString_Add (kString str, const kChar *content)
| Appends content to the string. More...
kStatus | kString_Addf (kString str, const kChar *format,...)
| Appends content to the string using a printf-like format string and arguments. More...
kStatus | kString_AddSubstring (kString str, const kChar *content, kSize start, kSize count)
| Appends a portion of another string to this string. More...
kStatus | kString_Addvf (kString str, const kChar *format, kVarArgList argList)
| Variable-argument version of kString_Addf. More...
kStatus | kString_Assign (kString str, kString source)
| Copies the source string content. More...
kSize | kString_Capacity (kString str)
| Returns the number of character units that can be stored without reallocation. More...
kChar * | kString_Chars (kString str)
| Returns a pointer to the internal character buffer. More...
kStatus | kString_Clear (kString str)
| Sets the length of the string to zero. More...
k32s | kString_Compare (kString str, const kChar *content)
| Compares this string to another string. More...
kStatus | kString_Construct (kString *str, const kChar *content, kAlloc allocator)
| Constructs a kString object. More...
kBool | kString_Equals (kString str, const kChar *content)
| Compares this string to another character sequence to determine equality. More...
kSize | kString_Length (kString str)
| Returns the number of character units in the string buffer (excluding null-terminator). More...
kStatus | kString_Reserve (kString str, kSize minimumCapacity)
| Ensures that capacity is reserved for at least the specified number of character units (excluding null terminator). More...
kStatus | kString_Set (kString str, const kChar *content)
| Sets the content of the string. More...
kStatus | kString_Setf (kString str, const kChar *format,...)
| Sets the content of the string using a printf-like format string and arguments. More...
kStatus | kString_SetLength (kString str, kSize length)
| Explicitly sets the length of the string. More...
kStatus | kString_Setvf (kString str, const kChar *format, kVarArgList argList)
| Variable-argument version of kString_Setf. More...
kStatus | kString_Split (kString str, const kChar *delimiters, kArrayList *tokens, kAlloc allocator)
| Splits this string into substrings using the supplied delimiters. More...
kStatus | kString_Trim (kString str)
| Removes leading and trailing whitespace. More...

## Member Function Documentation

kAlloc kObject_Alloc | ( | kObject | object | ) |
| inherited

Gets the memory allocator associated with this object.

Most objects are constructed with an allocator, which is used to allocate the memory required by the object. Objects retain a reference to this allocator to enable further allocations and to free memory when the object is destroyed.

Parameters

  object | Object.

Returns
  Memory allocator.

See also
  kAlloc, kObject_Alloc_

kStatus kObject_Clone | ( | kObject * | object,
|  | kObject | source,
|  | kAlloc | allocator
| ) |  |
| inherited

Constructs a new object by copying an existing object, including any aggregated child elements.

If the source object is an object collection (e.g. kArrayList<kString>), any aggregated child objects are also cloned. In this case, the kObject_Dispose method can be used to free the cloned collection and its associated elements.

This method will fail if the source object (or an aggregated child element) does not support cloning.

Parameters

  object | Receives the constructed object.
  source | Source object.
  allocator | Memory allocator (or kNULL for default).

Returns
  Operation status.

See also
  kObject_Dispose

kStatus kObject_Destroy | ( | kObject | object | ) |
| inherited

Destroys the object.

The kObject_Destroy method destroys the object itself and any resources that are owned by the object. See Object Destruction for more information.

When an object is destroyed (or disposed), its reference count is decremented. The object is only truly destroyed when the reference count reaches zero. See Reference Counting for more information.

Parameters

  object | Object (or kNULL).

Returns
  Operation status.

See also
  Object Destruction, Reference Counting

kStatus kObject_Dispose | ( | kObject | object | ) |
| inherited

Destroys the object and any aggregated child elements.

The kObject_Dispose method destroys the object itself, any resources that are owned by the object, and if the object represents a collection of objects, any child objects in the collection. See Object Destruction for more information.

When an object is destroyed (or disposed), its reference count is decremented. The object is only truly destroyed when the reference count reaches zero. See Reference Counting for more information.

Parameters

  object | Object (or kNULL).

Returns
  Operation status.

See also
  Object Destruction, Reference Counting

kBool kObject_Equals | ( | kObject | object,
|  | kObject | other
| ) |  |
| inherited

Determines whether the object is equal to another object.

By default, objects are compared by reference; objects are considered equal if the given handles refer to the same object instance. However, some classes override the Equals method to provide a more meaningful comparison (e.g. kString).

Parameters

  object | Object.
  other | Object for comparison.

Returns
  kTRUE if the objects are equal.

kSize kObject_HashCode | ( | kObject | object | ) |
| inherited

Gets a hash code representing the state of this object.

By default, objects return a hash code based on the object handle value. However, some classes override the HashCode method to provide a more useful hash (e.g. kString).

Parameters

  object | Object.

Returns
  Hash code.

kBool kObject_Is | ( | kObject | object,
|  | kType | type
| ) |  |
| inherited

Determines whether this object is an instance of the specified type.

This function compares the type of this object with the given type. An object is considered to be an instance of a given type if a) the type represents a class and this object inherits from (or instantiates) that class, or b) the type represents an interface and this object implements the interface.

Parameters

  object | Object.
  type | Type.

Returns
  kTRUE if the object is of the specified type; otherwise kFALSE.

See also
  kObject_Is_, kType_Is

kBool kObject_IsShared | ( | kObject | object | ) |
| inherited

Reports whether the object is currently shared (reference count greater than one).

Objects are initialized with a reference count of one. The kObject_Share method can be used to increment the reference count. The kObject_Destroy and kObject_Dispose methods decrease the reference count, and when the reference count reaches zero, the object is actually destroyed/disposed.

This method can be used to determine if the reference count of an object is currently greater than one.

This method is thread-safe.

Parameters

  object | Object.

Returns
  kTRUE if the object is shared; kFALSE otherwise.

See also
  Reference Counting, kObject_Share

kStatus kObject_SetPool | ( | kObject | object,
|  | kObjectPool | pool
| ) |  |
| inherited

Sets the object pool associated with this object.

Object pools can be used to implement custom lifecycle management. If an object has an assigned pool, then the kObjectPool_Reclaim method will be called just prior to destruction, to provide an opportunity for the object to be reclaimed.

Parameters

  object | Object.
  pool | Pool object (or kNULL to clear the pool assignment).

Returns
  Operation status.

kStatus kObject_Share | ( | kObject | object | ) |
| inherited

Increments the reference count associated with this object.

This method is thread-safe.

Parameters

  object | Object.

Returns
  Operation status.

See also
  reference-counting

kSize kObject_Size | ( | kObject | object | ) |
| inherited

Estimates the memory consumed by this object, including any aggregated child elements.

This method can be optionally overridden by kObject-derived classes to report the amount of memory consumed by an object. The default implementation reports only the size of the class instance (additional allocations performed by the class are excluded).

Parameters

  object | Object.

Returns
  Object size, in bytes.

kType kObject_Type | ( | kObject | object | ) |
| inherited

Returns the type of the object.

Each object is an instance of a specific class type. The type handle returned by this function can be used to learn about the class.

Parameters

  object | Object.

Returns
  Type.

See also
  kType, kObject_Type_

kStatus kString_Add | ( | kString | str,
|  | const kChar * | content
| ) |  |

Appends content to the string.

Parameters

  str | String object.
  content | String content to append.

Returns
  Operation status.

kStatus kString_Addf | ( | kString | str,
|  | const kChar * | format,
|  |  | ...
| ) |  |

Appends content to the string using a printf-like format string and arguments.

This function relies on formatting support from underlying system libraries; results can vary.

Parameters

  str | String object.
  format | Print format string.

Returns
  Operation status.

kStatus kString_AddSubstring | ( | kString | str,
|  | const kChar * | content,
|  | kSize | start,
|  | kSize | count
| ) |  |

Appends a portion of another string to this string.

Parameters

  str | String object.
  content | String content to append.
  start | Starting offset with content argument.
  count | Count of characters to append.

Returns
  Operation status.

kStatus kString_Addvf | ( | kString | str,
|  | const kChar * | format,
|  | kVarArgList | argList
| ) |  |

Variable-argument version of kString_Addf.

Parameters

  str | String object.
  format | Print format string.
  argList | Variable argument list.

Returns
  Operation status.

kStatus kString_Assign | ( | kString | str,
|  | kString | source
| ) |  |

Copies the source string content.

Parameters

  str | String object.
  source | Source string to be copied.

Returns
  Operation status.

kSize kString_Capacity | ( | kString | str | ) |

Returns the number of character units that can be stored without reallocation.

Parameters

  str | String object.

Returns
  String capacity.

kChar * kString_Chars | ( | kString | str | ) |

Returns a pointer to the internal character buffer.

Parameters

  str | String object.

Returns
  Pointer to null-terminated character buffer.

kStatus kString_Clear | ( | kString | str | ) |

Sets the length of the string to zero.

Parameters

  str | String object.

Returns
  Operation status.

k32s kString_Compare | ( | kString | str,
|  | const kChar * | content
| ) |  |

Compares this string to another string.

The result is negative if the string object is lexically less than the input, positive if the string object is lexically greater than the input, and zero if they are equal.

This function performs comparison of UTF-8 encoded characters by Unicode code point.

Parameters

  str | String object.
  content | String content to be compared.

Returns
  Comparison result.

kStatus kString_Construct | ( | kString * | str,
|  | const kChar * | content,
|  | kAlloc | allocator
| ) |  |

Constructs a kString object.

Parameters

  str | Receives constructed string object.
  content | Initial string content (or kNULL).
  allocator | Memory allocator.

Returns
  Operation status.

kBool kString_Equals | ( | kString | str,
|  | const kChar * | content
| ) |  |

Compares this string to another character sequence to determine equality.

Parameters

  str | String object.
  content | String content to be compared.

Returns
  kTRUE if the character sequences are equal; otherwise, kFALSE.

kSize kString_Length | ( | kString | str | ) |

Returns the number of character units in the string buffer (excluding null-terminator).

kString assumes UTF8-encoded data; the string length refers to the number of encoded character units (bytes), rather than the number of characters.

Parameters

  str | String object.

Returns
  Count of character units (excluding null-terminator).

kStatus kString_Reserve | ( | kString | str,
|  | kSize | minimumCapacity
| ) |  |

Ensures that capacity is reserved for at least the specified number of character units (excluding null terminator).

Existing string content is preserved.

Parameters

  str | String object.
  minimumCapacity | Minimum string capacity, in character units.

Returns
  Operation status.

kStatus kString_Set | ( | kString | str,
|  | const kChar * | content
| ) |  |

Sets the content of the string.

Parameters

  str | String object.
  content | String content to copy.

Returns
  Operation status.

kStatus kString_Setf | ( | kString | str,
|  | const kChar * | format,
|  |  | ...
| ) |  |

Sets the content of the string using a printf-like format string and arguments.

This function relies on formatting support from underlying system libraries; results can vary.

Parameters

  str | String object.
  format | Print format string.

Returns
  Operation status.

kStatus kString_SetLength | ( | kString | str,
|  | kSize | length
| ) |  |

Explicitly sets the length of the string.

This function can be used to specify the string length if the string buffer has been directly manipulated. Use with caution; no error-checking is performed to ensure that the string is properly formatted.

Parameters

  str | String object.
  length | New string length, in character units (excluding null-terminator).

Returns
  Operation status.

kStatus kString_Setvf | ( | kString | str,
|  | const kChar * | format,
|  | kVarArgList | argList
| ) |  |

Variable-argument version of kString_Setf.

Parameters

  str | String object.
  format | Print format string.
  argList | Variable argument list.

Returns
  Operation status.

kStatus kString_Split | ( | kString | str,
|  | const kChar * | delimiters,
|  | kArrayList * | tokens,
|  | kAlloc | allocator
| ) |  |

Splits this string into substrings using the supplied delimiters.

This function currently supports delimiters only within the ASCII character range.

Parameters

  str | String object.
  delimiters | Null-terminated string containing delimiter characters.
  tokens | Receives a list substrings.
  allocator | Memory allocator (or kNULL for default).

Returns
  Comparison result.

kStatus kString_Trim | ( | kString | str | ) |

Removes leading and trailing whitespace.

Parameters

  str | String object.

Returns
  Comparison result.

The documentation for this class was generated from the following file:

- Data/kString.h