XSString Reference

File
XSFoundation/include/XS/Classes/XSString.h
Author
Jean-David Gadina - www.xs-labs.com
Copyright
© (c) 2020 - Jean-David Gadina - www.xs-labs.com
Date
Sunday, September 27, 2020
Includes

Overview

XSString class

Tasks

XSStringContainsCString

Checks whether a string contains a C string

XS_EXPORT bool XSStringContainsCString( XSStringRef str, const char *search );

Parameters
  • str
    The string object
  • search
    The C string to search
Return value

True if the string contains the C string, otherwise false

XSStringContainsString

Checks whether a string contains another string

XS_EXPORT bool XSStringContainsString( XSStringRef str, XSStringRef search );

Parameters
  • str
    The string object
  • search
    The string to search
Return value

True if the string contains the search string, otherwise false

XSStringCreateWithBytes

Creates a string with bytes

XS_EXPORT XSStringRef XSStringCreateWithBytes( const uint8_t *bytes, size_t length );

Parameters
  • bytes
    The bytes
  • length
    The number of bytes
Return value

A string object

XSStringCreateWithCString

Creates a string with a C string

XS_EXPORT XSStringRef XSStringCreateWithCString( const char *cstr );

Parameters
  • cstr
    The C string
Return value

A string object

XSStringCreateWithFormat

Creates a string with a format string

XS_EXPORT XSStringRef XSStringCreateWithFormat( const char *fmt, ... ) XS_FORMAT_ATTRIBUTE( printf, 1, 2 );

Parameters
  • fmt
    The format string
  • ...
    Arguments for the format string
Return value

A string object

XSStringCreateWithFormatAndArguments

Creates a string with a format string

XS_EXPORT XSStringRef XSStringCreateWithFormatAndArguments( const char *fmt, va_list ap ) XS_FORMAT_ATTRIBUTE( printf, 1, 0 );

Parameters
  • fmt
    The format string
  • ap
    Arguments for the format string
Return value

A string object

XSStringGetCharacterAtIndex

Gets the character at a specific index

XS_EXPORT char XSStringGetCharacterAtIndex( XSStringRef str, size_t index );

Discussion

Returns 0 is the string is NULL or if the index is out of bounds.

Parameters
  • str
    The string object
  • index
    The index of the character
Return value

The character at the specified index

XSStringGetClassID

Gets the class ID for XSString

XS_EXPORT XSClassID XSStringGetClassID( void );

Return value

The class ID for XSString

XSStringGetCString

Gets the internal C string of a string object

XS_EXPORT const char * XSStringGetCString( XSStringRef str );

Discussion

Any modification to the returned C string results in undefined behavior.

Parameters
  • str
    The string object
Return value

The C string

XSStringGetLength

Gets the length of a string object

XS_EXPORT size_t XSStringGetLength( XSStringRef str );

Parameters
  • str
    The string object
Return value

The string's length

XSStringHasCStringPrefix

Checks whether a string has a prefix

XS_EXPORT bool XSStringHasCStringPrefix( XSStringRef str, const char *prefix );

Parameters
  • str
    The string object
  • prefix
    The prefix C string
Return value

True if the string has the prefix, otherwise false

XSStringHasCStringSuffix

Checks whether a string has a suffix

XS_EXPORT bool XSStringHasCStringSuffix( XSStringRef str, const char *suffix );

Parameters
  • str
    The string object
  • suffix
    The suffix C string
Return value

True if the string has the suffix, otherwise false

XSStringHasPrefix

Checks whether a string has a prefix

XS_EXPORT bool XSStringHasPrefix( XSStringRef str, XSStringRef prefix );

Parameters
  • str
    The string object
  • prefix
    The prefix string
Return value

True if the string has the prefix, otherwise false

XSStringHasSuffix

Checks whether a string has a suffix

XS_EXPORT bool XSStringHasSuffix( XSStringRef str, XSStringRef suffix );

Parameters
  • str
    The string object
  • suffix
    The suffix string
Return value

True if the string has the suffix, otherwise false

XSStringWithBytes

Creates a string with bytes

XS_EXPORT XS_AUTORELEASED XSStringRef XSStringWithBytes( const uint8_t *bytes, size_t length );

Discussion

The returned object is autoreleased.

Parameters
  • bytes
    The bytes
  • length
    The number of bytes
Return value

A string object

XSStringWithCString

Creates a string with a C string

XS_EXPORT XS_AUTORELEASED XSStringRef XSStringWithCString( const char *cstr );

Discussion

The returned object is autoreleased.

Parameters
  • cstr
    The C string
Return value

A string object

XSStringWithFormat

Creates a string with a format string

XS_EXPORT XS_AUTORELEASED XSStringRef XSStringWithFormat( const char *fmt, ... ) XS_FORMAT_ATTRIBUTE( printf, 1, 2 );

Discussion

The returned object is autoreleased.

Parameters
  • fmt
    The format string
  • ...
    Arguments for the format string
Return value

A string object

XSStringWithFormatAndArguments

Creates a string with a format string

XS_EXPORT XS_AUTORELEASED XSStringRef XSStringWithFormatAndArguments( const char *fmt, va_list ap ) XS_FORMAT_ATTRIBUTE( printf, 1, 0 );

Discussion

The returned object is autoreleased.

Parameters
  • fmt
    The format string
  • ap
    Arguments for the format string
Return value

A string object

Types

XSStringRef

Opaque type for XSString (immutable)

typedef const struct XSString * XSStringRef;