4 #endif /* HAVE_CONFIG_H */
10 \95¶
\8e\9a\97ñ
\8aÖ
\8cW
12 BYTE g_byLeadByteTable[256];
13 BYTE g_byToLowerTable[256];
14 BYTE g_byToUpperTable[256];
16 static const char gcszEmpty[] = "";//
\8bó
\95¶
\8e\9a\97ñ
17 ///////////////////////////////////////////////////////////////////////////////
18 void __fastcall kbStr_Initialize(void)
19 {//
\83e
\81[
\83u
\83\8b\8f\89\8aú
\89»
20 //
\8eg
\97p
\91O
\82É
\82P
\93x
\82¾
\82¯
\8cÄ
\82Î
\82È
\82¯
\82ê
\82Î
\82È
\82ç
\82È
\82¢
21 static LONG uInit = -1; //
\8f\89\8aú
\89»
\8aJ
\8en
\8cã
\82Í 0
22 if (InterlockedIncrement(&uInit) == 0) {
23 char szLowerUpper[4] = {0};
25 for (i = 0; i < 256; i++) {
26 g_byLeadByteTable[i] = (BYTE) IsDBCSLeadByte((BYTE) i);
28 CharLower(szLowerUpper);
29 g_byToLowerTable[i] = szLowerUpper[0];
30 CharUpper(szLowerUpper);
31 g_byToUpperTable[i] = szLowerUpper[0];
35 InterlockedDecrement(&uInit);
38 ///////////////////////////////////////////////////////////////////////////////
39 int __fastcall kbStrLen(const char *cszString)
40 {//cszString
\82Ì
\92·
\82³
\82ð
\95Ô
\82·
41 //cszString
\82Ì
\8fI
\92[
\82ª
\93r
\92\86\82Å
\93r
\90Ø
\82ê
\82Ä
\82¢
\82é
\8fê
\8d\87\82Í
\81A
\97L
\8cø
\82È
\95\94\95ª
\82Ü
\82Å
\82Ì
\92·
\82³
\82ð
\95Ô
\82·
42 const char *s = cszString;
44 if (kbIsLeadByte(*s)) {
56 ///////////////////////////////////////////////////////////////////////////////
57 int __fastcall kbStrLCpy(char *szDest, const char *cszSrc, int nBufSize)
58 {// cszSrc
\82ð szDest
\82É nBufSize
\83o
\83C
\83g
\95ª
\83R
\83s
\81[
59 //
\95¶
\8e\9a\97ñ
\82Ì
\92·
\82³
\82ª
\91«
\82è
\82È
\82¢
\8fê
\8d\87\82Í nBufSize-1
\83o
\83C
\83g
\83R
\83s
\81[
\82µ
\82Ä
\8fI
\92[
\82É \0
\82ð
\95t
\89Á
60 //
\8fI
\92[
\95¶
\8e\9a\82ª
\93r
\90Ø
\82ê
\82Ä
\82¢
\82é
\82æ
\82¤
\82È
\8fê
\8d\87\82É
\82à
\91Î
\89\9e
61 // cszSrc
\82Ì
\97L
\8cø
\82È
\92·
\82³(kbStrLen(cszSrc))
\82ð
\95Ô
\82·
62 //
\96ß
\82è
\92l >= nBufSize
\82Ì
\8fê
\8d\87\81A
\95¶
\8e\9a\97ñ
\82ð
\90Ø
\82è
\8eÌ
\82Ä
\82½
\82±
\82Æ
\82ð
\88Ó
\96¡
\82·
\82é
65 if (kbIsLeadByte(*cszSrc)) {
71 *(WORD*) szDest = *(const WORD*) cszSrc;
76 else if (++p < nBufSize) {
77 *szDest++ = *cszSrc++;
88 ///////////////////////////////////////////////////////////////////////////////
89 int __fastcall kbStrLCat(char *szDest, const char *cszSrc, int nBufSize)
90 {// cszSrc
\82ð szDest
\82É
\98A
\8c\8b
91 // nBufSize
\82Í szDest
\82Ì
\83T
\83C
\83Y
\81i
\8fI
\92[
\82Ì '\0'
\82ð
\8aÜ
\82Þ
\81j
92 //
\8fI
\92[
\95¶
\8e\9a\82ª
\93r
\90Ø
\82ê
\82Ä
\82¢
\82é
\82æ
\82¤
\82È
\8fê
\8d\87\82É
\82à
\91Î
\89\9e
93 // kbStrLen(cszSrc) + min(kbStrLen(szDest), nBufSize)
\82ð
\95Ô
\82·
94 //
\96ß
\82è
\92l
\82ª >= nBufSize
\82Ì
\8fê
\8d\87\81A
\98A
\8c\8b\95¶
\8e\9a\97ñ
\82ð
\90Ø
\82è
\8eÌ
\82Ä
\82½
\82±
\82Æ
\82ð
\88Ó
\96¡
\82·
\82é
96 //min(kbStrLen(szDest) + nBufSize)
\82Æ
\83R
\83s
\81[
\90æ
\83o
\83b
\83t
\83@
\82Ö
\82Ì
\83|
\83C
\83\93\83^
\82ð
\93¾
\82é
98 while (*szDest && nDestLen < nBufSize) {
99 if (kbIsLeadByte(*szDest)) {
100 if (!*(szDest+1) || nDestLen >= nBufSize-2) {
113 return kbStrLCpy(szDest, cszSrc, nBufSize - nDestLen) + nDestLen;
115 ///////////////////////////////////////////////////////////////////////////////
116 //static const WORD wWSpace = 0x4081;//
\91S
\8ap
\83X
\83y
\81[
\83X
117 char* __fastcall kbStrTrimRight(char* szString)
118 {//
\95¶
\8e\9a\97ñlpszString
\82Ì
\8fI
\92[
\82©
\82ç
\8bó
\94\92\95¶
\8e\9a\82ð
\8eæ
\82è
\8f\9c\82
119 register char *p = szString;
123 if (kbIsLeadByte(*p)) {//
\91S
\8ap
124 /*if (*(WORD*) p == wWSpace) {
125 //
\91S
\8ap
\83X
\83y
\81[
\83X
\82ª
\8c©
\82Â
\82©
\82Á
\82½
131 Space = NULL;//
\8bó
\94\92\88È
\8aO
\82ª
\8c©
\82Â
\82©
\82Á
\82½
133 else {//
\95¶
\8e\9a\97ñ
\82ª
\93r
\92\86\82Å
\93r
\90Ø
\82ê
\82Ä
\82µ
\82Ü
\82Á
\82Ä
\82¢
\82é
\81H
134 *p = 0;//
\91S
\8ap
\82P
\83o
\83C
\83g
\96Ú
\82Ì
\95\94\95ª
\82Í
\90Ø
\82è
\8eÌ
\82Ä
\82é
141 //
\94¼
\8ap
\83X
\83y
\81[
\83X
147 Space = NULL;//
\8bó
\94\92\88È
\8aO
\82ª
\8c©
\82Â
\82©
\82Á
\82½
158 ///////////////////////////////////////////////////////////////////////////////
159 char* __fastcall kbStrTrimLeft(char* szString)
160 {//
\95¶
\8e\9a\97ñlpszString
\82Ì
\90æ
\93ª
\82©
\82ç
\8bó
\94\92\95¶
\8e\9a\82ð
\8eæ
\82è
\8f\9c\82
161 register char *src = szString;
164 if (*src == ' ') {//
\94¼
\8ap
\83X
\83y
\81[
\83X
168 if (src != szString) {
169 register char *dst = szString;
178 *szString = 0;//
\82·
\82×
\82Ä
\8bó
\94\92
182 ///////////////////////////////////////////////////////////////////////////////
183 char* __fastcall kbStrTrim(char *szString)
184 {//
\95¶
\8e\9a\97ñlpszString
\82Ì
\90æ
\93ª
\82Æ
\8fI
\92[
\82©
\82ç
\8bó
\94\92\95¶
\8e\9a\82ð
\8eæ
\82è
\8f\9c\82
185 return kbStrTrimLeft(kbStrTrimRight(szString));
187 ///////////////////////////////////////////////////////////////////////////////
188 char* __fastcall kbCRLFtoSpace(char *szString)
189 {//
\89ü
\8ds
\81E
\95\9c\8bA
\95¶
\8e\9a\82Æ
\83^
\83u
\95¶
\8e\9a\82ð
\94¼
\8ap
\83X
\83y
\81[
\83X
\82É
\95Ï
\8a·
\82·
\82é
190 register char* p = szString;
193 if (kbIsLeadByte(*p)) {//
\91S
\8ap
194 if (!p[1]) {//
\95¶
\8e\9a\97ñ
\82ª
\93r
\92\86\82Å
\93r
\90Ø
\82ê
\82Ä
\82¢
\82é
201 if (*p == '\n' || *p == '\r' || *p == '\t') {
210 ///////////////////////////////////////////////////////////////////////////////
211 int __fastcall kbStrCmp(const char *cszStr1, const char *cszStr2)
217 if (kbIsLeadByte(*cszStr1)) {
218 if (kbIsLeadByte(*cszStr2)) {
219 int cmp = *(WORD*) cszStr1 - *(WORD*) cszStr2;
220 if (cmp == 0 && cszStr1[1]) {
225 if (*cszStr1 == *cszStr2) {
226 return (BYTE) cszStr1[1] - (BYTE) cszStr2[1];
228 return (BYTE) cszStr1[0] - (BYTE) cszStr2[0];
236 if (kbIsLeadByte(*cszStr2)) {
239 int cmp = (BYTE)(*cszStr1) - (BYTE)(*cszStr2);
247 return (BYTE) *cszStr1 - (BYTE) *cszStr2;
249 ///////////////////////////////////////////////////////////////////////////////
250 //#define KBSTRCMPI_DEBUG
251 #ifdef KBSTRCMPI_DEBUG
252 static int __fastcall kbStrCmpI_(const char *cszStr1, const char *cszStr2);
253 int __fastcall kbStrCmpI(const char *cszStr1, const char *cszStr2)
256 int ret1 = kbStrCmpI_(cszStr1, cszStr2);
257 int ret2 = strcmpi(cszStr1, cszStr2);
266 if (!ret1 || !ret2) {
267 //
\92v
\96½
\93I
\83G
\83\89\81[
273 ///////////////////////////////////////////////////////////////////////////////
274 static int __fastcall kbStrCmpI_(const char *cszStr1, const char *cszStr2)
276 int __fastcall kbStrCmpI(const char *cszStr1, const char *cszStr2)
283 if (kbIsLeadByte(*cszStr1)) {
284 if (kbIsLeadByte(*cszStr2)) {
285 int cmp = *(WORD*) cszStr1 - *(WORD*) cszStr2;
286 if (cmp == 0 && cszStr1[1]) {
291 if (*cszStr1 == *cszStr2) {
292 return (BYTE) cszStr1[1] - (BYTE) cszStr2[1];
294 return (BYTE) cszStr1[0] - (BYTE) cszStr2[0];
302 if (kbIsLeadByte(*cszStr2)) {
305 int cmp = kbToLower(*cszStr1) - kbToLower(*cszStr2);
306 //int cmp = tolower(*cszStr1) - tolower(*cszStr2);
314 return (BYTE) *cszStr1 - (BYTE) *cszStr2;
316 ///////////////////////////////////////////////////////////////////////////////
317 int __fastcall kbStrNCmp(const char *cszStr1, const char *cszStr2, int nLen)
319 while (nLen > 0 && *cszStr1) {
323 if (kbIsLeadByte(*cszStr1)) {
324 if (kbIsLeadByte(*cszStr2)) {
325 int cmp = *(WORD*) cszStr1 - *(WORD*) cszStr2;
326 if (cmp == 0 && cszStr1[1]) {
332 if (*cszStr1 == *cszStr2) {
333 return (BYTE) cszStr1[1] - (BYTE) cszStr2[1];
335 return (BYTE) cszStr1[0] - (BYTE) cszStr2[0];
343 if (kbIsLeadByte(*cszStr2)) {
346 int cmp = (BYTE)(*cszStr1) - (BYTE)(*cszStr2);
347 //int cmp = tolower(*cszStr1) - tolower(*cszStr2);
357 return (BYTE) *cszStr1 - (BYTE) *cszStr2;
363 ///////////////////////////////////////////////////////////////////////////////
364 int __fastcall kbStrNCmpI(const char *cszStr1, const char *cszStr2, int nLen)
366 while (nLen > 0 && *cszStr1) {
370 if (kbIsLeadByte(*cszStr1)) {
371 if (kbIsLeadByte(*cszStr2)) {
372 int cmp = *(WORD*) cszStr1 - *(WORD*) cszStr2;
373 if (cmp == 0 && cszStr1[1]) {
379 if (*cszStr1 == *cszStr2) {
380 return (BYTE) cszStr1[1] - (BYTE) cszStr2[1];
382 return (BYTE) cszStr1[0] - (BYTE) cszStr2[0];
390 if (kbIsLeadByte(*cszStr2)) {
393 int cmp = kbToLower(*cszStr1) - kbToLower(*cszStr2);
394 //int cmp = tolower(*cszStr1) - tolower(*cszStr2);
404 return (BYTE) *cszStr1 - (BYTE) *cszStr2;
410 ///////////////////////////////////////////////////////////////////////////////
411 const char* __fastcall kbStrChr(const char *cszString, char cFind)
412 {//
\95¶
\8e\9a\97ñ cszString
\82©
\82ç
\95¶
\8e\9a cFind
\82ð
\8c\9f\8dõ
\82µ
\81A
\8dÅ
\8f\89\82É
\8c©
\82Â
\82©
\82Á
\82½
\95¶
\8e\9a\82Ö
\82Ì
\83|
\83C
\83\93\83^
\82ð
\95Ô
\82·
413 //
\8c©
\82Â
\82©
\82ç
\82È
\82¢
\8fê
\8d\87\82Í NULL
\82ð
\95Ô
\82·
414 //cFind
\82Í '\0'
\82à
\97L
\8cø
415 //cFind == '\0'
\82Å
\95¶
\8e\9a\97ñ
\82ª
\93r
\90Ø
\82ê
\82Ä
\82¢
\82é
\82Æ
\82«
\81A
\93r
\90Ø
\82ê
\82½
\8dÅ
\8f\89\82Ì
\95¶
\8e\9a\82Ö
\82Ì
\83|
\83C
\83\93\83^
\82ð
\95Ô
\82·
416 if (!cszString) return NULL;
418 if ((BYTE) *cszString == (BYTE) cFind) {
421 else if (kbIsLeadByte((BYTE) *cszString)) {
425 else if (cFind) {//
\95¶
\8e\9a\97ñ
\82ª
\93r
\90Ø
\82ê
\82Ä
\82¢
\82é
428 else {//
\93r
\90Ø
\82ê
\82½
\8dÅ
\8f\89\82Ì
\95¶
\8e\9a\82Ö
\82Ì
\83|
\83C
\83\93\83^
432 else if (*cszString) {
440 ///////////////////////////////////////////////////////////////////////////////
441 const char* __fastcall kbStrRChr(const char *cszString, char cFind)
442 {//
\95¶
\8e\9a\97ñ cszString
\82©
\82ç
\95¶
\8e\9a cFind
\82ð
\8c\9f\8dõ
\82µ
\81A
\8dÅ
\8cã
\82É
\8c©
\82Â
\82©
\82Á
\82½
\95¶
\8e\9a\82Ö
\82Ì
\83|
\83C
\83\93\83^
\82ð
\95Ô
\82·
443 //
\8c©
\82Â
\82©
\82ç
\82È
\82¢
\8fê
\8d\87\82Í NULL
\82ð
\95Ô
\82·
444 //cFind
\82Í '\0'
\82à
\97L
\8cø
445 //cFind == '\0'
\82Å
\95¶
\8e\9a\97ñ
\82ª
\93r
\90Ø
\82ê
\82Ä
\82¢
\82é
\82Æ
\82«
\81A
\93r
\90Ø
\82ê
\82½
\8dÅ
\8f\89\82Ì
\95¶
\8e\9a\82Ö
\82Ì
\83|
\83C
\83\93\83^
\82ð
\95Ô
\82·
446 if (!cszString) return NULL;
447 const char *cszRet = NULL;
449 if ((BYTE) *cszString == (BYTE) cFind) {
452 else if (kbIsLeadByte((BYTE) *cszString)) {
457 else if (cFind) {//
\95¶
\8e\9a\97ñ
\82ª
\93r
\90Ø
\82ê
\82Ä
\82¢
\82é
460 else {//
\93r
\90Ø
\82ê
\82½
\8dÅ
\8f\89\82Ì
\95¶
\8e\9a\82Ö
\82Ì
\83|
\83C
\83\93\83^
473 ///////////////////////////////////////////////////////////////////////////////
474 const char* __fastcall kbStrStr(const char *cszString, const char *cszSearch)
478 if (*cszString == *cszSearch) {
479 if (nSearchLen < 0) {
480 nSearchLen = kbStrLen(cszSearch);
482 //if (strncmp(cszString, cszSearch, nSearchLen) == 0) {
483 if (kbStrNCmp(cszString, cszSearch, nSearchLen) == 0) {
487 if (kbIsLeadByte(*cszString)) {
499 ///////////////////////////////////////////////////////////////////////////////
500 const char* __fastcall kbStrStrI(const char *cszString, const char *cszSearch)
502 int nSearchLen = kbStrLen(cszSearch);
504 //if (strnicmp(cszString, cszSearch, nSearchLen) == 0) {
507 if (kbStrNCmpI(cszString, cszSearch, nSearchLen) == 0) {
510 if (kbIsLeadByte(*cszString)) {
522 ///////////////////////////////////////////////////////////////////////////////
523 char* __fastcall kbStrUpr(char *pszString)
532 ///////////////////////////////////////////////////////////////////////////////
533 char* __fastcall kbStrLwr(char *pszString)
542 ///////////////////////////////////////////////////////////////////////////////
543 char* __fastcall kbStrTok(char *pszString, const char *cszDelimiter, char **ppszNext)
549 if (kbIsLeadByte(*p)) {
550 if (!p[1]) {//
\95¶
\8e\9a\97ñ
\82ª
\93r
\90Ø
\82ê
\82Ä
\82¢
\82é
557 const char *delim = cszDelimiter;
559 if (*p == *delim++) {
573 ///////////////////////////////////////////////////////////////////////////////
575 static inline bool __fastcall is_digit(char c)
577 return ('0' <= c && c <= '9');
579 int __fastcall kbStrToIntDef(const char* p, int nDefault)
580 {//
\95¶
\8e\9a\97ñ
\82ð
\90®
\90\94\82É
\95Ï
\8a·
\82Å
\82«
\82½
\8fê
\8d\87\82Í
\82»
\82Ì
\92l
\82ð
\95Ô
\82·
581 //
\95Ï
\8a·
\82Å
\82«
\82È
\82¢
\8fê
\8d\87\82Í nDefault
\82ð
\95Ô
\82·
582 int nSign = 1;//
\95\84\8d\86
583 //
\8bó
\94\92\82ð
\82Æ
\82Î
\82·
598 //
\90®
\90\94\95\94\95ª
599 int nReturn = (*p++ - '0');
600 while (is_digit(*p)) {
602 nReturn += (*p++ - '0');
604 //
\8f¬
\90\94\95\94\95ª
606 while (is_digit(*++p));//
\8f¬
\90\94\95\94\95ª
\82Í
\82·
\82×
\82Ä
\96³
\8e\8b
608 //
\90\94\92l
\82Ì
\95\94\95ª
\88È
\8d~
\82É
\8bó
\94\92\88È
\8aO
\82Ì
\95¶
\8e\9a\82ª
\8c©
\82Â
\82©
\82Á
\82½
\8fê
\8d\87\82Í nDefault
\82ð
\95Ô
\82·
613 return nSign*nReturn;
618 double __fastcall kbStrToDoubleDef(const char* p, double nDefault)
619 {//
\95¶
\8e\9a\97ñ
\82ð
\8f¬
\90\94\82É
\95Ï
\8a·
\82Å
\82«
\82½
\8fê
\8d\87\82Í
\82»
\82Ì
\92l
\82ð
\95Ô
\82·
620 //
\95Ï
\8a·
\82Å
\82«
\82È
\82¢
\8fê
\8d\87\82Í nDefault
\82ð
\95Ô
\82·
621 int nSign = 1;//
\95\84\8d\86
622 //
\8bó
\94\92\82ð
\82Æ
\82Î
\82·
637 //
\90®
\90\94\95\94\95ª
638 double nReturn = (*p++ - '0');
639 while (is_digit(*p)) {
641 nReturn += (*p++ - '0');
643 //
\8f¬
\90\94\95\94\95ª
647 while (is_digit(*p)) {
649 nReturn += (double)(*p++ - '0') / multi;
652 //
\90\94\92l
\82Ì
\95\94\95ª
\88È
\8d~
\82É
\8bó
\94\92\88È
\8aO
\82Ì
\95¶
\8e\9a\82ª
\8c©
\82Â
\82©
\82Á
\82½
\8fê
\8d\87\82Í nDefault
\82ð
\95Ô
\82·
657 return nSign*nReturn;
663 int __fastcall kbStrToIntDef(const char* cszStr, int nDefault)
664 {//cszStr
\82ð
\90®
\90\94\82É
\95Ï
\8a·
\82·
\82é
665 //
\95Ï
\8a·
\82Å
\82«
\82È
\82¢
\8fê
\8d\87\82Í nDefault
\82ð
\95Ô
\82·
669 const int cMaxLen = 1024;
670 const int len = kbStrLen(cszStr) + 1;
672 return nDefault;//
\95¶
\8e\9a\97ñ
\82ª
\92·
\82·
\82¬
\82é
674 char szCopy[cMaxLen];
675 memcpy(szCopy, cszStr, len);
679 char *szEndStr = NULL;
680 ret = strtol(szCopy, &szEndStr, 10);
681 if (szEndStr && szEndStr[0]) {
690 double __fastcall kbStrToDoubleDef(const char* cszStr, double nDefault)
691 {//cszStr
\82ð
\8f¬
\90\94\82É
\95Ï
\8a·
\82·
\82é
692 //
\95Ï
\8a·
\82Å
\82«
\82È
\82¢
\8fê
\8d\87\82Í nDefault
\82ð
\95Ô
\82·
696 const int cMaxLen = 1024;
697 const int len = kbStrLen(cszStr) + 1;
699 return nDefault;//
\95¶
\8e\9a\97ñ
\82ª
\92·
\82·
\82¬
\82é
701 char szCopy[cMaxLen];
702 memcpy(szCopy, cszStr, len);
706 char *szEndStr = NULL;
707 ret = strtof(szCopy, &szEndStr, 10);
708 if (szEndStr && szEndStr[0]) {
718 ///////////////////////////////////////////////////////////////////////////////
719 int __fastcall kbStringReplace(char *dst,
722 const char *old_pattern,
723 const char *new_pattern)
724 {//
\95¶
\8e\9a\97ñ src
\82Ì old_pattern
\82ð new_pattern
\82É
\92u
\8a·
\82·
\82é
725 //size
\82Í dst
\82Ì
\83o
\83b
\83t
\83@
\83T
\83C
\83Y
726 //old_pattern == ""
\81i
\8bó
\95¶
\8e\9a\97ñ
\81j
\82Ì
\8fê
\8d\87\81AkbStrLCat(dst, size, new_pattern)
\82Æ
\93¯
\82¶
727 //
\83o
\83b
\83t
\83@
\83T
\83C
\83Y
\82ª
\91«
\82è
\82È
\82¢
\8fê
\8d\87\82Í
\81Asize-1
\83o
\83C
\83g
\82Ü
\82Å
\92u
\8a·
\82·
\82é
728 //
\8a®
\91S
\92u
\8a·
\82³
\82ê
\82½
\82Æ
\82µ
\82½
\82Æ
\82«
\82Ì
\95¶
\8e\9a\97ñ
\82Ì
\92·
\82³
\82ð
\95Ô
\82·
729 //
\96ß
\82è
\92l >= size
\82Ì
\8fê
\8d\87\81A
\92u
\8a·
\8cã
\82Ì
\95¶
\8e\9a\97ñ
\82ª
\88ê
\95\94\90Ø
\82è
\8eÌ
\82Ä
\82ç
\82ê
\82½
\82±
\82Æ
\82ð
\88Ó
\96¡
\82·
\82é
731 const int old_pattern_len = kbStrLen(old_pattern);
734 *src == *old_pattern &&
735 kbStrNCmp(src, old_pattern, old_pattern_len) == 0) {
736 const int new_pattern_len = kbStrLCpy(dst, new_pattern, size - ret);
737 if (new_pattern_len < size - ret) {
738 dst += new_pattern_len;
743 ret += new_pattern_len;
747 src += old_pattern_len;
750 if (kbIsLeadByte(*src)) {
754 *((WORD*) dst) = *((WORD*) src);
780 ///////////////////////////////////////////////////////////////////////////////
781 int __fastcall kbMultiByteToWideChar(const char *cszMultiByte,
782 wchar_t* wszWideChar,
784 {//cchWideChar == 0
\82Ì
\82Æ
\82«
\82Í
\95K
\97v
\82È
\83o
\83b
\83t
\83@
\82Ì
\83T
\83C
\83Y(
\95¶
\8e\9a\90\94\92P
\88Ê)
\82ð
\95Ô
\82·
785 int ret = MultiByteToWideChar(CP_ACP, 0, cszMultiByte, -1,
786 wszWideChar, cchWideChar);
787 //
\83o
\83b
\83t
\83@
\83T
\83C
\83Y
\82ª
\91«
\82è
\82È
\82¢
\8fê
\8d\87\81AwszWideChar
\82Ì
\8fI
\92[
\95¶
\8e\9a\82Í \0
\82É
\82È
\82ç
\82È
\82¢
789 wszWideChar[cchWideChar-1] = 0;//
\8fI
\92[
\82ð \0
\82É
\82·
\82é
793 ///////////////////////////////////////////////////////////////////////////////
794 int __fastcall kbWideCharToMultiByte(const wchar_t *wcszWideChar,
797 {//cchMultiByte
\82ª 0
\82Ì
\82Æ
\82«
\82Í
\95K
\97v
\82È
\83o
\83b
\83t
\83@
\82Ì
\83T
\83C
\83Y
\82ð
\95Ô
\82·
798 int ret = WideCharToMultiByte(CP_ACP, 0, wcszWideChar, -1,
799 szMultiByte, cchMultiByte, NULL, NULL);
800 //
\83o
\83b
\83t
\83@
\83T
\83C
\83Y
\82ª
\91«
\82è
\82È
\82¢
\8fê
\8d\87\81AszMultiByte
\82Ì
\8fI
\92[
\95¶
\8e\9a\82Í \0
\82É
\82È
\82ç
\82È
\82¢
802 szMultiByte[cchMultiByte-1] = 0;//
\8fI
\92[
\82ð \0
\82É
\82·
\82é
803 if (ret == 0) {//
\83T
\83C
\83Y
\82ª
\91«
\82è
\82È
\82¢(
\81ª
\82Å
\8fI
\92[
\95¶
\8e\9a\82ª
\83}
\83\8b\83`
\83o
\83C
\83g
\82Ì2
\83o
\83C
\83g
\96Ú
\82¾
\82Á
\82½
\8fê
\8d\87\82É
\91Î
\8f\88\81j
804 int nLen = kbStrLen(szMultiByte);//
\95¶
\8e\9a\97ñ
\82ª
\93r
\90Ø
\82ê
\82Ä
\82é
\8fê
\8d\87\82Í
\97L
\8cø
\82È
\95\94\95ª
\82Ü
\82Å
\82Ì
\92·
\82³
\82ð
\95Ô
\82·
805 szMultiByte[nLen] = 0; //
\93r
\90Ø
\82ê
\82Ä
\82é
\8fê
\8d\87\82Í
\93r
\90Ø
\82ê
\82½
\95\94\95ª
\82ª
\8f\9c\8b\8e\82³
\82ê
\82é
810 ///////////////////////////////////////////////////////////////////////////////
812 //
\83t
\83@
\83C
\83\8b\96¼
\8aÖ
\8cW
814 ///////////////////////////////////////////////////////////////////////////////
815 const char* __fastcall kbExtractFileExt(const char* cszSrc)
816 {//cszSrc
\93à
\82Ì
\8ag
\92£
\8eq
\95\94\95ª
\82Ì
\83|
\83C
\83\93\83^
\82ð
\95Ô
\82·
817 //
\8c©
\82Â
\82©
\82ç
\82È
\82¢
\8fê
\8d\87\82Í
\8bó
\95¶
\8e\9a\97ñ
\82ð
\95Ô
\82·
\81iNULL
\82Å
\82Í
\82È
\82¢
\81j
818 if (!cszSrc) return gcszEmpty;
819 const BYTE* LastPeriod = NULL;
820 const BYTE* LastPathDelimiter = NULL;
822 if (kbIsLeadByte((*((const BYTE*) cszSrc)))) {
827 else {//
\95¶
\8e\9a\97ñ
\82ª
\93r
\92\86\82Å
\93r
\90Ø
\82ê
\82Ä
\82¢
\82é
831 if ((BYTE) *cszSrc == (BYTE)'.') {
832 LastPeriod = (BYTE*) cszSrc;
834 else if ((BYTE) *cszSrc == (BYTE)'\\') {
835 LastPathDelimiter = (BYTE*) cszSrc;
839 if (LastPeriod && (DWORD) LastPeriod > (DWORD) LastPathDelimiter) {
840 //
\83s
\83\8a\83I
\83h
\82ª
\8c©
\82Â
\82©
\82Á
\82Ä
\82à
\81A
\8ag
\92£
\8eq
\82Æ
\82Í
\8cÀ
\82ç
\82È
\82¢
841 //
\97á
\81FC:\\hoge.hoge\\hogehoge
842 return (const char*) LastPeriod;
846 ///////////////////////////////////////////////////////////////////////////////
847 const char* __fastcall kbExtractFileName(const char* cszFileName)
848 {//cszFileName
\82©
\82ç
\83p
\83X
\82ð
\8eæ
\82è
\8f\9c\82¢
\82½
\82à
\82Ì
\81i
\83t
\83@
\83C
\83\8b\96¼
\95\94\95ª
\81j
\82Ì
\83|
\83C
\83\93\83^
\82ð
\95Ô
\82·
849 const char *cszLastDelimiter = kbStrRChr(cszFileName, '\\');
850 if (cszLastDelimiter) {
851 return cszLastDelimiter + 1;
853 if (cszFileName) return cszFileName;
856 ///////////////////////////////////////////////////////////////////////////////
857 char* __fastcall kbExtractFilePath(char *szDest, const char *cszFileName, int nSize)
858 {//cszFileName
\82©
\82ç
\83p
\83X
\82ð
\8eæ
\93¾
\82µ
\82Ä
\83|
\83C
\83\93\83^
\82ð
\95Ô
\82·
859 //szDest == cszFileName
\82Å
\82 \82Á
\82Ä
\82Í
\82È
\82ç
\82È
\82¢
861 const char *cszLastPathDelimiter = kbStrRChr(cszFileName, '\\');
862 if (cszLastPathDelimiter) {
863 int nLen = cszLastPathDelimiter - cszFileName + 1;
865 memcpy(szDest, cszFileName, nLen);
871 ///////////////////////////////////////////////////////////////////////////////
872 const char* __fastcall kbExtractFileNameInArc(const char *cszFileName)
873 {//
\8f\91\8cÉ
\83t
\83@
\83C
\83\8b\93à
\82Ì
\83t
\83@
\83C
\83\8b\96¼
\82©
\82ç
\83p
\83X
\82ð
\8eæ
\82è
\8f\9c\82¢
\82½
\82à
\82Ì
\82ð
\95Ô
\82·
874 //
\97á
\82P
\81FC:\hoge\hoge.lzh>test.mid
\82Ì
\96ß
\82è
\92l = test.mid
875 //
\97á
\82Q
\81FC:\hoge\hoge.lzh>test/test2.mid
\82Ì
\96ß
\82è
\92l
\81\81test2.mid
876 //
\97á
\82R
\81FC:\hoge\hoge.lzh>test/testzip.zip>test3.mid
\82Ì
\96ß
\82è
\92l = test3.mid
877 //
\97á
\82S
\81FC:\hoge\hoge.lzh>test/testzip.zip>test/test4.mid
\82Ì
\96ß
\82è
\92l = test4.mid
878 if (!cszFileName) return gcszEmpty;
879 const char *cszDelimiter = kbStrRChr(cszFileName, '>');
881 cszFileName = cszDelimiter + 1;
883 cszDelimiter = kbStrRChr(cszFileName, '/');
885 return cszDelimiter + 1;
889 ///////////////////////////////////////////////////////////////////////////////
890 const char* __fastcall kbExtractFilePathInArc(char *szDest, const char *cszFileName)
891 {//
\8f\91\8cÉ
\83t
\83@
\83C
\83\8b\93à
\82Ì
\83t
\83@
\83C
\83\8b\96¼
\82©
\82ç
\83t
\83@
\83C
\83\8b\96¼
\82ð
\8eæ
\82è
\8f\9c\82¢
\82½
\82à
\82Ì
\82ð
\95Ô
\82·
892 //
\97á
\82P
\81FC:\hoge\hoge.lzh>test.mid
\82Ì
\96ß
\82è
\92l = C:\hoge\hoge.lzh>
893 //
\97á
\82Q
\81FC:\hoge\hoge.lzh>test/test2.mid
\82Ì
\96ß
\82è
\92l = C:\hoge\hoge.lzh>test/
894 //
\97á
\82R
\81FC:\hoge\hoge.lzh>test/testzip.zip>test3.mid
\82Ì
\96ß
\82è
\92l = C:\hoge\hoge.lzh>test/testzip.zip>
895 //
\97á
\82S
\81FC:\hoge\hoge.lzh>test/testzip.zip>test/test4.mid
\82Ì
\96ß
\82è
\92l = C:\hoge\hoge.lzh>test/testzip.zip>test/
896 if (!szDest) return NULL;
898 if (!cszFileName) return szDest;
899 const char *cszFirst = cszFileName;
900 const char *cszDelimiter = kbStrRChr(cszFileName, '>');
902 cszFileName = cszDelimiter + 1;
904 cszDelimiter = kbStrRChr(cszFileName, '/');
906 cszFileName = cszDelimiter + 1;
908 int nCopySize = cszFileName - cszFirst;
910 memcpy(szDest, cszFirst, nCopySize);
911 szDest[nCopySize] = 0;
915 ///////////////////////////////////////////////////////////////////////////////
916 char* __fastcall kbExtractReplacedFileExt(char *szDest,
917 const char *cszFileName,
919 {//cszFileName
\82Ì
\8ag
\92£
\8eq
\82ð cszExt
\82É
\92u
\82«
\8a·
\82¦
\82Ä szDest
\82É
\83R
\83s
\81[
\82·
\82é
920 //szDest
\82Ì
\83T
\83C
\83Y
\82Í cszFileName
\82Æ cszExt
\82Ì
\8d\87\8cv
\82æ
\82è
\91å
\82«
\82¢
\82±
\82Æ
\82ª
\91O
\92ñ
928 strcpy(szDest, cszExt);
931 const char *ext = kbStrRChr(cszFileName, '.');
932 const char *path = kbStrRChr(cszFileName, '\\');
933 if (ext && ext > path) {
934 const int len = ext - cszFileName;
935 memcpy(szDest, cszFileName, len);
936 strcpy(szDest + len, cszExt);
939 strcpy(szDest, cszFileName);
940 strcat(szDest, cszExt);
945 ///////////////////////////////////////////////////////////////////////////////
946 void __fastcall kbAddPathDelimiter(char *szPath)
947 {//
\95¶
\8e\9a\97ñ
\82Ì
\8fI
\92[
\82É \
\82ð
\92Ç
\89Á
948 //
\82·
\82Å
\82É
\8fI
\92[
\82ª \
\82Ì
\8fê
\8d\87\82Í
\89½
\82à
\82µ
\82È
\82¢
951 //
\8fI
\92[
\95¶
\8e\9a\82ð
\92T
\82·
954 if (kbIsLeadByte(*p)) {
955 if (!p[1]) {//
\95¶
\8e\9a\97ñ
\82ª
\93r
\90Ø
\82ê
\82Ä
\82¢
\82é
958 continue;//
\8dÅ
\8f\89\82©
\82ç
\82â
\82è
\92¼
\82·
971 ///////////////////////////////////////////////////////////////////////////////
972 void __fastcall kbCombinePath(char *szDest, const char *cszSrc,
973 const char *cszAdd, int nDestSize)
975 kbStrLCpy(szDest, cszSrc, nDestSize);
976 char *p = kbStrRChr(szDest, '\\');
977 if (!p || p[1]) {//\
\82ª
\8aÜ
\82Ü
\82ê
\82È
\82¢ or
\8aÜ
\82Þ
\82ª
\8fI
\92[
\82Å
\82Í
\82È
\82¢
978 kbStrLCat(szDest, "\\", nDestSize);//kbAddPathDelimiter
\82¾
\82Æ
\83o
\83b
\83t
\83@
\83T
\83C
\83Y
\82Ì
\83`
\83F
\83b
\83N
\82ð
\82µ
\82È
\82¢
\82Ì
\82Å
\8eg
\97p
\95s
\89Â
980 kbStrLCat(szDest, cszAdd, nDestSize);
982 ///////////////////////////////////////////////////////////////////////////////
983 void __fastcall kbRemovePathDelimiter(char *szPath)
984 { //
\83h
\83\89\83C
\83u
\82Ì
\83\8b\81[
\83g
\82Å
\82È
\82¢
\8fê
\8d\87\82Í
\8fI
\92[
\82Ì \
\82ð
\8f\9c\82
985 char *p = kbStrRChr(szPath, '\\');
986 if (p && !p[1] && (p - szPath >= 3)) {
990 ///////////////////////////////////////////////////////////////////////////////