python-on-a-chip online compiler

Dependencies:   mbed TSI

Embed: (wiki syntax)

« Back to documentation index

strobj.h File Reference

strobj.h File Reference

String Object Type. More...

Go to the source code of this file.

Data Structures

struct  PmString_s
 String obj. More...

Typedefs

typedef struct PmString_s PmString_t
 String obj.

Functions

PmReturn_t string_create (PmMemSpace_t memspace, uint8_t const **paddr, int16_t len, int16_t n, pPmObj_t *r_pstring)
 Creates a new String obj.
PmReturn_t string_newFromChar (uint8_t const c, pPmObj_t *r_pstring)
 Creates a new String object from a single character.
int8_t string_compare (pPmString_t pstr1, pPmString_t pstr2)
 Compares two String objects for equality.
PmReturn_t string_print (pPmObj_t pstr, uint8_t is_escaped)
 Sends out a string object bytewise.
PmReturn_t string_cacheInit (void)
 Clears the string cache if one exists.
PmReturn_t string_getCache (pPmString_t **r_ppstrcache)
 Returns a pointer to the base of the string cache.
PmReturn_t string_concat (pPmString_t pstr1, pPmString_t pstr2, pPmObj_t *r_pstring)
 Returns a new string object that is the concatenation of the two given strings.
PmReturn_t string_format (pPmString_t pstr, pPmObj_t parg, pPmObj_t *r_pstring)
 Returns a new string object that is created from the given format string and the argument(s).
PmReturn_t string_printFormattedBytes (uint8_t *pb, uint8_t is_escaped, uint16_t n)
 Prints n bytes, formatting them if is_escaped is true.

Detailed Description

String Object Type.

String object type header.

Definition in file strobj.h.


Typedef Documentation

typedef struct PmString_s PmString_t

String obj.

Null terminated array of chars.


Function Documentation

PmReturn_t string_cacheInit ( void   )

Clears the string cache if one exists.

Called by heap_init()

Returns:
Return status

Definition at line 247 of file strobj.c.

int8_t string_compare ( pPmString_t  pstr1,
pPmString_t  pstr2 
)

Compares two String objects for equality.

Parameters:
pstr1Ptr to first string
pstr2Ptr to second string
Returns:
C_SAME if the strings are equivalent, C_DIFFER otherwise

Definition at line 144 of file strobj.c.

PmReturn_t string_concat ( pPmString_t  pstr1,
pPmString_t  pstr2,
pPmObj_t r_pstring 
)

Returns a new string object that is the concatenation of the two given strings.

Parameters:
pstr1First source string
pstr2Second source string
r_pstringReturn arg; ptr to new string object
Returns:
Return status

Definition at line 268 of file strobj.c.

PmReturn_t string_create ( PmMemSpace_t  memspace,
uint8_t const **  paddr,
int16_t  len,
int16_t  n,
pPmObj_t r_pstring 
)

Creates a new String obj.

If len is less than zero, load from a String image. If len is zero, copy from a C string (which has a null terminator) If len is positive, copy as many chars as given in the len argument A string image has the following structure: -type: int8 - OBJ_TYPE_STRING -length: uint16 - number of bytes in the string -val: uint8[] - array of chars with null term

Returns by reference a ptr to String obj.

Obtain space for String from the heap. Copy string from memspace. Leave contents of paddr pointing one byte past end of str.

THE PROGRAMMER SHOULD NOT CALL THIS FUNCTION DIRECTLY. Instead, use one of the two macros string_loadFromImg() or string_new().

Parameters:
memspacememory space where *paddr points
paddrptr to ptr to null term character array or image.
lenlength of the C character array (use -1 for string images, 0 for C strings)
nNumber of times to replicate the given string argument
r_pstringReturn by reference; ptr to String obj
Returns:
Return status

Definition at line 41 of file strobj.c.

PmReturn_t string_format ( pPmString_t  pstr,
pPmObj_t  parg,
pPmObj_t r_pstring 
)

Returns a new string object that is created from the given format string and the argument(s).

Parameters:
pstrFormat string object
pargSingle argument or tuple of arguments
r_pstringReturn arg; ptr to new string object
Returns:
Return status

Definition at line 329 of file strobj.c.

PmReturn_t string_getCache ( pPmString_t **  r_ppstrcache )

Returns a pointer to the base of the string cache.

Definition at line 256 of file strobj.c.

PmReturn_t string_newFromChar ( uint8_t const   c,
pPmObj_t r_pstring 
)

Creates a new String object from a single character.

Parameters:
cThe character to become the string
r_pstringReturn by reference; ptr to String obj
Returns:
Return status

Definition at line 121 of file strobj.c.

PmReturn_t string_print ( pPmObj_t  pstr,
uint8_t  is_escaped 
)

Sends out a string object bytewise.

Escaping and framing is configurable via is_escaped.

Parameters:
pstrPtr to string object
is_escapedIf 0, print out string as is. Otherwise escape unprintable characters and surround string with single quotes.
Returns:
Return status

Definition at line 224 of file strobj.c.

PmReturn_t string_printFormattedBytes ( uint8_t *  pb,
uint8_t  is_escaped,
uint16_t  n 
)

Prints n bytes, formatting them if is_escaped is true.

Parameters:
pbPointer to C bytes
is_escapedBoolean true if string is to be escaped
nNumber of bytes to print
Returns:
Return status

Definition at line 161 of file strobj.c.