Strx.h
[目次 | 型・クラス・構造体 | マクロ]
1|/**************************************************************************
2|* 1. <<< 文字列の拡張 (StrX) >>>
3|*【補足】
4|*・StrX では、文字列を格納する領域のサイズを指定するときは、
5|* 格納できる最大の文字列数+1、つまりメモリサイズを指定します。
6|***************************************************************************/
7|
8|#ifndef __STRX_H
9|#define __STRX_H
10|
11|/*----------------------------------------------------------------------
12|[Module Property]
13|name = StrX
14|title = 文字列
15|category = 基本型
16|src = strx.c
17|depend = Types, Errors
18|priority =
19|accord =
20|----------------------------------------------------------------------*/
21|
22|
23|
24|
25|/**************************************************************************
26|* 2. <<< 優先ヘッダ >>>
27|***************************************************************************/
28|#ifndef USES_PRIORITY_HEADER
29|/*[START_OF_PRIORITY_HEADER]*/
30|
31|#ifndef USES_STRX
32|#define USES_STRX
33|
34|typedef struct _StrX_ListElem StrX_ListElem;
35|typedef struct _StrX_ListElem2 StrX_ListElem2;
36|typedef struct _StrX_Mem StrX_Mem;
37|typedef struct _StrX_Set StrX_Set;
38|typedef struct _StrX_MemV StrX_MemV;
39|typedef struct _StrX_MemV2 StrX_MemV2;
40|typedef struct _StrX_MemV2E StrX_MemV2E;
41|typedef struct _StrX_SetV StrX_SetV;
42|typedef struct _StrX_MemVE StrX_MemVE;
43|typedef struct _StrX_Pathes StrX_Pathes;
44|typedef void StrX_ConvFunc( void* obj, char* s, int s_size );
45|typedef char StrX_Path[260];
46|
47|typedef int (*StrX_HashFunc)( const char* s, int width );
48|
49|#endif
50|
51|/*[END_OF_PRIORITY_HEADER]*/
52|#endif /* USES_PRIORITY_HEADER */
53|
54|#define StrX_Err_MemEmpty 3180 /* StrX_Mem empty */
55|#define StrX_Err_MallocEmpty 3181
56|#define StrX_Err_NoMoreParentDir 3182
57|
58|/**************************************************************************
59|* 3. <<< モジュール設定 >>>
60|***************************************************************************/
61|#ifndef STDX_SETTING
62|
63| /*#define STRX_USES_MALLOC*/ /* malloc を使用する関数を有効にする */
64|
65|#endif
66|
67|
68|#if _MAX_PATH > 260 /* StrX_Path のサイズチェック */
69| #error
70|#endif
71|
72|#ifdef _STDLIB
73|#include "stdlib.h"
74|#endif
75|
76|
77|/*------------------------------------------------------------------------*/
78|/* 4. <<< Interface Area ----------------------------------------------- >>> */
79|/*------------------------------------------------------------------------*/
80|
81|#ifdef __cplusplus
82|extern "C" {
83|#endif
84|
85|
86|
87|/***********************************************************
88|* 5. <<< 文字★ >>>
89|*【一覧】
90|*・制御文字 [StrX_SI, StrX_SO, StrX_ESC]
91|*・ディレクトリ区切り文字 [StrX_DirMark_char, StrX_DirMark_str]
92|*・漢字コードの種類
93|* [StrX_CodeT, StrX_Ascii, StrX_Jis, StrX_ShiftJis, StrX_Euc]
94|* [StrX_JisIn, StrX_JisOut]
95|*
96|* 6. <<< [改行文字] >>>
97|*・Windows の改行は、0x0D '\r' + 0x0A '\n'
98|*・UNIX の改行は、0x0A '\n' のみ
99|************************************************************/
100|/*bool StrX_isMBBLeadNotTerm( char s ) */
101|
102|
103|/***********************************************************
104|* 7. <<< 制御文字 [StrX_SI, StrX_SO, StrX_ESC] >>>
105|************************************************************/
106|#define StrX_SI 14
107|#define StrX_SO 15
108|#define StrX_ESC 0x1B
109|
110|
111|
112|/**************************************************************************
113|* 8. <<< ディレクトリ区切り文字 [StrX_DirMark_char, StrX_DirMark_str] >>>
114|***************************************************************************/
115|#define StrX_DirMark_char '\\'
116|#define StrX_DirMark_str "\\"
117|
118|
119|
120|/***********************************************************************
121|* 9. <<< [StrX_CodeT] 漢字コードの種類 >>>
122|* 10. <<< [StrX_Ascii, StrX_Jis, StrX_ShiftJis, StrX_Euc] >>>
123|* 11. <<< [StrX_JisIn, StrX_JisOut] >>>
124|************************************************************************/
125|typedef enum _StrX_CodeT {
126| StrX_Ascii =0, StrX_Jis, StrX_ShiftJis, StrX_Euc,
127| StrX_JisIn, StrX_JisOut
128|} StrX_CodeT;
129|
130|
131|
132|/***********************************************************
133|* 12. <<< [StrX] char* 型の文字列 ★>>>
134|************************************************************/
135|extern const char* StrX_argv0; /* main() で argv[0] 引数をポイントすること */
136|
137|
138|/***********************************************************
139|* 13. <<< (StrX) char* 型の文字列(コピー・連結) >>>
140|************************************************************/
141|char* StrX_cpy( char* dst, const char* src, int dst_size );
142|char* StrX_ncpy( char* dst, char* src, int n, int dst_maxLen );
143|void StrX_wordCpy( char* dec, int dec_len, const char* src, char term );
144|char* StrX_toCSV( char* dst, const char* src, int dst_maxLen );
145|char* StrX_meltCSV( char* t, const char* s );
146|char* StrX_cpyToCSymbol( char* dst, const char* src );
147|char* StrX_getCmdWord( char* t, const char* s );
148|char* StrX_cat( char* rcv, const char* add, int rcv_maxLen );
149|char* StrX_catR( const char* s1, char* s2, int s2_maxLen );
150|char* StrX_cpyWild( char* dst, const char* dst_wild, const char* src,
151| const char* src_wild );
152|char* StrX_ins( char* dst, const char* src );
153|char* StrX_setLast( char* s, char c );
154|
155|
156|/***********************************************************
157|* 14. <<< (StrX) char* 型の文字列(削除) >>>
158|************************************************************/
159|char* StrX_bs( char* );
160|char* StrX_bs2( char*, int n );
161|void StrX_del( char* s, int n );
162|char* StrX_trim( char* s );
163|char* StrX_trim2( char* s );
164|void StrX_cutHtmlTag( char* );
165|char* StrX_cutRet( char* s );
166|char* StrX_cutLastOf( char* s, char c );
167|char* StrX_cutLastOf2( char* s, char c );
168|char* StrX_cutLastOf_2byteFirst( char* s );
169|
170|
171|/***********************************************************
172|* 15. <<< (StrX) char* 型の文字列(検索・参照) >>>
173|************************************************************/
174|char StrX_getLast( const char* s );
175|char* StrX_strchrs( const char* s, const char* key );
176|char* StrX_strchr2( const char* s, int k );
177|char* StrX_strchrs2( const char* s, const char* key );
178|char* StrX_strchrs_not( const char* s, const char* key );
179|char* StrX_RSearchC( const char* s, char key );
180|char* StrX_RSearchC2( const char* s, int key );
181|char* StrX_RSearch( char* s, char* key );
182|char* StrX_stristr( const char* s, const char* key );
183|char* StrX_stristr3( const char* s, const char* key, bool bCase,
184| int* hitCount );
185|char* StrX_searchWord( const char* s, const char* k );
186|char* StrX_getWordTop( char* s, char* p, char term );
187|char* StrX_getCmdParam( const char* cmdline, char* param, int param_size );
188|char* StrX_getCSV( const char* s, int iColumn, char* out, int out_size );
189|int StrX_findInCSV( const char* s, const char* key, bool bCase );
190|int StrX_getCSVColumn( const char* s, const char* pos );
191|int StrX_getCSVNColumn( const char* s, bool bCountSpace );
192|char* StrX_getCIdent( const char* src, char* ident, int ident_sizeof );
193|char* StrX_getCIdent2( const char* src, char* ident, int ident_sizeof );
194|char* StrX_getToken( const char* src, char* token, int token_sizeof );
195|bool StrX_isTokenFirst( const char* s );
196|bool StrX_getCSSValueOfInt( const char* css, const char* attr_name,
197| int* pValue );
198|bool StrX_getCSSValueOfStr( const char* css, const char* attr_name,
199| char* str, int str_size );
200|#ifdef USES_COLOR
201|bool StrX_getCSSValueOfColor( const char* css, const char* attr_name,
202| Color_WinRGB* pColor );
203|#endif
204|int StrX_getSVGPoints( const char* points, int* xs, int* ys, int n );
205|char* StrX_getIdiom2( const char* src, int mWord, int* nWord,
206| char* idiom, int idiom_size );
207|char* StrX_getCppIdiom( const char* src, int mWord, int* nWord,
208| char* idiom, int idiom_size );
209|char** StrX_searchInArr( const char* s, char** arr, int arr_n );
210|char** StrX_searchInArr2( const char* s, const char** arr, int arr_size );
211|/*char** StrX_searchInArrX( const char* s, ArrX* arrx, type );*/
212|
213|
214|/***********************************************************
215|* 16. <<< (StrX) char* 型の文字列(置換・文字コード変換) >>>
216|************************************************************/
217|char* StrX_rep1( char* s, char f, char t );
218|char* StrX_rep1b( char* s, char f, char t );
219|char* StrX_rep( char* s, int s_sizeof, const char* f, const char* t );
220|char* StrX_repi( char* s, int s_sizeof, const char* f, int t );
221|char* StrX_repEx( char* s, int s_sizeof, const char* f, const char* t,
222| StrX_ConvFunc term_conv_func, void* obj, char* work, int work_size );
223|
224|#if !defined(_ismbblead) && !defined(_MBLEADTRAIL_DEFINED)
225|int _ismbblead( unsigned int c );
226|#define _MBLEADTRAIL_DEFINED
227|#endif
228|unsigned short StrX_mbc2sjis( char* str );
229|unsigned short StrX_sjis2jis( unsigned short code );
230|int StrX_getCodeT( const unsigned char* s );
231|char* StrX_toSJIS( char* out, const char* in );
232|int StrX_jis2sjis( unsigned char* out, const unsigned char* in,
233| bool* bSISO, bool* bKanji );
234|int StrX_euc2sjis( unsigned char* out, const unsigned char* in,
235| bool* bSISO );
236|int StrX_getJisIOType( const char* s );
237|void StrX_sjis2unicode( unsigned short* unicodeStr, const char* shiftJisStr,
238| int unicodeStr_size );
239|void StrX_unicode2sjis( unsigned char* shiftJisStr, const unsigned short* unicodeStr,
240| int shiftJisStr_size );
241|int StrX_getHash( const char* s, int width );
242|int StrX_getHashI( const char* s, int width );
243|char* StrX_toHtmlTxt( const char* src, char* dst, int dst_size );
244|void StrX_cpyLower( char* dst, const char* src );
245|void StrX_cpyUpper( char* dst, const char* src );
246|void StrX_getTableXY( const char* xy, int* x, int* y );
247|
248|
249|/***********************************************************
250|* 17. <<< (StrX) char* 型の文字列(判断・正規化) >>>
251|************************************************************/
252|int StrX_isSJis2byte( const char* char_top, const char* pChar );
253|int StrX_isExist2byte( const char* s );
254|bool StrX_isSpace( int c );
255|bool StrX_isSpcTabRet( int c );
256|bool StrX_isAlpha( int c );
257|bool StrX_isDigit( int c );
258|int StrX_isSpaceStr( const char* c );
259|int StrX_isTerm( char c );
260|bool StrX_isFName( const char* name );
261|int StrX_cmpHead( const char* str, const char* head );
262|int StrX_cmpWild( const char* wild, const char* str );
263|int StrX_cmpWildI( const char* wild, const char* str );
264|bool StrX_isMatchMask( const char* target, const char* wildcard );
265|
266|
267|/***********************************************************
268|* 18. <<< (StrX) char* 型の文字列(ファイル名、ファイルパス) >>>
269|************************************************************/
270|#if ( defined(_MSC_VER) || defined(__BORLANDC__) ) && !defined(FOR_WINCE)
271|char* StrX_getRunFullPath( char* absPath, const char* stepPath,
272| int absPath_len );
273|#endif
274|
275|char* StrX_getExeFullPath( char* absPath, const char* stepPath,
276| int absPath_len );
277|bool StrX_isAbsPath( const char* path );
278|bool StrX_isUrl( const char* url );
279|char* StrX_chgPathToUrl( char* url, const char* path );
280|char* StrX_toRegularPath( char* s );
281|char* StrX_toAbsPath( char* path, int path_maxlen, const char* base );
282|char* StrX_toAbsPath2( char* path, int path_maxlen, const char* base );
283|char* StrX_cpyAbsPath( char* absp, const char* stepp, int absp_maxlen, const char* base );
284|char* StrX_cpyAbsPath2( char* absp, const char* stepp, int absp_maxlen, const char* base );
285|char* StrX_cpyAbsPath2CSV( char* absp, const char* stepp, int absp_size,
286| const char* base );
287|char* StrX_toStepPath( char* path, int path_maxlen, const char* base );
288|char* StrX_toStepPath2( char* path, int path_maxlen, const char* file );
289|char* StrX_cpyStepPath( char* stepp, const char* absp, int stepp_maxlen, const char* base );
290|char* StrX_cpyStepPath2( char* stepp, const char* absp, int stepp_maxlen, const char* base );
291|char* StrX_cpyStepPath2CSV( char* stepp, const char* absp, int stepp_size,
292| const char* base );
293|
294|char* StrX_toStepURL( char* url, int url_maxlen, const char* base );
295|char* StrX_toAbsURL( char* url, int url_maxlen, const char* base );
296|
297|void StrX_movePath( const char* src,
298| const char* from_folder, const char* to_folder,
299| char* dst, int dst_size );
300|char* StrX_toLongPath( char* longPath, const char* shortPath );
301|#ifdef USES_FILEX
302| void StrX_getSpacedPath( const char* str, char* path, char** param );
303|#endif
304|char* StrX_refFName( const char* path );
305|char* StrX_cpyFName( char* fname, const char* path );
306|char* StrX_cpyFolder( char* fname, const char* path );
307|char* StrX_cutFName( char* path );
308|char* StrX_addFName( char* path, const char* fname );
309|char* StrX_insLastOfFName( char* path, char* ins );
310|char* StrX_cdFName( char* path, const char* cd );
311|char* StrX_refExt( const char* path );
312|char* StrX_chgExt( char* path, const char* ext );
313|int StrX_cmpNoExt( const char* path1, const char* path2 );
314|
315|char* StrX_cpyWithoutURLSubName( char* path, const char* url );
316|char* StrX_refURLSubName( const char* url );
317|
318|
319|/***********************************************************
320|* 19. <<< (StrX) char* 型の文字列(変換・n進数) >>>
321|************************************************************/
322|void StrX_initByInt16s( char* str, unsigned int n );
323|void StrX_initByInt16s_2( char* str, unsigned int n );
324|void StrX_initByInt( char* str, int str_len, int n );
325|char* StrX_scanInt( const char* str, int* n );
326|void StrX_initByLong16s( char* str, unsigned long n );
327|char* StrX_get2s_fromLong( char* s, unsigned long n, char term );
328|long StrX_getLong_from2s( char* s );
329|
330|#ifdef USES_COLOR
331|Color_WinRGB StrX_getColorValue( const char* color_str );
332|void StrX_getColorStr( char* color_str, Color_WinRGB value );
333|#endif
334|
335|void StrX_getFontValue( const char* font_str, char* face, int* size,
336| bool* bBold, bool* bItalic );
337|void StrX_getFontStr( char* font_str, const char* face, int size,
338| bool bBold, bool bItalic );
339|
340|
341|/***********************************************************
342|* 20. <<< [StrX_ListElem] リストの要素になる文字列 >>>
343|* 21. <<< [StrX_ListElem2] リストの要素になる文字列(補助番号付き) >>>
344|*【補足】
345|*・文字列 str をヒープにとっている場合、StrX_ListElem_finish2
346|* を呼び出す必要があります。
347|************************************************************/
348|#ifdef USES_LISTX
349|
350|struct _StrX_ListElem {
351| ListX_Elem inherit_ListX_Elem;
352| char* p;
353|};
354|void StrX_ListElem_finish2( StrX_ListElem* );
355|
356|struct _StrX_ListElem2 {
357| ListX_Elem inherit_ListX_Elem;
358| char* p;
359| void* data;
360|};
361|void StrX_ListElem2_finish2( StrX_ListElem2* );
362|
363|#ifdef USES_SYM
364|extern Sym_Struct* StrX_ListElem_registSymStruct( Sym* );
365|extern Sym_Struct StrX_ListElem_symStruct;
366|#endif
367|
368|#endif
369|
370|/**************************************************************************
371|* 22. <<< [StrX_Mem] 文字列の記憶領域 >>>
372|*【役割】
373|*・大量の文字列定数を扱う場合、最も効率よく詰めて格納するようにメモリを
374|* 割り振ります。
375|*・格納した文字列の長さを後で変えることはできません。
376|**************************************************************************/
377|struct _StrX_Mem {
378| char* buf; /* 記憶領域の先頭アドレス */
379| char* buf_over; /* 記憶領域の最終アドレスの次 */
380| char* pBuf; /* 認識している空き領域の先頭アドレス */
381| bool checked; /* pBuf が適当な位置にあるかチェックしたかどうか */
382|};
383|void StrX_Mem_init( StrX_Mem*, char* buf, size_t buf_sizeof );
384|void* StrX_Mem_getTopAdr( StrX_Mem* );
385|void StrX_Mem_toEmpty( StrX_Mem* );
386|char* StrX_Mem_alloc( StrX_Mem* );
387|char* StrX_Mem_alloc2( StrX_Mem*, const char* str );
388|char* StrX_Mem_alloc3( StrX_Mem*, const char* str );
389|char* StrX_Mem_copyAlloc( StrX_Mem*, const char* str );
390|void StrX_Mem_free( StrX_Mem*, const char* adr );
391|size_t StrX_Mem_getLeftSize( StrX_Mem* );
392|char* StrX_Mem_getFirst( StrX_Mem* );
393|char* StrX_Mem_getNext( StrX_Mem*, char* cur );
394|/* StrX_Mem_forEach( StrX_Mem*, char** ); */
395|
396|#ifndef ERRORS_CUT_DEBUG_TOOL
397|void StrX_Mem_print( StrX_Mem*, const char* title );
398|void StrX_Mem_printAll( StrX_Mem* );
399|#endif
400|
401|
402|
403|
404|/**************************************************************************
405|* 23. <<< [StrX_Set] 文字列の記憶領域の部分集合 >>>
406|*【役割】
407|*・StrX_Mem に格納した文字列の部分集合です。
408|*・1つの StrX_Mem 領域に対して、複数の集合を表現できます。
409|*・参照した文字列の長さを変えることはできません。
410|**************************************************************************/
411|#ifdef USES_STDLIBS
412|
413|struct _StrX_Set {
414| char* first; /* 最初の文字列の先頭アドレス */
415| char* last; /* 最後の次の文字列の先頭アドレス */
416|};
417|void StrX_Set_init1( StrX_Set*, StrX_Mem* );
418|void StrX_Set_init2( StrX_Set*, StrX_Mem* );
419|void StrX_Set_initEmpty( StrX_Set* );
420|/* StrX_Set_forEach( StrX_Set*, char** ); */
421|int StrX_Set_searchWild( StrX_Set*, const char* wildkey );
422|int StrX_Set_searchWild2( StrX_Set* wilds, const char* key );
423|
424|#ifndef ERRORS_CUT_DEBUG_TOOL
425|void StrX_Set_printAll( StrX_Set* );
426|#endif
427|
428|#endif /* USES_STDLIBS */
429|
430|
431|/**************************************************************************
432|* 24. <<< [StrX_MemV] 文字列の記憶領域(malloc 使用) >>>
433|*【補足】
434|*・malloc を使用するので、ヒープメモリ領域が許す限り無限に領域を確保する
435|* ことができます。
436|*・格納した文字列の長さを後で変えることはできません。
437|*・StrX_MemV_alloc で確保した領域は、char* 型か StrX_SetV 型で管理します。
438|**************************************************************************/
439|#ifdef STRX_USES_MALLOC
440|#ifdef USES_LISTX
441|
442|#define StrX_MemV_unitSize 2048 /* 増加する単位(バイト) */
443|#define StrX_MemV_maxLen 256 /* 一度に確保できる文字列領域(\0含む)サイズ */
444|
445|void StrX_MemV_init( StrX_MemV* );
446|void StrX_MemV_finish( StrX_MemV* );
447|void StrX_MemV_setMax( StrX_MemV*, int x );
448|char* StrX_MemV_alloc( StrX_MemV* );
449|
450|
451|struct _StrX_MemV {
452| ListX mems; /* StrX_MemVE 型リスト */
453| StrX_MemVE* mem_last;
454| int maxLen; /* →StrX_MemV_maxLen */
455|};
456|
457|struct _StrX_MemVE { /* リスト要素:StrX_Mem のリスト */
458| StrX_Mem mem;
459| ListX_Elem ListX_Elem_extend;
460|};
461|
462|#endif
463|#endif
464|
465|
466|/***********************************************************************
467|* 25. <<< [StrX_MemV2] 文字列の記憶領域(malloc & ハッシュ 使用) >>>
468|*【補足】
469|*・同じ内容の文字列は同じ領域を使うように検索を行う文字列領域管理です。
470|************************************************************************/
471|#if defined(USES_INF) && defined(USES_ARRX) && defined(USES_LISTX) && defined(USES_STDPLUS)
472|struct _StrX_MemV2 {
473| ListX_Dic dic;
474| Offset_Key key;
475| ListX symbols; /* StrX_MemV2E 型、→StrX_MemV2_setSymbol() */
476| ERRORS_INITCHK_VAR
477|};
478|
479|void StrX_MemV2_init( StrX_MemV2*, int width, StrX_HashFunc hash,
480| bool bCase );
481|void StrX_MemV2_finish( StrX_MemV2* );
482|void StrX_MemV2_toEmpty( StrX_MemV2* );
483|void StrX_MemV2_setSymbol( StrX_MemV2*, const char* setStr );
484|char* StrX_MemV2_alloc( StrX_MemV2*, const char* str );
485|int StrX_MemV2_getN( StrX_MemV2* );
486|void StrX_MemV2_print( StrX_MemV2*, const char* title );
487|
488|
489|/* 以下は内部用です */
490|struct _StrX_MemV2E {
491| ListX_Elem inherit_ListX_Elem;
492| char* p;
493|};
494|
495|void StrX_MemV2E_init( StrX_MemV2E*, const char* str );
496|void StrX_MemV2E_finish( StrX_MemV2E* );
497|
498|#endif
499|
500|/**************************************************************************
501|* 26. <<< [StrX_SetV] 文字列の記憶領域の部分集合(StrX_MemV用) >>>
502|*【役割】
503|*・StrX_MemV に格納した文字列の部分集合です。
504|*・1つの StrX_Mem 領域に対して、複数の集合を表現できます。
505|*・参照した文字列の長さを変えることはできません。
506|**************************************************************************/
507|#ifdef STRX_USES_MALLOC
508|#ifdef USES_LISTX
509|
510|struct _StrX_SetV {
511| char* first; /* 最初の文字列の先頭アドレス */
512| char* last; /* 最後の次の文字列の先頭アドレス */
513| StrX_MemVE* firstVE; /* first の StrX_MemVE 型リストの参照 */
514| StrX_MemVE* pVE; /* StrX_SetV_forEach 用ポインタ */
515|};
516|void StrX_SetV_init1( StrX_Set*, StrX_MemV* );
517|void StrX_SetV_init2( StrX_Set*, StrX_MemV* );
518|/* StrX_SetV_forEach( StrX_Set*, char** ); */
519|
520|#endif
521|#endif
522|
523|
524|/***********************************************************************
525|* 27. <<< [StrX_Pathes] 右クリック『送る』のファイルパス >>>
526|*【補足】
527|*・スペースによる区切りの短いファイル名をそれぞれ長いファイル名で参照します。
528|*・.exe ファイルにドラッグ&ドロップしたときも同じ AfxGetApp()->m_lpCmdLine
529|* からファイルパスを取得できます。
530|************************************************************************/
531|#ifdef USES_STDLIBS
532|struct _StrX_Pathes {
533| char* pathes; /* 先頭のファイルパス(短いファイル名の列挙) */
534| char* curPath; /* 現在のファイルパス(pathes の中へのアドレス) */
535| char longPath[_MAX_PATH]; /* 現在のファイルパス(長いファイル名) */
536|};
537|
538|void StrX_Pathes_init( StrX_Pathes*, const char* );
539|void StrX_Pathes_reset( StrX_Pathes* );
540|char* StrX_Pathes_getCurPath( StrX_Pathes* );
541|bool StrX_Pathes_next( StrX_Pathes* );
542|int StrX_Pathes_getN( StrX_Pathes* );
543|#endif
544|
545|/***********************************************************************
546|* 28. <<< [StrX_ConvFunc] 文字列を変換するコールバック関数の型 >>>
547|*【引数】
548|* ・void* obj; オブジェクト(任意アドレス)
549|* ・char* s; 変換する文字列のアドレス
550|* ・int s_size; s のメモリサイズ
551|*【補足】
552|*・定義は優先ヘッダにあります
553|*************************************************************************/
554|
555|/**************************************************************************
556| 29. <<< [STRX_DECLARE_ID_CONV_FUNC_START] 番号と文字列の変換関数の定義をする >>>
557| 30. <<< [STRX_DECLARE_ID_CONV_FUNC_END](同) >>>
558|【補足】
559|・IDS 型の enum を定義したとき、ヘッダファイルには、次のように記述します。
560| typedef enum { IDS_A, IDS_B, IDS_C, IDS_over } IDS;
561| char* IDS_getStr( IDS );
562| IDS IDS_getID( const char* str );
563|
564|・〜_over は、「非」正規の番号(番兵)です。名前は _over にする必要はありませんが、
565| 必ず定義してください。
566|
567|・ソースファイル(.c)には、次のように記述します。
568| //-------------------------------------------------------------
569| // [IDS_getStr, IDS_getID] IDS 型の番号と文字列を変換する
570| //【補足】
571| //・STRX_... マクロは、IDS_getStr, IDS_getID 関数を実装しています。
572| //-------------------------------------------------------------
573| STRX_DECLARE_ID_CONV_FUNC_START( IDS )
574| "String-A", "String-B", "String-C"
575| STRX_DECLARE_ID_CONV_FUNC_END( IDS, IDS_over, "NotFound" )
576|
577|・〜END の第2第3引数は、番兵の番号(兼 IDS_getID で見つからなかったときの番号)と、
578| IDS_getStr で見つからなかったときの文字列です。
579|***************************************************************************/
580|#define STRX_DECLARE_ID_CONV_FUNC_START( ID ) \
581| char* ID##_getStr( ID self ) \
582| { \
583| static char* s[] = {
584|
585|
586|#define STRX_DECLARE_ID_CONV_FUNC_END( ID, overID, overString ) \
587| }; \
588| if ( self < 0 || self >= overID ) return overString; \
589| else return s[self]; \
590| } \
591| \
592| ID ID##_getID( const char* str ) \
593| { \
594| int i; \
595| \
596| for ( i = 0; i < ID##_over; i++ ) { \
597| if ( strcmp( ID##_getStr( i ), str ) == 0 ) \
598| return i; \
599| } \
600| return overID; \
601| }
602|
603|
604|/*------------------------------------------------------------------------*/
605|/* 31. <<< Mapping Area ------------------------------------------------- >>> */
606|/*------------------------------------------------------------------------*/
607|
608|
609|/*-------------------------------------------------------------------------*/
610|/* ◆32. <<<< (StrX) char* 型の文字列 >>>> */
611|/*-------------------------------------------------------------------------*/
612|
613|/**************************************************************************
614| 32-1. <<< [_ismbblead] 1byte 文字コード c が、2 byte 文字コードの1 byte 目か判断する >>>
615| Microsoft #include <mbctype.h> と互換
616|***************************************************************************/
617|#ifndef _ismbblead
618|#ifndef _MSC_VER
619|#define _ismbblead( c ) \
620| ( ( (unsigned char)(c) >= 0x81 && (unsigned char)(c) <= 0x9F ) || \
621| ( (unsigned char)(c) >= 0xE0 && (unsigned char)(c) <= 0xFC ) )
622|#endif
623|#endif
624|
625|
626|/***********************************************************
627| 32-2. <<< [StrX_isMBBLeadNotTerm] 区切り文字以外の全角文字か判断する >>>
628|************************************************************/
629|#define StrX_isMBBLeadNotTerm( c ) \
630| (_ismbblead(c) && ((char)(c)) != (char)0x81)
631|
632|
633|
634|/**************************************************************************
635| 32-3. <<< [StrX_mbc2jsis] マルチバイト文字から Shift JIS コードを得る >>>
636| ・str : マルチバイト文字へのポインタ
637| ・返り値 : Shift JIS コードの値
638|***************************************************************************/
639|#define StrX_mbc2sjis( str ) \
640| ( *((unsigned char*)(str)+1) | (*(unsigned char*)(str)<<8) )
641|
642|
643|
644|/**************************************************************************
645| 32-4. <<< [StrX_isTokenFirst] 指定文字列の先頭がトークンの先頭かどうかを返す >>>
646|【引数】
647| ・char* s; トークンの先頭かどうかを調べる文字列
648| ・bool 返り値; 判定結果
649|【補足】
650|・トークンについては、StrX_getToken を参照。
651|**************************************************************************/
652|#define StrX_isTokenFirst( s ) \
653| ( (unsigned char)*(s) > ' ' )
654|
655|/**************************************************************************
656| 32-5. <<< [StrX_searchInArrX] 文字列配列の中から検索する >>>
657|【引数】
658| ・ArrX* arrx; 文字列配列(char* 型の配列)
659| ・char** 返り値; 見つかった文字列へのアドレス(arr 配列内), NULL=ない
660|***************************************************************************/
661|#define StrX_searchInArrX( s, arrx ) \
662| StrX_searchInArr( s, (char**)(arrx)->first, ArrX_getN( arrx, char* ) )
663|
664|
665|/**************************************************************************
666| 32-6. <<< [StrX_cmpHead] 頭文字列を比較する >>>
667|【機能】
668|・str のうち、先頭の n バイトが head と同じか比較する。
669| ただし、n は head のバイト数とする。
670|【引数】
671| ・char* str; 比較対象の文字列
672| ・char* head; 頭文字列
673| ・int 返り値; 標準関数の strncmp と同じ
674|***************************************************************************/
675|#define StrX_cmpHead( str, head ) \
676| strncmp( str, head, strlen(head) )
677|
678|
679|/**************************************************************************
680| 32-7. <<< [StrX_cpyAbsPath] StrX_toAbsPath のコピー版 >>>
681|***************************************************************************/
682|#define StrX_cpyAbsPath( absp, stepp, absp_maxlen, base ) \
683| ( strcpy( absp, stepp ), StrX_toAbsPath( absp, absp_maxlen, base ) )
684|
685|
686|/**************************************************************************
687| 32-8. <<< [StrX_cpyAbsPath2] StrX_toAbsPath2 のコピー版 >>>
688|***************************************************************************/
689|#define StrX_cpyAbsPath2( absp, stepp, absp_maxlen, base ) \
690| ( strcpy( absp, stepp ), StrX_toAbsPath2( absp, absp_maxlen, base ) )
691|
692|
693|/**************************************************************************
694| 32-9. <<< [StrX_cpyStepPath] StrX_toStepPath のコピー版 >>>
695|***************************************************************************/
696|#define StrX_cpyStepPath( stepp, absp, stepp_maxlen, base ) \
697| ( strcpy( stepp, absp ), StrX_toStepPath( stepp, stepp_maxlen, base ) )
698|
699|
700|/**************************************************************************
701| 32-10. <<< [StrX_cpyStepPath2] StrX_toStepPath2 のコピー版 >>>
702|***************************************************************************/
703|#define StrX_cpyStepPath2( stepp, absp, stepp_maxlen, base ) \
704| ( strcpy( stepp, absp ), StrX_toStepPath2( stepp, stepp_maxlen, base ) )
705|
706|
707|/*-------------------------------------------------------------------------*/
708|/* ◆33. <<<< (StrX_ListElem2) リストの要素になる文字列(補助番号付き) >>>> */
709|/*-------------------------------------------------------------------------*/
710|
711|/***********************************************************************
712| 33-1. <<< [StrX_ListElem2_finish2] リスト要素の文字列を後始末する >>>
713|************************************************************************/
714|#define StrX_ListElem2_finish2( this ) \
715| StrX_ListElem_finish2( (StrX_ListElem*)(this) )
716|
717|/*-------------------------------------------------------------------------*/
718|/* ◆34. <<<< (StrX_Mem) 文字列の記憶領域 >>>> */
719|/*-------------------------------------------------------------------------*/
720|
721|
722|/**************************************************************************
723| 34-1. <<< [StrX_Mem_getTopAdr] メモリ領域の先頭アドレスを取得する >>>
724|【引数】
725| ・StrX_Mem* this; 文字列の記憶領域
726| ・void* 返り値; メモリ領域の先頭アドレス
727|【補足】
728|・buf に malloc したアドレスを指定した場合、本関数で取得したアドレスを
729| free することを忘れないでください。
730|**************************************************************************/
731|#define StrX_Mem_getTopAdr( this ) \
732| ((void*)(this)->buf)
733|
734|
735|
736|/**************************************************************************
737| 34-2. <<< [StrX_Mem_getFirst] 最初の文字列を返す >>>
738|【引数】
739| ・StrX_Mem* this; 文字列の記憶領域
740| ・char** 返り値; 最初の文字列
741|**************************************************************************/
742|#define StrX_Mem_getFirst( this ) \
743| ( (this)->buf + 1 )
744|
745|/**************************************************************************
746| 34-3. <<< [StrX_Mem_forEach] 先頭から文字列を列挙しながらループする >>>
747|【引数】
748| ・char** pp; 要素文字列(char*ポインタ)を格納するアドレス
749| ・StrX_Mem* this; 文字列の記憶領域
750|【補足】
751|・for 文の中で使用します。
752| for ( StrX_Mem_forEach( &mem, &p ) );
753|***************************************************************************/
754|#if 0
755|
756|#define StrX_Mem_forEach( this, pp ) \
757| *(pp) = StrX_Mem_getNext( this, NULL ); \
758| *(pp) != NULL; *(pp) = StrX_Mem_getNext( this, *(pp) )
759|
760|#else
761|
762|#define StrX_Mem_forEach( this, pp ) \
763| *(pp) = ( (this)->pBuf == (this)->buf ? NULL : (this)->buf + 1 ); \
764| *(pp) != NULL; \
765| *(pp) = ( *(pp) >= (this)->pBuf ? NULL : strchr( *(pp), '\0' ) + 1 )
766|
767|#endif
768|
769|/*-------------------------------------------------------------------------*/
770|/* ◆35. <<<< (StrX_Set) 文字列の記憶領域の部分集合 >>>> */
771|/*-------------------------------------------------------------------------*/
772|
773|
774|/**************************************************************************
775| 35-1. <<< [StrX_Set_init1] 集合を定義する(step-1) >>>
776| 35-2. <<< [StrX_Set_init2] 集合を定義する(step-2) >>>
777|【補足】
778|・StrX_Set_init1 から StrX_Set_init2 の間に
779| mem に StrX_Mem_alloc した文字列の集合に初期化します。
780|・StrX_Set_init2 を呼び出す前に、集合の最後の要素に相当する
781| 文字列を格納しておいてください。
782|***************************************************************************/
783|#ifdef USES_STDLIBS
784|
785|#define StrX_Set_init1( this, mem ) \
786| ( (this)->first = strchr( (mem)->pBuf, '\0' ) + 1 )
787|
788|#define StrX_Set_init2( this, mem ) \
789| ( (this)->last = strchr( (mem)->pBuf, '\0' ) + 1 )
790|
791|#endif /* USES_STDLIBS */
792|
793|
794|/**************************************************************************
795| 35-3. <<< [StrX_Set_initEmpty] 空の集合に初期化する >>>
796|***************************************************************************/
797|#ifdef USES_STDLIBS
798|
799|#define StrX_Set_initEmpty( this ) \
800| ( (this)->first = NULL, (this)->last = NULL )
801|
802|#endif
803|
804|/**************************************************************************
805| 35-4. <<< [StrX_Set_forEach] 集合に含まれる文字列を列挙しながらループする >>>
806|【引数】
807| ・char** pp; 要素文字列(char*ポインタ)を格納するアドレス
808| ・StrX_Set* set; 文字列の記憶領域
809|【補足】
810|・for 文の中で使用します。
811| for ( StrX_Set_forEach( &set, &p ) );
812|***************************************************************************/
813|#ifdef USES_STDLIBS
814|
815|#define StrX_Set_forEach( set, pp ) \
816| *(pp) = (set)->first; \
817| *(pp) < (set)->last; \
818| *(pp) = strchr( *(pp), '\0' ) + 1
819|
820|#endif
821|
822|/*-------------------------------------------------------------------------*/
823|/* ◆36. <<<< (StrX_MemV) 文字列の記憶領域(malloc 使用) >>>> */
824|/*-------------------------------------------------------------------------*/
825|
826|
827|/***********************************************************************
828| 36-1. <<< [StrX_MemV_setMax] 一度に確保できる文字列領域のサイズを設定する >>>
829|【補足】
830|・StrX_MemV_alloc 関数で得られたアドレスから文字列を格納することが
831| できると保証する長さ('\0'文字含む)を設定します。
832|************************************************************************/
833|#ifdef USES_LISTX
834|
835|#define StrX_MemV_setMax( this, x ) \
836| (this)->maxLen = (x)
837|
838|#endif
839|
840|
841|/***********************************************************************
842| 36-2. <<< [StrX_MemV2_finish] 後始末する >>>
843|************************************************************************/
844|#define StrX_MemV2_finish( this ) \
845| ListX_Dic_finish( &(this)->dic, StrX_MemV2E, (Inf_FinishFunc)StrX_MemV2E_finish ), \
846| ListX_finish2( &(this)->symbols, StrX_MemV2E, NULL )
847|
848|/***********************************************************************
849| 36-3. <<< [StrX_MemV2_toEmpty] 領域をすべて開放する >>>
850|************************************************************************/
851|#define StrX_MemV2_toEmpty( this ) \
852| ListX_Dic_toEmpty( &(this)->dic, StrX_MemV2E, (Inf_FinishFunc)StrX_MemV2E_finish )
853|
854|/***********************************************************************
855| 36-4. <<< [StrX_MemV2_getN] 確保している文字列の要素数を返す >>>
856|************************************************************************/
857|#define StrX_MemV2_getN( this ) \
858| ListX_Dic_getN( &(this)->dic )
859|
860|/***********************************************************************
861| 36-5. <<< [StrX_MemV2E_init] 文字列領域をヒープから確保する >>>
862|************************************************************************/
863|#define StrX_MemV2E_init( this, str ) \
864| strcpy( (char*)( (this)->p = malloc( strlen( str ) + 1 ) ), str )
865|
866|
867|/*-------------------------------------------------------------------------*/
868|/* ◆37. <<<< (StrX_SetV) 文字列の記憶領域の部分集合(StrX_MemV用) >>>> */
869|/*-------------------------------------------------------------------------*/
870|
871|
872|/**************************************************************************
873| 37-1. <<< [StrX_SetV_init1] 集合を定義する(step-1) >>>
874| 37-2. <<< [StrX_SetV_init2] 集合を定義する(step-2) >>>
875|【補足】
876|・StrX_SetV_init1 から StrX_SetV_init2 の間に
877| mem に StrX_MemV_alloc した文字列の集合に初期化します。
878|・StrX_SetV_init2 を呼び出す前に、集合の最後の要素に相当する
879| 文字列を格納しておいてください。
880|***************************************************************************/
881|#ifdef USES_STDLIBS
882|#ifdef USES_LISTX
883|
884|#define StrX_SetV_init1( this, _mem ) \
885|( \
886| ( (this)->first = strchr( (_mem)->mem_last->mem.pBuf, '\0' ) + 1 ), \
887| (this)->firstVE = (_mem)->mem_last \
888|)
889|
890|#define StrX_SetV_init2( this, _mem ) \
891| ( (this)->last = strchr( (_mem)->mem_last->mem.pBuf, '\0' ) + 1 )
892|
893|
894|#endif
895|#endif /* USES_STDLIBS */
896|
897|
898|/**************************************************************************
899| 37-3. <<< [StrX_SetV_forEach] 集合に含まれる文字列を列挙しながらループする >>>
900|【引数】
901| ・char** pp; 要素文字列(char*ポインタ)を格納するアドレス
902| ・StrX_SetV* set; 文字列の記憶領域
903|【補足】
904|・for 文の中で使用します。
905| for ( StrX_SetV_forEach( &set, &p ) );
906|***************************************************************************/
907|#ifdef USES_STDLIBS
908|#ifdef USES_LISTX
909|
910|#define StrX_SetV_forEach( set, pp ) \
911| *(pp) = ((set)->first==(set)->last ? NULL : (set)->first), \
912| (set)->pVE = (set)->firstVE; \
913| *(pp) != NULL ; \
914| *(pp) = StrX_SetV_forEach_imp( set, *(pp) )
915|
916|/* 内部用 */
917|char* StrX_SetV_forEach_imp( StrX_SetV*, char* p );
918|
919|
920|#endif
921|#endif /* USES_STDLIBS */
922|
923|#ifdef __cplusplus
924|}
925|#endif
926|
927|#endif
928|
929|