enhanced lda with binary heap functions
added more wide character handling functions
This commit is contained in:
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: chr.h 287 2009-09-15 10:01:02Z hyunghwan.chung $
|
||||
* $Id: chr.h 323 2010-04-05 12:50:01Z hyunghwan.chung $
|
||||
*
|
||||
Copyright 2006-2009 Chung, Hyung-Hwan.
|
||||
This file is part of QSE.
|
||||
@ -110,42 +110,42 @@ qse_cint_t qse_ccls_to (
|
||||
qse_ccls_id_t type
|
||||
);
|
||||
|
||||
/**
|
||||
* The qse_mblen() function scans a multibyte sequence to get the number of
|
||||
* bytes needed to form a wide character. It does not scan more than @a mblen
|
||||
* bytes.
|
||||
* @return number of bytes processed on success,
|
||||
* 0 for invalid sequences,
|
||||
* mblen + 1 for incomplete sequences
|
||||
*/
|
||||
qse_size_t qse_mblen (
|
||||
const qse_mchar_t* mb,
|
||||
qse_size_t mblen
|
||||
qse_size_t mblen
|
||||
);
|
||||
|
||||
/****f* Common/qse_mbtowc
|
||||
* NAME
|
||||
* qse_mbtowc - convert a multibyte sequence to a wide character.
|
||||
* RETURN
|
||||
* The qse_mbtowc() function returns 0 if an invalid multibyte sequence is
|
||||
* detected, mblen + 1 if the sequence is incomplete. It returns the number
|
||||
* of bytes processed to form a wide character.
|
||||
* SYNOPSIS
|
||||
/**
|
||||
* The qse_mbtowc() function converts a multibyte sequence to a wide character.
|
||||
* It returns 0 if an invalid multibyte sequence is detected, mblen + 1 if the
|
||||
* sequence is incomplete. It returns the number of bytes processed to form a
|
||||
* wide character.
|
||||
*/
|
||||
qse_size_t qse_mbtowc (
|
||||
const qse_mchar_t* mb,
|
||||
qse_size_t mblen,
|
||||
qse_wchar_t* wc
|
||||
);
|
||||
/******/
|
||||
|
||||
/****f* Common/qse_wctomb
|
||||
* NAME
|
||||
* qse_wctomb - convert a wide character to a multibyte sequence
|
||||
* RETURN
|
||||
* The qse_wctomb() functions returns 0 if the wide character is illegal,
|
||||
* mblen + 1 if mblen is not large enough to hold the multibyte sequence.
|
||||
* On successful conversion, it returns the number of bytes in the sequence.
|
||||
* SYNOPSIS
|
||||
/**
|
||||
* The qse_wctomb() function converts a wide character to a multibyte sequence.
|
||||
* It returns 0 if the wide character is illegal, mblen + 1 if mblen is not
|
||||
* large enough to hold the multibyte sequence. On successful conversion, it
|
||||
* returns the number of bytes in the sequence.
|
||||
*/
|
||||
qse_size_t qse_wctomb (
|
||||
qse_wchar_t wc,
|
||||
qse_mchar_t* mb,
|
||||
qse_size_t mblen
|
||||
);
|
||||
/******/
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: lda.h 311 2009-12-09 11:35:54Z hyunghwan.chung $
|
||||
* $Id: lda.h 323 2010-04-05 12:50:01Z hyunghwan.chung $
|
||||
*
|
||||
Copyright 2006-2009 Chung, Hyung-Hwan.
|
||||
This file is part of QSE.
|
||||
@ -24,13 +24,9 @@
|
||||
#include <qse/types.h>
|
||||
#include <qse/macros.h>
|
||||
|
||||
/****o* Common/linear dynamic array
|
||||
* DESCRIPTION
|
||||
* <Common.h> provides a linear dynamic array. It grows as more items
|
||||
* are added.
|
||||
*
|
||||
* #include <Common.h>
|
||||
******
|
||||
/** @file
|
||||
* This file provides a linear dynamic array. It grows dynamically as items
|
||||
* are added.
|
||||
*/
|
||||
|
||||
enum qse_lda_walk_t
|
||||
@ -62,14 +58,8 @@ typedef enum qse_lda_walk_t qse_lda_walk_t;
|
||||
#define QSE_LDA_KEEPER(lda) ((lda)->keeper)
|
||||
#define QSE_LDA_SIZER(lda) ((lda)->sizer)
|
||||
|
||||
|
||||
|
||||
/****t* Common/qse_lda_copier_t
|
||||
* NAME
|
||||
* qse_lda_copier_t - define a node contruction callback
|
||||
*
|
||||
* DESCRIPTION
|
||||
* The qse_lda_copier_t defines a callback function for node construction.
|
||||
/**
|
||||
* The qse_lda_copier_t type defines a callback function for node construction.
|
||||
* A node is contructed when a user adds data to a list. The user can
|
||||
* define how the data to add can be maintained in the list. A singly
|
||||
* linked list not specified with any copiers stores the data pointer and
|
||||
@ -80,44 +70,30 @@ typedef enum qse_lda_walk_t qse_lda_walk_t;
|
||||
* A copier should return the pointer to the copied data. If it fails to copy
|
||||
* data, it may return QSE_NULL. You need to set a proper freeer to free up
|
||||
* memory allocated for copy.
|
||||
*
|
||||
* SEE ALSO
|
||||
* qse_lda_setcopier, qse_lda_getcopier, QSE_LDA_COPIER
|
||||
*
|
||||
* SYNOPSIS
|
||||
*/
|
||||
typedef void* (*qse_lda_copier_t) (
|
||||
qse_lda_t* lda /* lda */,
|
||||
void* dptr /* the pointer to data to copy */,
|
||||
qse_size_t dlen /* the length of data to copy */
|
||||
);
|
||||
/******/
|
||||
|
||||
/****t* Common/qse_lda_freeer_t
|
||||
* NAME
|
||||
* qse_lda_freeer_t - define a node destruction callback
|
||||
* SYNOPSIS
|
||||
/**
|
||||
* The qse_lda_freeer_t type defines a node destruction callback.
|
||||
*/
|
||||
typedef void (*qse_lda_freeer_t) (
|
||||
qse_lda_t* lda /* lda */,
|
||||
void* dptr /* the pointer to data to free */,
|
||||
qse_size_t dlen /* the length of data to free */
|
||||
);
|
||||
/******/
|
||||
|
||||
/****t* Common/qse_lda_comper_t
|
||||
* NAME
|
||||
* qse_lda_comper_t - define a data comparator
|
||||
/**
|
||||
* The qse_lda_comper_t type defines a key comparator that is called when
|
||||
* the list needs to compare data. A linear dynamic array is created with a
|
||||
* default comparator that performs bitwise comparison.
|
||||
*
|
||||
* DESCRIPTION
|
||||
* The qse_lda_comper_t type defines a key comparator that is called when
|
||||
* the list needs to compare data. A linear dynamic array is created with a
|
||||
* default comparator that performs bitwise comparison.
|
||||
* The comparator should return 0 if the data are the same and a non-zero
|
||||
* integer otherwise.
|
||||
*
|
||||
* The comparator should return 0 if the data are the same and a non-zero
|
||||
* integer otherwise.
|
||||
*
|
||||
* SYNOPSIS
|
||||
*/
|
||||
typedef int (*qse_lda_comper_t) (
|
||||
qse_lda_t* lda /* a linear dynamic array */,
|
||||
@ -126,42 +102,27 @@ typedef int (*qse_lda_comper_t) (
|
||||
const void* dptr2 /* a data pointer */,
|
||||
qse_size_t dlen2 /* a data length */
|
||||
);
|
||||
/******/
|
||||
|
||||
/****t* Common/qse_lda_keeper_t
|
||||
* NAME
|
||||
* qse_lda_keeper_t - define a value keeper
|
||||
*
|
||||
* DESCRIPTION
|
||||
* The qse_lda_keeper_t type defines a value keeper that is called when
|
||||
* a value is retained in the context that it should be destroyed because
|
||||
* it is identical to a new value. Two values are identical if their beginning
|
||||
* pointers and their lengths are equal.
|
||||
*
|
||||
* SYNOPSIS
|
||||
/**
|
||||
* The qse_lda_keeper_t type defines a value keeper that is called when
|
||||
* a value is retained in the context that it should be destroyed because
|
||||
* it is identical to a new value. Two values are identical if their beginning
|
||||
* pointers and their lengths are equal.
|
||||
*/
|
||||
typedef void (*qse_lda_keeper_t) (
|
||||
qse_lda_t* lda /* lda */,
|
||||
void* vptr /* the pointer to a value */,
|
||||
qse_size_t vlen /* the length of a value */
|
||||
);
|
||||
/******/
|
||||
|
||||
/****t* Common/qse_lda_sizer_t
|
||||
* NAME
|
||||
* qse_lda_sizer_t - define an array size calculator
|
||||
*
|
||||
* DESCRIPTION
|
||||
* The qse_lda_sizer_t type defines an array size claculator that is called
|
||||
* when the array needs to be resized.
|
||||
*
|
||||
* SYNOPSIS
|
||||
/**
|
||||
* The qse_lda_sizer_t type defines an array size claculator that is called
|
||||
* when the array needs to be resized.
|
||||
*/
|
||||
typedef qse_size_t (*qse_lda_sizer_t) (
|
||||
qse_lda_t* lda, /* a linear dynamic array */
|
||||
qse_size_t hint /* a sizing hint */
|
||||
);
|
||||
/******/
|
||||
|
||||
typedef qse_lda_walk_t (*qse_lda_walker_t) (
|
||||
qse_lda_t* lda /* a linear dynamic array */,
|
||||
@ -169,11 +130,8 @@ typedef qse_lda_walk_t (*qse_lda_walker_t) (
|
||||
void* arg /* user-defined data */
|
||||
);
|
||||
|
||||
/****s* Common/qse_lda_t
|
||||
* NAME
|
||||
* qse_lda_t - define a linear dynamic array
|
||||
*
|
||||
* SYNOPSIS
|
||||
/**
|
||||
* The qse_lda_t type defines a linear dynamic array.
|
||||
*/
|
||||
struct qse_lda_t
|
||||
{
|
||||
@ -185,24 +143,19 @@ struct qse_lda_t
|
||||
qse_lda_keeper_t keeper; /* data keeper */
|
||||
qse_lda_sizer_t sizer; /* size calculator */
|
||||
qse_byte_t scale; /* scale factor */
|
||||
qse_size_t size; /* the number of items */
|
||||
qse_size_t size; /* number of items */
|
||||
qse_size_t capa; /* capacity */
|
||||
qse_lda_node_t** node;
|
||||
};
|
||||
/******/
|
||||
|
||||
/****s*
|
||||
* NAME
|
||||
* qse_lda_node_t - define a linear dynamic array node
|
||||
*
|
||||
* SYNOPSIS
|
||||
/**
|
||||
* The qse_lda_node_t type defines a linear dynamic array node
|
||||
*/
|
||||
struct qse_lda_node_t
|
||||
{
|
||||
void* dptr;
|
||||
qse_size_t dlen;
|
||||
};
|
||||
/******/
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
@ -210,53 +163,37 @@ extern "C" {
|
||||
|
||||
QSE_DEFINE_COMMON_FUNCTIONS (lda)
|
||||
|
||||
/****f* Common/qse_lda_open
|
||||
* NAME
|
||||
* qse_lda_open - create a linear dynamic array
|
||||
*
|
||||
* SYNOPSIS
|
||||
/**
|
||||
* The qse_lda_open() function creates a linear dynamic array.
|
||||
*/
|
||||
qse_lda_t* qse_lda_open (
|
||||
qse_mmgr_t* lda,
|
||||
qse_size_t ext,
|
||||
qse_size_t capa
|
||||
);
|
||||
/******/
|
||||
|
||||
/****f* Common/qse_lda_close
|
||||
* NAME
|
||||
* qse_lda_close - destroy a linear dynamic array
|
||||
*
|
||||
* SYNOPSIS
|
||||
/**
|
||||
* The qse_lda_close() function destroys a linear dynamic array.
|
||||
*/
|
||||
void qse_lda_close (
|
||||
qse_lda_t* lda
|
||||
);
|
||||
/******/
|
||||
|
||||
/****f* Common/qse_lda_init
|
||||
* NAME
|
||||
* qse_lda_init - initialize a linear dynamic array
|
||||
*
|
||||
* SYNOPSIS
|
||||
/**
|
||||
* The qse_lda_init() function initializes a linear dynamic array.
|
||||
*/
|
||||
qse_lda_t* qse_lda_init (
|
||||
qse_lda_t* lda,
|
||||
qse_mmgr_t* mmgr,
|
||||
qse_size_t capa
|
||||
);
|
||||
/******/
|
||||
|
||||
/****f* Common/qse_lda_fini
|
||||
* NAME
|
||||
* qse_lda_fini - deinitialize a linear dynamic array
|
||||
*
|
||||
* SYNOPSIS
|
||||
/**
|
||||
* The qse_lda_fini() function finalizes a linear dynamic array.
|
||||
*/
|
||||
void qse_lda_fini (
|
||||
qse_lda_t* lda
|
||||
);
|
||||
/******/
|
||||
|
||||
int qse_lda_getscale (
|
||||
qse_lda_t* lda /* lda */
|
||||
@ -383,43 +320,25 @@ qse_size_t qse_lda_update (
|
||||
qse_size_t dlen
|
||||
);
|
||||
|
||||
/****f* Common/qse_lda_delete
|
||||
* NAME
|
||||
* qse_lda_delete - delete data
|
||||
*
|
||||
* DESCRIPTION
|
||||
* The qse_lda_delete() function deletes the as many data as the count
|
||||
* from the index.
|
||||
*
|
||||
* RETURN
|
||||
* The qse_lda_delete() function returns the number of data deleted.
|
||||
*
|
||||
* SYNOPSIS
|
||||
/**
|
||||
* The qse_lda_delete() function deletes the as many data as the count
|
||||
* from the index. It returns the number of data deleted.
|
||||
*/
|
||||
qse_size_t qse_lda_delete (
|
||||
qse_lda_t* lda,
|
||||
qse_size_t index,
|
||||
qse_size_t count
|
||||
);
|
||||
/******/
|
||||
|
||||
/****f* Common/qse_lda_uplete
|
||||
* NAME
|
||||
* qse_lda_uplete - delete data node
|
||||
*
|
||||
* DESCRIPTION
|
||||
/**
|
||||
* The qse_lda_uplete() function deletes data node without compaction.
|
||||
*
|
||||
* RETURN
|
||||
* The qse_lda_uplete() function returns the number of data affected.
|
||||
*
|
||||
* It returns the number of data affected.
|
||||
*/
|
||||
qse_size_t qse_lda_uplete (
|
||||
qse_lda_t* lda,
|
||||
qse_size_t index,
|
||||
qse_size_t count
|
||||
);
|
||||
/******/
|
||||
|
||||
void qse_lda_clear (
|
||||
qse_lda_t* lda
|
||||
@ -437,6 +356,52 @@ void qse_lda_rwalk (
|
||||
void* arg
|
||||
);
|
||||
|
||||
/**
|
||||
* The qse_lda_pushstack() function appends data to the array. It is a utility
|
||||
* function to allow stack-like operations over an array. To do so, you should
|
||||
* not play with other non-stack related functions.
|
||||
*/
|
||||
qse_size_t qse_lda_pushstack (
|
||||
qse_lda_t* lda,
|
||||
void* dptr,
|
||||
qse_size_t dlen
|
||||
);
|
||||
|
||||
/**
|
||||
* The qse_lda_popstack() function deletes the last array data. It is a utility
|
||||
* function to allow stack-like operations over an array. To do so, you should
|
||||
* not play with other non-stack related functions.
|
||||
* @note You must not call this function if @a lda is empty.
|
||||
*/
|
||||
void qse_lda_popstack (
|
||||
qse_lda_t* lda
|
||||
);
|
||||
|
||||
/**
|
||||
* The qse_lda_pushheap() function inserts data to an array while keeping the
|
||||
* largest data at position 0. It is a utiltiy funtion to implement a binary
|
||||
* max-heap over an array. Inverse the comparator to implement a min-heap.
|
||||
* @return number of array elements
|
||||
* @note You must not mess up the array with other non-heap related functions
|
||||
* to keep the heap property.
|
||||
*/
|
||||
qse_size_t qse_lda_pushheap (
|
||||
qse_lda_t* lda,
|
||||
void* dptr,
|
||||
qse_size_t dlen
|
||||
);
|
||||
|
||||
/**
|
||||
* The qse_lda_popheap() function deletes data at position 0 while keeping
|
||||
* the largest data at positon 0. It is a utiltiy funtion to implement a binary
|
||||
* max-heap over an array.
|
||||
* @note You must not mess up the array with other non-heap related functions
|
||||
* to keep the heap property.
|
||||
*/
|
||||
void qse_lda_popheap (
|
||||
qse_lda_t* lda
|
||||
);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: str.h 320 2009-12-21 12:29:52Z hyunghwan.chung $
|
||||
* $Id: str.h 323 2010-04-05 12:50:01Z hyunghwan.chung $
|
||||
*
|
||||
Copyright 2006-2009 Chung, Hyung-Hwan.
|
||||
This file is part of QSE.
|
||||
@ -120,31 +120,29 @@ extern "C" {
|
||||
* basic string functions
|
||||
*/
|
||||
|
||||
/****f* Common/qse_strlen
|
||||
* NAME
|
||||
* qse_strlen - get the number of characters
|
||||
* DESCRIPTION
|
||||
* The qse_strlen() function returns the number of characters in a
|
||||
* null-terminated string. The length returned excludes a terminating null.
|
||||
* SYNOPSIS
|
||||
/**
|
||||
* The qse_strlen() function returns the number of characters in a
|
||||
* null-terminated string. The length returned excludes a terminating null.
|
||||
*/
|
||||
qse_size_t qse_strlen (
|
||||
const qse_char_t* str
|
||||
);
|
||||
/******/
|
||||
|
||||
/****f* Common/qse_strbytes
|
||||
* NAME
|
||||
* qse_strbytes - get the length of a string in bytes
|
||||
* DESCRIPTOIN
|
||||
* The qse_strbytes() function returns the number of bytes a null-terminated
|
||||
* string is holding excluding a terminating null.
|
||||
* SYNOPSIS
|
||||
/**
|
||||
* The qse_strbytes() function returns the number of bytes a null-terminated
|
||||
* string is holding excluding a terminating null.
|
||||
*/
|
||||
qse_size_t qse_strbytes (
|
||||
const qse_char_t* str
|
||||
);
|
||||
/******/
|
||||
|
||||
qse_size_t qse_mbslen (
|
||||
const qse_mchar_t* mbs
|
||||
);
|
||||
|
||||
qse_size_t qse_wcslen (
|
||||
const qse_wchar_t* wcs
|
||||
);
|
||||
|
||||
qse_size_t qse_strcpy (
|
||||
qse_char_t* buf,
|
||||
@ -170,36 +168,32 @@ qse_size_t qse_strxncpy (
|
||||
qse_size_t len
|
||||
);
|
||||
|
||||
/****f* Common/qse_strfcpy
|
||||
* NAME
|
||||
* qse_strfcpy - copy a string
|
||||
* DESCRIPTION
|
||||
* "format ${1} ${3} ${2} \\${1} string"
|
||||
* SYNOPSIS
|
||||
/**
|
||||
* The qse_strfcpy() function formats a string by position.
|
||||
* The position specifier is a number enclosed in ${ and }.
|
||||
* When ${ is preceeded by a backslash, it is treated literally.
|
||||
* A sameple format string containing the position specifiers are shown below:
|
||||
* @code
|
||||
* "${1} ${3} ${2} \\${1} string"
|
||||
* @endcode
|
||||
*/
|
||||
qse_size_t qse_strfcpy (
|
||||
qse_char_t* buf,
|
||||
const qse_char_t* fmt,
|
||||
const qse_char_t* str[]
|
||||
);
|
||||
/******/
|
||||
|
||||
/****f* Common/qse_strfncpy
|
||||
* NAME
|
||||
* qse_strfncpy - copy a string
|
||||
* SYNOPSIS
|
||||
/**
|
||||
* The qse_strfncpy() function formats a string by position.
|
||||
*/
|
||||
qse_size_t qse_strfncpy (
|
||||
qse_char_t* buf,
|
||||
const qse_char_t* fmt,
|
||||
const qse_cstr_t str[]
|
||||
);
|
||||
/******/
|
||||
|
||||
/****f* Common/qse_strxfcpy
|
||||
* NAME
|
||||
* qse_strxfcpy - copy a string
|
||||
* SYNOPSIS
|
||||
/**
|
||||
* The qse_strxfcpy() function formats a string by position.
|
||||
*/
|
||||
qse_size_t qse_strxfcpy (
|
||||
qse_char_t* buf,
|
||||
@ -207,12 +201,9 @@ qse_size_t qse_strxfcpy (
|
||||
const qse_char_t* fmt,
|
||||
const qse_char_t* str[]
|
||||
);
|
||||
/******/
|
||||
|
||||
/****f* Common/qse_strxfncpy
|
||||
* NAME
|
||||
* qse_strxfncpy - copy a string
|
||||
* SYNOPSIS
|
||||
/**
|
||||
* The qse_strxfncpy() function formats a string by position.
|
||||
*/
|
||||
qse_size_t qse_strxfncpy (
|
||||
qse_char_t* buf,
|
||||
@ -220,7 +211,6 @@ qse_size_t qse_strxfncpy (
|
||||
const qse_char_t* fmt,
|
||||
const qse_cstr_t str[]
|
||||
);
|
||||
/******/
|
||||
|
||||
qse_size_t qse_strxcat (
|
||||
qse_char_t* buf,
|
||||
@ -235,11 +225,23 @@ qse_size_t qse_strxncat (
|
||||
qse_size_t len
|
||||
);
|
||||
|
||||
int qse_strcmp (const qse_char_t* s1, const qse_char_t* s2);
|
||||
int qse_strxcmp (const qse_char_t* s1, qse_size_t len1, const qse_char_t* s2);
|
||||
int qse_strcmp (
|
||||
const qse_char_t* s1,
|
||||
const qse_char_t* s2
|
||||
);
|
||||
|
||||
int qse_strxcmp (
|
||||
const qse_char_t* s1,
|
||||
qse_size_t len1,
|
||||
const qse_char_t* s2
|
||||
);
|
||||
|
||||
int qse_strxncmp (
|
||||
const qse_char_t* s1, qse_size_t len1,
|
||||
const qse_char_t* s2, qse_size_t len2);
|
||||
const qse_char_t* s1,
|
||||
qse_size_t len1,
|
||||
const qse_char_t* s2,
|
||||
qse_size_t len2
|
||||
);
|
||||
|
||||
int qse_strcasecmp (const qse_char_t* s1, const qse_char_t* s2);
|
||||
|
||||
@ -361,20 +363,56 @@ qse_char_t* qse_strxnrstr (
|
||||
qse_size_t subsz
|
||||
);
|
||||
|
||||
qse_char_t* qse_strchr (const qse_char_t* str, qse_cint_t c);
|
||||
qse_char_t* qse_strxchr (const qse_char_t* str, qse_size_t len, qse_cint_t c);
|
||||
qse_char_t* qse_strrchr (const qse_char_t* str, qse_cint_t c);
|
||||
qse_char_t* qse_strxrchr (const qse_char_t* str, qse_size_t len, qse_cint_t c);
|
||||
qse_char_t* qse_strchr (
|
||||
const qse_char_t* str,
|
||||
qse_cint_t c
|
||||
);
|
||||
|
||||
qse_char_t* qse_strxchr (
|
||||
const qse_char_t* str,
|
||||
qse_size_t len,
|
||||
qse_cint_t c
|
||||
);
|
||||
|
||||
qse_char_t* qse_strrchr (
|
||||
const qse_char_t* str,
|
||||
qse_cint_t c
|
||||
);
|
||||
|
||||
qse_char_t* qse_strxrchr (
|
||||
const qse_char_t* str,
|
||||
qse_size_t len,
|
||||
qse_cint_t c
|
||||
);
|
||||
|
||||
/**
|
||||
* The qse_strbeg() function checks if the a string begins with a substring.
|
||||
* @return the pointer to a beginning of a matching beginning,
|
||||
* QSE_NULL if no match is found.
|
||||
*/
|
||||
qse_char_t* qse_strbeg (
|
||||
const qse_char_t* str,
|
||||
const qse_char_t* sub
|
||||
);
|
||||
|
||||
/* Checks if a string begins with a substring */
|
||||
qse_char_t* qse_strbeg (const qse_char_t* str, const qse_char_t* sub);
|
||||
qse_char_t* qse_strxbeg (
|
||||
const qse_char_t* str, qse_size_t len, const qse_char_t* sub);
|
||||
const qse_char_t* str,
|
||||
qse_size_t len,
|
||||
const qse_char_t* sub)
|
||||
;
|
||||
|
||||
qse_char_t* qse_strnbeg (
|
||||
const qse_char_t* str, const qse_char_t* sub, qse_size_t len);
|
||||
const qse_char_t* str,
|
||||
const qse_char_t* sub,
|
||||
qse_size_t len
|
||||
);
|
||||
|
||||
qse_char_t* qse_strxnbeg (
|
||||
const qse_char_t* str, qse_size_t len1,
|
||||
const qse_char_t* sub, qse_size_t len2);
|
||||
const qse_char_t* str,
|
||||
qse_size_t len1,
|
||||
const qse_char_t* sub,
|
||||
qse_size_t len2
|
||||
);
|
||||
|
||||
/**
|
||||
* The qse_strend() function checks if the a string ends with a substring.
|
||||
@ -443,12 +481,8 @@ qse_long_t qse_strxtolong (const qse_char_t* str, qse_size_t len);
|
||||
qse_uint_t qse_strxtouint (const qse_char_t* str, qse_size_t len);
|
||||
qse_ulong_t qse_strxtoulong (const qse_char_t* str, qse_size_t len);
|
||||
|
||||
/****f* Common/qse_strspl
|
||||
* NAME
|
||||
* qse_strspl - split a string into fields
|
||||
* SEE ALSO
|
||||
* qse_strspltrn
|
||||
* SYNOPSIS
|
||||
/**
|
||||
* The qse_strspl() function splits a string into fields.
|
||||
*/
|
||||
int qse_strspl (
|
||||
qse_char_t* str,
|
||||
@ -459,24 +493,24 @@ int qse_strspl (
|
||||
);
|
||||
/******/
|
||||
|
||||
/****f* Common/qse_strspltrn
|
||||
* NAME
|
||||
* qse_strspltrn - split a string translating special escape sequences
|
||||
* DESCRIPTION
|
||||
* The argument trset is a translation character set which is composed
|
||||
* of multiple character pairs. An escape character followed by the
|
||||
* first character in a pair is translated into the second character
|
||||
* in the pair. If trset is QSE_NULL, no translation is performed.
|
||||
* EXAMPLES
|
||||
* Let's translate a sequence of '\n' and '\r' to a new line and a carriage
|
||||
* return respectively.
|
||||
/**
|
||||
* The qse_strspltrn() function splits a string translating special
|
||||
* escape sequences.
|
||||
* The argument @a trset is a translation character set which is composed
|
||||
* of multiple character pairs. An escape character followed by the
|
||||
* first character in a pair is translated into the second character
|
||||
* in the pair. If trset is QSE_NULL, no translation is performed.
|
||||
*
|
||||
* Let's translate a sequence of '\n' and '\r' to a new line and a carriage
|
||||
* return respectively.
|
||||
* @code
|
||||
* qse_strspltrn (str, QSE_T(':'), QSE_T('['), QSE_T(']'), QSE_T('\\'), QSE_T("n\nr\r"), &nfields);
|
||||
* Given [xxx]:[\rabc\ndef]:[] as an input, the example breaks the second
|
||||
* fields to <CR>abc<NL>def where <CR> is a carriage return and <NL> is a
|
||||
* new line.
|
||||
* SEE ALSO
|
||||
* If you don't need any translation, you may call qse_strspl() alternatively.
|
||||
* SYNOPSIS
|
||||
* @endcode
|
||||
* Given [xxx]:[\rabc\ndef]:[] as an input, the example breaks the second
|
||||
* fields to <CR>abc<NL>def where <CR> is a carriage return and <NL> is a
|
||||
* new line.
|
||||
*
|
||||
* If you don't need any translation, you may call qse_strspl() alternatively.
|
||||
*/
|
||||
int qse_strspltrn (
|
||||
qse_char_t* str,
|
||||
@ -486,7 +520,6 @@ int qse_strspltrn (
|
||||
qse_char_t escape,
|
||||
const qse_char_t* trset
|
||||
);
|
||||
/******/
|
||||
|
||||
/**
|
||||
* The qse_strtrmx() function strips leading spaces and/or trailing
|
||||
@ -556,9 +589,50 @@ qse_size_t qse_strxpac (
|
||||
qse_size_t len /**< length */
|
||||
);
|
||||
|
||||
/**
|
||||
* The qse_mbstowcslen() function scans a null-terminated multibyte string
|
||||
* to calculate the number of wide characters it can be converted to.
|
||||
* The number of wide characters is returned via @a wcslen if it is not
|
||||
* #QSE_NULL. The function may be aborted if it has encountered invalid
|
||||
* or incomplete multibyte sequences. The return value, in this case,
|
||||
* is less than qse_strlen(mcs).
|
||||
* @return number of bytes scanned
|
||||
*/
|
||||
qse_size_t qse_mbstowcslen (
|
||||
const qse_mchar_t* mcs,
|
||||
qse_size_t* wcslen
|
||||
);
|
||||
|
||||
/**
|
||||
* The qse_mbsntowcsnlen() function scans a multibyte string of @a mcslen bytes
|
||||
* to get the number of wide characters it can be converted to.
|
||||
* The number of wide characters is returned via @a wcslen if it is not
|
||||
* #QSE_NULL. The function may be aborted if it has encountered invalid
|
||||
* or incomplete multibyte sequences. The return value, in this case,
|
||||
* is less than @a mcslen.
|
||||
* @return number of bytes scanned
|
||||
*/
|
||||
qse_size_t qse_mbsntowcsnlen (
|
||||
const qse_mchar_t* mcs,
|
||||
qse_size_t mcslen,
|
||||
qse_size_t* wcslen
|
||||
);
|
||||
|
||||
/**
|
||||
* The qse_mbstowcs() function converts a multibyte string to a wide
|
||||
* character string.
|
||||
*
|
||||
* @code
|
||||
* const qse_mchar_t* mbs = "a multibyte string";
|
||||
* qse_wchar_t buf[100];
|
||||
* qse_size_t bufsz = QSE_COUNTOF(buf), n;
|
||||
* n = qse_mbstowcs (mbs, buf, bufsz);
|
||||
* if (bufsz >= QSE_COUNTOF(buf)) { buffer too small }
|
||||
* if (mbs[n] != '\0') { incomplete processing }
|
||||
* //if (n != strlen(mbs)) { incomplete processing }
|
||||
* @endcode
|
||||
*
|
||||
* @return number of multibyte characters processed.
|
||||
*/
|
||||
qse_size_t qse_mbstowcs (
|
||||
const qse_mchar_t* mbs,
|
||||
@ -569,7 +643,7 @@ qse_size_t qse_mbstowcs (
|
||||
/**
|
||||
* The qse_mbsntowcsn() function converts a multibyte string to a
|
||||
* wide character string.
|
||||
* @return number of bytes handled.
|
||||
* @return number of multibyte characters processed.
|
||||
*/
|
||||
qse_size_t qse_mbsntowcsn (
|
||||
const qse_mchar_t* mbs,
|
||||
@ -578,11 +652,15 @@ qse_size_t qse_mbsntowcsn (
|
||||
qse_size_t* wcslen
|
||||
);
|
||||
|
||||
/****f* Common/qse_wcstombslen
|
||||
/**
|
||||
* The qse_wcstombslen() function scans a null-terminated wide character
|
||||
* string @a wcs to get the total number of multibyte characters that it can be
|
||||
* converted to. The resulting number of characters is stored into memory
|
||||
* pointed to by @a mbslen.
|
||||
* string @a wcs to get the total number of multibyte characters that it
|
||||
* can be converted to. The resulting number of characters is stored into
|
||||
* memory pointed to by @a mbslen.
|
||||
* Complete scanning is indicated by the following condition:
|
||||
* @code
|
||||
* qse_wcstombslen(wcs,&xx) == qse_strlen(wcs)
|
||||
* @endcode
|
||||
* @return number of wide characters handled
|
||||
*/
|
||||
qse_size_t qse_wcstombslen (
|
||||
@ -592,9 +670,13 @@ qse_size_t qse_wcstombslen (
|
||||
|
||||
/**
|
||||
* The qse_wcsntombsnlen() function scans a wide character wcs as long as
|
||||
* wcslen characters to get the get the total number of multibyte characters
|
||||
* @a wcslen characters to get the total number of multibyte characters
|
||||
* that it can be converted to. The resulting number of characters is stored
|
||||
* into memory pointed to by @a mbslen.
|
||||
* Complete scanning is indicated by the following condition:
|
||||
* @code
|
||||
* qse_wcstombslen(wcs,&xx) == wcslen
|
||||
* @endcode
|
||||
* @return number of wide characters handled
|
||||
*/
|
||||
qse_size_t qse_wcsntombsnlen (
|
||||
@ -608,12 +690,11 @@ qse_size_t qse_wcsntombsnlen (
|
||||
* string to a multibyte string and stores it into the buffer pointed to
|
||||
* by mbs. The pointer to a variable holding the buffer length should be
|
||||
* passed to the function as the third parameter. After conversion, it holds
|
||||
* the length of the multibyte string excluding the terminating-null.
|
||||
* the length of the multibyte string excluding the terminating-null character.
|
||||
* It may not null-terminate the resulting multibyte string if the buffer
|
||||
* is not large enough. You can check if the resulting mbslen is equal to
|
||||
* the input mbslen to know it.
|
||||
* @return number of wide characters handled
|
||||
* SYNOPSIS
|
||||
* @return number of wide characters processed
|
||||
*/
|
||||
qse_size_t qse_wcstombs (
|
||||
const qse_wchar_t* wcs,
|
||||
@ -627,14 +708,26 @@ qse_size_t qse_wcstombs (
|
||||
* @return the number of wide characters
|
||||
*/
|
||||
qse_size_t qse_wcsntombsn (
|
||||
const qse_wchar_t* wcs, /**< a wide string */
|
||||
const qse_wchar_t* wcs, /**< wide string */
|
||||
qse_size_t wcslen, /**< wide string length */
|
||||
qse_mchar_t* mbs, /**< a multibyte string buffer */
|
||||
qse_size_t* mbslen /**< the buffer size */
|
||||
qse_mchar_t* mbs, /**< multibyte string buffer */
|
||||
qse_size_t* mbslen /**< buffer size */
|
||||
);
|
||||
|
||||
/**
|
||||
* The qse_wcstombs_strict() function performs the same as the qse_wcsmbs()
|
||||
* The qse_mbstowcs_strict() function performs the same as the qse_mbstowcs()
|
||||
* function except that it returns an error if it can't fully convert the
|
||||
* input string and/or the buffer is not large enough.
|
||||
* @return 0 on success, -1 on failure.
|
||||
*/
|
||||
int qse_mbstowcs_strict (
|
||||
const qse_mchar_t* mbs,
|
||||
qse_wchar_t* wcs,
|
||||
qse_size_t wcslen
|
||||
);
|
||||
|
||||
/**
|
||||
* The qse_wcstombs_strict() function performs the same as the qse_wcstombs()
|
||||
* function except that it returns an error if it can't fully convert the
|
||||
* input string and/or the buffer is not large enough.
|
||||
* @return 0 on success, -1 on failure.
|
||||
@ -657,75 +750,51 @@ void qse_str_close (
|
||||
qse_str_t* str
|
||||
);
|
||||
|
||||
/****f* Common/qse_str_init
|
||||
* NAME
|
||||
* qse_str_init - initialize a dynamically resizable string
|
||||
* NOTE
|
||||
* If the parameter capa is 0, it doesn't allocate the internal buffer
|
||||
* in advance.
|
||||
* SYNOPSIS
|
||||
/**
|
||||
* The qse_str_init() function initializes a dynamically resizable string
|
||||
* If the parameter capa is 0, it doesn't allocate the internal buffer
|
||||
* in advance.
|
||||
*/
|
||||
qse_str_t* qse_str_init (
|
||||
qse_str_t* str,
|
||||
qse_mmgr_t* mmgr,
|
||||
qse_size_t capa
|
||||
);
|
||||
/******/
|
||||
|
||||
/****f* Common/qse_str_fini
|
||||
* NAME
|
||||
* qse_str_fini - finialize a dynamically resizable string
|
||||
* SYNOPSIS
|
||||
/**
|
||||
* The qse_str_fini() function finalizes a dynamically resizable string.
|
||||
*/
|
||||
void qse_str_fini (
|
||||
qse_str_t* str
|
||||
);
|
||||
/******/
|
||||
|
||||
/****f* Common/qse_str_yield
|
||||
* NAME
|
||||
* qse_str_yield - yield the buffer
|
||||
*
|
||||
* DESCRIPTION
|
||||
* The qse_str_yield() function assigns the buffer to an variable of the
|
||||
* qse_xstr_t type and recreate a new buffer of the new_capa capacity.
|
||||
* The function fails if it fails to allocate a new buffer.
|
||||
*
|
||||
* RETURN
|
||||
* The qse_str_yield() function returns 0 on success, and -1 on failure.
|
||||
*
|
||||
* SYNOPSIS
|
||||
/**
|
||||
* The qse_str_yield() function assigns the buffer to an variable of the
|
||||
* qse_xstr_t type and recreate a new buffer of the @a new_capa capacity.
|
||||
* The function fails if it fails to allocate a new buffer.
|
||||
* @return 0 on success, and -1 on failure.
|
||||
*/
|
||||
int qse_str_yield (
|
||||
qse_str_t* str /* a dynamic string */,
|
||||
qse_xstr_t* buf /* the pointer to a qse_xstr_t variable */,
|
||||
int new_capa /* new capacity in number of characters */
|
||||
qse_str_t* str, /**< string */
|
||||
qse_xstr_t* buf, /**< buffer pointer */
|
||||
int new_capa /**< new capacity */
|
||||
);
|
||||
/******/
|
||||
|
||||
/****f* Common/qse_str_getsizer
|
||||
* NAME
|
||||
* qse_str_getsizer - get the sizer
|
||||
* RETURN
|
||||
* a sizer function set or QSE_NULL if no sizer is set.
|
||||
* SYNOPSIS
|
||||
/**
|
||||
* The qse_str_getsizer() function gets the sizer.
|
||||
* @return sizer function set or QSE_NULL if no sizer is set.
|
||||
*/
|
||||
qse_str_sizer_t qse_str_getsizer (
|
||||
qse_str_t* str
|
||||
);
|
||||
/******/
|
||||
|
||||
/****f* Common/qse_str_setsizer
|
||||
* NAME
|
||||
* qse_str_setsizer - specify a sizer
|
||||
* DESCRIPTION
|
||||
* The qse_str_setsizer() function specify a new sizer for a dynamic string.
|
||||
* With no sizer specified, the dynamic string doubles the current buffer
|
||||
* when it needs to increase its size. The sizer function is passed a dynamic
|
||||
* string and the minimum capacity required to hold data after resizing.
|
||||
* The string is truncated if the sizer function returns a smaller number
|
||||
* than the hint passed.
|
||||
* SYNOPSIS
|
||||
/**
|
||||
* The qse_str_setsizer() function specify a new sizer for a dynamic string.
|
||||
* With no sizer specified, the dynamic string doubles the current buffer
|
||||
* when it needs to increase its size. The sizer function is passed a dynamic
|
||||
* string and the minimum capacity required to hold data after resizing.
|
||||
* The string is truncated if the sizer function returns a smaller number
|
||||
* than the hint passed.
|
||||
*/
|
||||
void qse_str_setsizer (
|
||||
qse_str_t* str,
|
||||
@ -733,87 +802,58 @@ void qse_str_setsizer (
|
||||
);
|
||||
/******/
|
||||
|
||||
/****f* Common/qse_str_getcapa
|
||||
* NAME
|
||||
* qse_str_getcapa - get capacity
|
||||
* DESCRIPTION
|
||||
* The qse_str_getcapa() function returns the current capacity.
|
||||
* You may use QSE_STR_CAPA(str) macro for performance sake.
|
||||
* RETURNS
|
||||
* current capacity in number of characters.
|
||||
* SYNOPSIS
|
||||
/**
|
||||
* The qse_str_getcapa() function returns the current capacity.
|
||||
* You may use QSE_STR_CAPA(str) macro for performance sake.
|
||||
* @return current capacity in number of characters.
|
||||
*/
|
||||
qse_size_t qse_str_getcapa (
|
||||
qse_str_t* str
|
||||
);
|
||||
/******/
|
||||
|
||||
/****f* Common/qse_str_setcapa
|
||||
* NAME
|
||||
* qse_str_setcapa - set new capacity
|
||||
* DESCRIPTION
|
||||
* The qse_str_setcapa() function sets the new capacity. If the new capacity
|
||||
* is smaller than the old, the overflowing characters are removed from
|
||||
* from the buffer.
|
||||
* RETURNS
|
||||
* (qse_size_t)-1 on failure, new capacity on success
|
||||
* SYNOPSIS
|
||||
/**
|
||||
* The qse_str_setcapa() function sets the new capacity. If the new capacity
|
||||
* is smaller than the old, the overflowing characters are removed from
|
||||
* from the buffer.
|
||||
* @return (qse_size_t)-1 on failure, new capacity on success
|
||||
*/
|
||||
qse_size_t qse_str_setcapa (
|
||||
qse_str_t* str,
|
||||
qse_size_t capa
|
||||
);
|
||||
/******/
|
||||
|
||||
/****f* Common/qse_str_getlen
|
||||
* NAME
|
||||
* qse_str_getlen - get length
|
||||
* SYNOPSIS
|
||||
/**
|
||||
* The qse_str_getlen() function return the string length.
|
||||
*/
|
||||
qse_size_t qse_str_getlen (
|
||||
qse_str_t* str
|
||||
);
|
||||
/******/
|
||||
|
||||
/****f* Common/qse_str_setlen
|
||||
* NAME
|
||||
* qse_str_setlen - change length
|
||||
* RETURNS
|
||||
* (qse_size_t)-1 on failure, new length on success
|
||||
* SYNOPSIS
|
||||
/**
|
||||
* The qse_str_setlen() function changes the string length.
|
||||
* @return (qse_size_t)-1 on failure, new length on success
|
||||
*/
|
||||
qse_size_t qse_str_setlen (
|
||||
qse_str_t* str,
|
||||
qse_size_t len
|
||||
);
|
||||
/******/
|
||||
|
||||
/****f* Common/qse_str_clear
|
||||
* NAME
|
||||
* qse_str_clear - clear a string
|
||||
* DESCRIPTION
|
||||
* The qse_str_clear() funtion deletes all characters in a string and sets
|
||||
* the length to 0. It doesn't resize the internal buffer.
|
||||
* SYNOPSIS
|
||||
/**
|
||||
* The qse_str_clear() funtion deletes all characters in a string and sets
|
||||
* the length to 0. It doesn't resize the internal buffer.
|
||||
*/
|
||||
void qse_str_clear (
|
||||
qse_str_t* str
|
||||
);
|
||||
/******/
|
||||
|
||||
/****f* Common/qse_str_swap
|
||||
* NAME
|
||||
* qse_str_swap - swap buffers of two dynamic string
|
||||
* DESCRIPTION
|
||||
* The qse_str_swap() function exchanges the pointers to a buffer between
|
||||
* two strings. It updates the length and the capacity accordingly.
|
||||
* SYNOPSIS
|
||||
/**
|
||||
* The qse_str_swap() function exchanges the pointers to a buffer between
|
||||
* two strings. It updates the length and the capacity accordingly.
|
||||
*/
|
||||
void qse_str_swap (
|
||||
qse_str_t* str1,
|
||||
qse_str_t* str2
|
||||
);
|
||||
/******/
|
||||
|
||||
qse_size_t qse_str_cpy (
|
||||
qse_str_t* str,
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: macros.h 289 2009-09-16 06:35:29Z hyunghwan.chung $
|
||||
* $Id: macros.h 323 2010-04-05 12:50:01Z hyunghwan.chung $
|
||||
*
|
||||
Copyright 2006-2009 Chung, Hyung-Hwan.
|
||||
This file is part of QSE.
|
||||
@ -27,6 +27,14 @@
|
||||
* <qse/macros.h> contains various useful macro definitions.
|
||||
*/
|
||||
|
||||
#if defined(__STDC_VERSION__) && (__STDC_VERSION__>=199901L)
|
||||
# define QSE_INLINE inline
|
||||
#elif defined(__GNUC__) && defined(__GNUC_GNU_INLINE__)
|
||||
# define QSE_INLINE /*extern*/ inline
|
||||
#else
|
||||
# define QSE_INLINE
|
||||
#endif
|
||||
|
||||
/**
|
||||
* The #QSE_NULL macro defines a special pointer value to indicate an error or
|
||||
* that it does not point to anything.
|
||||
@ -128,13 +136,13 @@
|
||||
|
||||
#define QSE_ABS(x) ((x) < 0? -(x): (x))
|
||||
|
||||
#define QSE_ERR_THROW(id) goto __err_ ## id
|
||||
#define QSE_ERR_CATCH(id) while(0) __err_ ## id:
|
||||
#define QSE_THROW_ERR(id) goto __err_ ## id
|
||||
#define QSE_CATCH_ERR(id) while(0) __err_ ## id:
|
||||
|
||||
#define QSE_LOOP_CONTINUE(id) goto __loop_ ## id ## _begin__
|
||||
#define QSE_LOOP_BREAK(id) goto __loop_ ## id ## _end__
|
||||
#define QSE_LOOP_BEGIN(id) __loop_ ## id ## _begin__: {
|
||||
#define QSE_LOOP_END(id) QSE_LOOP_CONTINUE(id) } __loop_ ## id ## _end__:
|
||||
#define QSE_CONTINUE_LOOP(id) goto __loop_ ## id ## _begin__
|
||||
#define QSE_BREAK_LOOP(id) goto __loop_ ## id ## _end__
|
||||
#define QSE_BEGIN_LOOP(id) __loop_ ## id ## _begin__: {
|
||||
#define QSE_END_LOOP(id) QSE_LOOP_CONTINUE(id) } __loop_ ## id ## _end__:
|
||||
|
||||
#define QSE_REPEAT(n,blk) \
|
||||
do { \
|
||||
@ -196,6 +204,16 @@
|
||||
# define QSE_END_PACKED_STRUCT() };
|
||||
#endif
|
||||
|
||||
/**
|
||||
* The QSE_STRUCT_FIELD() macro provides a neutral way to specify
|
||||
* a field ID for initialzing a structure in both C9X and C89
|
||||
*/
|
||||
#if (defined(__STDC_VERSION__) && (__STDC_VERSION__>=199901L)) || defined(__GNUC__)
|
||||
# define QSE_STRUCT_FIELD(id) .id =
|
||||
#else
|
||||
# define QSE_STRUCT_FIELD(id)
|
||||
#endif
|
||||
|
||||
#ifdef NDEBUG
|
||||
# define QSE_ASSERT(expr) ((void)0)
|
||||
# define QSE_ASSERTX(expr,desc) ((void)0)
|
||||
@ -227,8 +245,17 @@
|
||||
* The QSE_DEFINE_COMMON_FIELDS() macro defines common object fields.
|
||||
*/
|
||||
#define QSE_DEFINE_COMMON_FIELDS(name) \
|
||||
qse_mmgr_t* mmgr;
|
||||
qse_mmgr_t* mmgr;
|
||||
|
||||
|
||||
#define QSE_BEGIN_CLASS(name) \
|
||||
typedef struct name name; \
|
||||
struct name \
|
||||
{ \
|
||||
qse_mmgr_t* mmgr; \
|
||||
|
||||
#define QSE_END_CLASS(name) };
|
||||
|
||||
/**
|
||||
* The QSE_DEFINE_COMMON_FUNCTIONS() macro defines common object functions.
|
||||
* - @code void qse_xxx_setmmgr (qse_xxx_t* xxx, qse_mmgr_t* mmgr); @endcode
|
||||
|
Reference in New Issue
Block a user