00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00044 #ifndef CSTRING_INCL_CSTRING_H_CSTRING
00045 #define CSTRING_INCL_CSTRING_H_CSTRING
00046
00047
00048
00049
00050
00051 #ifndef CSTRING_DOCUMENTATION_SKIP_SECTION
00052 # define CSTRING_VER_CSTRING_H_CSTRING_MAJOR 3
00053 # define CSTRING_VER_CSTRING_H_CSTRING_MINOR 7
00054 # define CSTRING_VER_CSTRING_H_CSTRING_REVISION 1
00055 # define CSTRING_VER_CSTRING_H_CSTRING_EDIT 57
00056 #endif
00057
00074 #ifndef CSTRING_DOCUMENTATION_SKIP_SECTION
00075 # define CSTRING_VER_1_0_1 0x01000100
00076 # define CSTRING_VER_1_0_2 0x01000200
00077 # define CSTRING_VER_2_0_1 0x02000100
00078 # define CSTRING_VER_2_1_1 0x02010100
00079 # define CSTRING_VER_2_2_1 0x02020100
00080 # define CSTRING_VER_3_0_1 0x03000100
00081 # define CSTRING_VER_3_1_1 0x03010100
00082 # define CSTRING_VER_3_1_2 0x03010200
00083 # define CSTRING_VER_3_1_3 0x03010300
00084 # define CSTRING_VER_3_2_1 0x03020100
00085 # define CSTRING_VER_3_3_1 0x03030100
00086 # define CSTRING_VER_3_3_2 0x03030200
00087 # define CSTRING_VER_3_4_1 0x03040100
00088 # define CSTRING_VER_3_4_2 0x03040200
00089 # define CSTRING_VER_3_4_3 0x03040300
00090 # define CSTRING_VER_3_4_4 0x03040400
00091 # define CSTRING_VER_3_5_1 0x03050100
00092 # define CSTRING_VER_3_5_2 0x03050200
00093
00094 # define CSTRING_VER CSTRING_VER_3_5_2
00095 #else
00096 # define CSTRING_VER 0x03050200
00097 #endif
00098
00099 #define CSTRING_VER_MAJOR 3
00100 #define CSTRING_VER_MINOR 5
00101 #define CSTRING_VER_REVISION 2
00102
00103
00104
00105
00106
00107 #include <stddef.h>
00108 #include <stdio.h>
00109
00110
00111
00112
00113
00121
00122
00123
00124
00125 #ifdef __cplusplus
00126 # define CSTRING_EXTERN_C extern "C"
00127 #else
00128 # define CSTRING_EXTERN_C extern
00129 #endif
00130
00131
00132
00133
00134
00138 enum CSTRING_RC
00139 {
00140 CSTRING_RC_SUCCESS = 0
00141 , CSTRING_RC_OUTOFMEMORY
00142 , CSTRING_RC_FIXED
00143 , CSTRING_RC_BORROWED
00144 , CSTRING_RC_READONLY
00145 , CSTRING_RC_INVALIDARENA
00146 , CSTRING_RC_CUSTOMARENANOTSUPPORTED
00147 , CSTRING_RC_EXCEEDFIXEDCAPACITY
00148 , CSTRING_RC_EXCEEDBORROWEDCAPACITY
00149 , CSTRING_RC_CANNOTYIELDFROMSO
00150 , CSTRING_RC_ARENAOVERLOADED
00151
00152 , CSTRING_RC_INVALIDSTREAM
00153 , CSTRING_RC_EOF
00154 , CSTRING_RC_INVALIDSECTION
00155 , CSTRING_RC_IOERROR
00156 };
00157 #ifndef CSTRING_DOCUMENTATION_SKIP_SECTION
00158 typedef enum CSTRING_RC CSTRING_RC;
00159 #endif
00160
00161
00162
00163
00164
00168 typedef size_t cstring_flags_t;
00169
00177 struct cstring_t
00178 {
00179 size_t len;
00180 char* ptr;
00182 size_t capacity;
00183 cstring_flags_t flags;
00185 };
00186 #ifndef CSTRING_DOCUMENTATION_SKIP_SECTION
00187 typedef struct cstring_t cstring_t;
00188 #endif
00189
00194 #define cstring_t_DEFAULT { 0, NULL, 0, 0 }
00195
00196
00197
00198
00199
00200 #ifndef CSTRING_NO_USE_SYNESIS_APIS
00201 # if defined(_SYNSOFT_INCL_H_MLMEMORY)
00202 # define CSTRING_USE_SYNESIS_APIS
00203 # endif
00204 #endif
00205
00206
00207
00208
00209
00220 #define CSTRING_FROM_END(x) (-1 - (int)(x))
00221
00222
00223
00224
00225
00234 #define CSTRING_F_TYPE_MASK (0x003f)
00235 #define CSTRING_F_MEMORY_IS_INTERNAL_HEAP (0x0000)
00237 #define CSTRING_F_MEMORY_IS_BORROWED (0x0001)
00240 #define CSTRING_F_MEMORY_IS_FIXED (0x0002)
00242 #define CSTRING_F_MEMORY_IS_READONLY (0x0004)
00243 #define CSTRING_F_MEMORY_IS_CONST CSTRING_F_MEMORY_IS_READONLY
00245 #define CSTRING_F_MEMORY_IS_OFFSET (0x0040)
00248 #define CSTRING_F_ARENA_MASK (0xff00)
00249 #define CSTRING_F_USE_REALLOC (0x0000)
00251 #if defined(WIN32) || \
00252 defined(WIN64)
00253 # define CSTRING_F_USE_WINDOWS_GLOBAL_MEMORY (0x0100)
00256 # define CSTRING_F_USE_WINDOWS_PROCESSHEAP_MEMORY (0x0200)
00259 # define CSTRING_F_USE_WINDOWS_COM_TASK_MEMORY (0x0400)
00262 #endif
00263 #if defined(CSTRING_USE_SYNESIS_APIS)
00264 # define CSTRING_F_USE_SYNESIS_HATOR (0x1000)
00266 #endif
00267 #define CSTRING_F_USE_CUSTOMARENAFUNCTIONS (0x2000)
00270 #define CSTRING_F_CUSTOMARENA_CC_CDECL (0x0000)
00273 #define CSTRING_F_CUSTOMARENA_CC_STDCALL (0x0040)
00279
00280
00281
00282
00291 CSTRING_EXTERN_C char const *cstring_error( CSTRING_RC rc);
00292
00300 CSTRING_EXTERN_C CSTRING_RC cstring_init(
00301 struct cstring_t* pcs
00302 );
00303
00315 CSTRING_EXTERN_C CSTRING_RC cstring_create(
00316 struct cstring_t* pcs
00317 , char const* s
00318 );
00319
00333 CSTRING_EXTERN_C CSTRING_RC cstring_createLen(
00334 struct cstring_t* pcs
00335 , char const* s
00336 , size_t cch
00337 );
00338
00352 CSTRING_EXTERN_C CSTRING_RC cstring_createN(
00353 struct cstring_t* pcs
00354 , char ch
00355 , size_t n
00356 );
00357
00358
00379 CSTRING_EXTERN_C CSTRING_RC cstring_createEx(
00380 struct cstring_t* pcs
00381 , char const* s
00382 , cstring_flags_t flags
00383 , void* arena
00384 , size_t capacity
00385 );
00386
00409 CSTRING_EXTERN_C CSTRING_RC cstring_createLenEx(
00410 struct cstring_t* pcs
00411 , char const* s
00412 , size_t cch
00413 , cstring_flags_t flags
00414 , void* arena
00415 , size_t capacity
00416 );
00417
00428 CSTRING_EXTERN_C CSTRING_RC cstring_destroy(
00429 struct cstring_t* pcs
00430 );
00431
00432
00451 CSTRING_EXTERN_C CSTRING_RC cstring_yield2(
00452 struct cstring_t* pcs
00453 , char** pPayload
00454 , void** pRaw
00455 );
00456
00457 #ifdef CSTRING_OBSOLETE
00458 CSTRING_EXTERN_C CSTRING_RC cstring_yield(
00459 struct cstring_t* pcs
00460 , char** ppBuff
00461 );
00462 #endif
00463
00480 CSTRING_EXTERN_C CSTRING_RC cstring_setCapacity(
00481 struct cstring_t* pcs
00482 , size_t capacity
00483 );
00484
00485
00502 CSTRING_EXTERN_C CSTRING_RC cstring_assign(
00503 struct cstring_t* pcs
00504 , char const* s
00505 );
00506
00525 CSTRING_EXTERN_C CSTRING_RC cstring_assignLen(
00526 struct cstring_t* pcs
00527 , char const* s
00528 , size_t cch
00529 );
00530
00543 CSTRING_EXTERN_C CSTRING_RC cstring_copy(
00544 struct cstring_t* pcs
00545 , struct cstring_t const* pcsSrc
00546 );
00547
00560 CSTRING_EXTERN_C CSTRING_RC cstring_append(
00561 struct cstring_t* pcs
00562 , char const* s
00563 );
00564
00583 CSTRING_EXTERN_C CSTRING_RC cstring_appendLen(
00584 struct cstring_t* pcs
00585 , char const* s
00586 , size_t cch
00587 );
00588
00600 CSTRING_EXTERN_C CSTRING_RC cstring_truncate(
00601 struct cstring_t* pcs
00602 , size_t len
00603 );
00604
00617 CSTRING_EXTERN_C CSTRING_RC cstring_swap(
00618 struct cstring_t* pcs1
00619 , struct cstring_t* pcs2
00620 );
00621
00622
00640 CSTRING_EXTERN_C CSTRING_RC cstring_readline(
00641 FILE* stm
00642 , struct cstring_t* pcs
00643 , size_t* numRead
00644 );
00645
00662 CSTRING_EXTERN_C CSTRING_RC cstring_writeline(
00663 FILE* stm
00664 , struct cstring_t const* pcs
00665 , size_t* numWritten
00666 );
00667
00668
00674 CSTRING_EXTERN_C CSTRING_RC cstring_insert(
00675 struct cstring_t* pcs
00676 , int index
00677 , char const* s
00678 );
00679
00685 CSTRING_EXTERN_C CSTRING_RC cstring_insertLen(
00686 struct cstring_t* pcs
00687 , int index
00688 , char const* s
00689 , size_t cch
00690 );
00691
00706 CSTRING_EXTERN_C CSTRING_RC cstring_replace(
00707 struct cstring_t* pcs
00708 , int index
00709 , size_t len
00710 , char const* s
00711 );
00712
00728 CSTRING_EXTERN_C CSTRING_RC cstring_replaceLen(
00729 struct cstring_t* pcs
00730 , int index
00731 , size_t len
00732 , char const* s
00733 , size_t cch
00734 );
00735
00749 CSTRING_EXTERN_C CSTRING_RC cstring_replaceAll(
00750 struct cstring_t* pcs
00751 , char const* f
00752 , char const* t
00753 , size_t* numReplaced
00754 );
00755
00756
00757
00758 #ifndef CSTRING_DOCUMENTATION_SKIP_SECTION
00759 typedef int (*cstring_allocFailHandler)(void* pv, size_t cb, cstring_flags_t flags, void* param);
00760
00761
00763 CSTRING_EXTERN_C CSTRING_RC cstring_createLenFn(
00764 struct cstring_t* pcs
00765 , char const* s
00766 , size_t cch
00767 , cstring_flags_t flags
00768 , void* arena
00769 , size_t capacity
00770 , cstring_allocFailHandler pfnAllocFailHandler
00771 , void* param
00772 );
00773
00775 CSTRING_EXTERN_C CSTRING_RC cstring_setCapacityFn(
00776 struct cstring_t* pcs
00777 , size_t capacity
00778 , cstring_allocFailHandler pfnAllocFailHandler
00779 , void* param
00780 );
00781
00783 CSTRING_EXTERN_C CSTRING_RC cstring_assignFn(
00784 struct cstring_t* pcs
00785 , char const* s
00786 , cstring_allocFailHandler pfnAllocFailHandler
00787 , void* param
00788 );
00790 CSTRING_EXTERN_C CSTRING_RC cstring_assignLenFn(
00791 struct cstring_t* pcs
00792 , char const* s
00793 , size_t cch
00794 , cstring_allocFailHandler pfnAllocFailHandler
00795 , void* param
00796 );
00797
00799 CSTRING_EXTERN_C CSTRING_RC cstring_appendFn(
00800 struct cstring_t* pcs
00801 , char const* s
00802 , cstring_allocFailHandler pfnAllocFailHandler
00803 , void* param
00804 );
00805
00807 CSTRING_EXTERN_C CSTRING_RC cstring_appendLenFn(
00808 struct cstring_t* pcs
00809 , char const* s
00810 , size_t cch
00811 , cstring_allocFailHandler pfnAllocFailHandler
00812 , void* param
00813 );
00814 #endif
00815
00816
00817
00818
00819
00820 #if defined(_MSC_VER)
00821 # if _MSC_VER >= 1200
00822 # pragma warning(push)
00823 # endif
00824 # pragma warning(disable : 4514)
00825 #endif
00826
00827
00828
00829
00830
00831 #ifdef __cplusplus
00832
00833 inline char const* c_str_data_a(struct cstring_t const* pcs)
00834 {
00835 return (NULL == pcs || 0u == pcs->len) ? "" : pcs->ptr;
00836 }
00837 inline char const* c_str_data(struct cstring_t const* pcs)
00838 {
00839 return c_str_data_a(pcs);
00840 }
00841 inline size_t c_str_len_a(struct cstring_t const* pcs)
00842 {
00843 return (NULL == pcs) ? 0u : pcs->len;
00844 }
00845 inline size_t c_str_len(struct cstring_t const* pcs)
00846 {
00847 return c_str_len_a(pcs);
00848 }
00849 inline char const* c_str_ptr_a(struct cstring_t const* pcs)
00850 {
00851 return c_str_data_a(pcs);
00852 }
00853 inline char const* c_str_ptr(struct cstring_t const* pcs)
00854 {
00855 return c_str_data_a(pcs);
00856 }
00857
00858 inline char const* c_str_data_a(struct cstring_t const& cs)
00859 {
00860 return (0u == cs.len) ? "" : cs.ptr;
00861 }
00862 inline char const* c_str_data(struct cstring_t const& cs)
00863 {
00864 return c_str_data_a(cs);
00865 }
00866 inline size_t c_str_len_a(struct cstring_t const& cs)
00867 {
00868 return cs.len;
00869 }
00870 inline size_t c_str_len(struct cstring_t const& cs)
00871 {
00872 return c_str_len_a(cs);
00873 }
00874 inline char const* c_str_ptr_a(struct cstring_t const& cs)
00875 {
00876 return c_str_data_a(cs);
00877 }
00878 inline char const* c_str_ptr(struct cstring_t const& cs)
00879 {
00880 return c_str_data_a(cs);
00881 }
00882
00883 # ifndef _STLSOFT_NO_NAMESPACE
00884 namespace stlsoft
00885 {
00886 using ::c_str_data_a;
00887 using ::c_str_len_a;
00888 using ::c_str_ptr_a;
00889 using ::c_str_data;
00890 using ::c_str_len;
00891 using ::c_str_ptr;
00892
00893 }
00894 # endif
00895
00896 #endif
00897
00898
00899
00900
00901
00902 #if defined(_MSC_VER)
00903 # if _MSC_VER >= 1200
00904
00905 # endif
00906 #endif
00907
00908
00909
00910
00911
00912 #ifdef CSTRING_F_USE_WINDOWS_GLOBAL_MEMORY
00913 # define CSTRING_F_USE_WIN32_GLOBAL_MEMORY CSTRING_F_USE_WINDOWS_GLOBAL_MEMORY
00914 #endif
00915
00916 #ifdef CSTRING_F_USE_WINDOWS_PROCESSHEAP_MEMORY
00917 # define CSTRING_F_USE_WIN32_PROCESSHEAP_MEMORY CSTRING_F_USE_WINDOWS_PROCESSHEAP_MEMORY
00918 #endif
00919
00920 #ifdef CSTRING_F_USE_WINDOWS_COM_TASK_MEMORY
00921 # define CSTRING_F_USE_WIN32_COM_TASK_MEMORY CSTRING_F_USE_WINDOWS_COM_TASK_MEMORY
00922 #endif
00923
00924
00925
00926 #endif
00927
00928