Coconut Framework  beta
Classes | Typedefs | Functions
CNString.h File Reference

Define CNString class. More...

#include "CNObject.h"
#include "CNList.h"
#include <stdint.h>
#include <string.h>
#include <stdio.h>

Go to the source code of this file.

Classes

struct  CNStringMethods
 Methods for CNString. More...
 
struct  CNString
 Fixed size string class. More...
 

Typedefs

typedef void(* CNVisitStringElementFuncRef )(size_t elmlen, const unsigned char *elmstr, void *info)
 

Functions

struct CNStringCNAllocateStringWithCString (size_t len, const unsigned char *str, struct CNResource *resource)
 Allocate CNString object. More...
 
struct CNStringCNAllocateEmptyString (struct CNResource *resource)
 Allocate empty string. More...
 
static void CNRetainString (struct CNString *dst)
 Retain CNString object. More...
 
static void CNReleaseString (struct CNString *dst)
 Release CNString object. More...
 
static size_t CNLengthOfString (const struct CNString *src)
 Get length of the string. More...
 
static uint64_t CNHashValueOfString (const struct CNString *src)
 Get hash value of source string. More...
 
static struct CNObjectCNObjectOfString (struct CNString *src)
 Get super class of CNString. More...
 
struct CNStringCNCopyString (struct CNString *src)
 Allocate the copy of string. More...
 
void CNAppendStringToString (struct CNString *dst, struct CNString *src)
 Append context of source string into destination. More...
 
void CNAppendCStringToString (struct CNString *dst, size_t len, const unsigned char *src)
 Append C-String to String. More...
 
static struct CNStringCNAddStrings (struct CNString *src0, struct CNString *src1)
 Allocate added string. More...
 
void CNMoveStringToString (struct CNString *dst, struct CNString *src)
 Move context of source string into destination. More...
 
struct CNStringCNPrintToString (struct CNResource *resource, const char *format,...)
 Allocate string with printf format. More...
 
void CNPutStringToCString (unsigned char *dst, const struct CNString *src)
 Put context of string into buffer. More...
 
void CNPrintString (FILE *fp, const struct CNString *src)
 Put context of string into file stream. More...
 
CNBoolean CNIsSameStrings (const struct CNString *src0, const struct CNString *src1)
 Compare CNStrings. More...
 
CNBoolean CNIsSameStringAndCString (const struct CNString *src0, size_t len1, const unsigned char *src1)
 Compare CNString and C-String. More...
 
void CNVisitStringElements (const struct CNString *src, CNVisitStringElementFuncRef func, void *info)
 Visit all elements in the string. More...
 
struct CNMemoryProfile CNProfileOfString (const struct CNString *src)
 Get memory profile of string. More...
 

Detailed Description

Define CNString class.

Copyright
Copyright (C) 2012 Steel Wheels Project

Typedef Documentation

typedef void(* CNVisitStringElementFuncRef)(size_t elmlen, const unsigned char *elmstr, void *info)

Function to visit all elements in CNString

Function Documentation

struct CNString* CNAllocateStringWithCString ( size_t  len,
const unsigned char *  str,
struct CNResource *  resource 
)

Allocate CNString object.

Return values
strAllocated string
NULLAllocation failed
Parameters
lenLength of source string
strSource string
resourceResource to allocate the string object.
Note
If you passed 0 length string, the context will be NULL.
struct CNString* CNAllocateEmptyString ( struct CNResource *  resource)

Allocate empty string.

Return values
strAllocated string
NULLAllocation failed
Parameters
resourceResource to allocate the string object
static void CNRetainString ( struct CNString dst)
inlinestatic

Retain CNString object.

Parameters
dstDestination string object

References CNRetainObject(), and CNString::superClass.

static void CNReleaseString ( struct CNString dst)
inlinestatic

Release CNString object.

Parameters
dstDestination string object

References CNReleaseObject(), and CNString::superClass.

static size_t CNLengthOfString ( const struct CNString src)
inlinestatic

Get length of the string.

Returns
Length of the string
Parameters
srcSource string

References CNString::length.

static uint64_t CNHashValueOfString ( const struct CNString src)
inlinestatic

Get hash value of source string.

Returns
Hash value
Parameters
srcSource string

References CNString::hashValue.

static struct CNObject* CNObjectOfString ( struct CNString src)
static

Get super class of CNString.

Returns
Super class
Parameters
srcSource string

References CNString::superClass.

struct CNString* CNCopyString ( struct CNString src)

Allocate the copy of string.

Returns
Copied string
Parameters
srcSource string

Referenced by CNAddStrings().

void CNAppendStringToString ( struct CNString dst,
struct CNString src 
)

Append context of source string into destination.

Parameters
dstDestination string
srcSource string

Referenced by CNAddStrings().

void CNAppendCStringToString ( struct CNString dst,
size_t  len,
const unsigned char *  src 
)

Append C-String to String.

Parameters
dstDestination string
lenLength of source string
srcSource string
static struct CNString* CNAddStrings ( struct CNString src0,
struct CNString src1 
)
static

Allocate added string.

Returns
Allocated string
Parameters
src0Source string 0
src1Source string 1

References CNAppendStringToString(), and CNCopyString().

void CNMoveStringToString ( struct CNString dst,
struct CNString src 
)

Move context of source string into destination.

Parameters
dstDestination string
srcSource string
Note
Source string will be empty after call this function
struct CNString* CNPrintToString ( struct CNResource *  resource,
const char *  format,
  ... 
)

Allocate string with printf format.

Returns
Allocated string
Parameters
resourceResource to allocate the string
formatPrint format
void CNPutStringToCString ( unsigned char *  dst,
const struct CNString src 
)

Put context of string into buffer.

Parameters
dstDestination buffer
srcSource string
Warning
The size of buffer must be bigger than the length of source string which is given by CNLengthOfString() + 1.
void CNPrintString ( FILE *  fp,
const struct CNString src 
)

Put context of string into file stream.

Parameters
fpDestination file stream
srcSource string
CNBoolean CNIsSameStrings ( const struct CNString src0,
const struct CNString src1 
)

Compare CNStrings.

Return values
TRUEThey have same context
FALSEThey have different context
Parameters
src0Source string 0
src1Source string 1
CNBoolean CNIsSameStringAndCString ( const struct CNString src0,
size_t  len1,
const unsigned char *  src1 
)

Compare CNString and C-String.

Return values
TRUEThey have same context
FALSEThey have different context
Parameters
src0Source string 0
len1Length of source string 1
src1Source string 1
void CNVisitStringElements ( const struct CNString src,
CNVisitStringElementFuncRef  func,
void *  info 
)

Visit all elements in the string.

Parameters
srcSource string
funcVisit function for each elements
infoUser defined parameter, this is passed to the visit function
struct CNMemoryProfile CNProfileOfString ( const struct CNString src)

Get memory profile of string.

Returns
Profile of source string
Parameters
srcSource string