diff options
Diffstat (limited to '')
-rw-r--r-- | CPP/Common/MyString.h | 89 |
1 files changed, 70 insertions, 19 deletions
diff --git a/CPP/Common/MyString.h b/CPP/Common/MyString.h index c777c8c..e5ce18a 100644 --- a/CPP/Common/MyString.h +++ b/CPP/Common/MyString.h | |||
@@ -1,7 +1,7 @@ | |||
1 | // Common/MyString.h | 1 | // Common/MyString.h |
2 | 2 | ||
3 | #ifndef __COMMON_MY_STRING_H | 3 | #ifndef ZIP7_INC_COMMON_MY_STRING_H |
4 | #define __COMMON_MY_STRING_H | 4 | #define ZIP7_INC_COMMON_MY_STRING_H |
5 | 5 | ||
6 | #include <string.h> | 6 | #include <string.h> |
7 | 7 | ||
@@ -10,6 +10,7 @@ | |||
10 | #include <wchar.h> | 10 | #include <wchar.h> |
11 | #endif | 11 | #endif |
12 | 12 | ||
13 | #include "Common.h" | ||
13 | #include "MyWindows.h" | 14 | #include "MyWindows.h" |
14 | #include "MyTypes.h" | 15 | #include "MyTypes.h" |
15 | #include "MyVector.h" | 16 | #include "MyVector.h" |
@@ -70,7 +71,7 @@ inline char *MyStpCpy(char *dest, const char *src) | |||
70 | { | 71 | { |
71 | for (;;) | 72 | for (;;) |
72 | { | 73 | { |
73 | char c = *src; | 74 | const char c = *src; |
74 | *dest = c; | 75 | *dest = c; |
75 | if (c == 0) | 76 | if (c == 0) |
76 | return dest; | 77 | return dest; |
@@ -79,6 +80,13 @@ inline char *MyStpCpy(char *dest, const char *src) | |||
79 | } | 80 | } |
80 | } | 81 | } |
81 | 82 | ||
83 | inline void MyStringCat(char *dest, const char *src) | ||
84 | { | ||
85 | for (; *dest != 0; dest++); | ||
86 | while ((*dest++ = *src++) != 0); | ||
87 | // MyStringCopy(dest + MyStringLen(dest), src); | ||
88 | } | ||
89 | |||
82 | inline unsigned MyStringLen(const wchar_t *s) | 90 | inline unsigned MyStringLen(const wchar_t *s) |
83 | { | 91 | { |
84 | unsigned i; | 92 | unsigned i; |
@@ -93,7 +101,9 @@ inline void MyStringCopy(wchar_t *dest, const wchar_t *src) | |||
93 | 101 | ||
94 | inline void MyStringCat(wchar_t *dest, const wchar_t *src) | 102 | inline void MyStringCat(wchar_t *dest, const wchar_t *src) |
95 | { | 103 | { |
96 | MyStringCopy(dest + MyStringLen(dest), src); | 104 | for (; *dest != 0; dest++); |
105 | while ((*dest++ = *src++) != 0); | ||
106 | // MyStringCopy(dest + MyStringLen(dest), src); | ||
97 | } | 107 | } |
98 | 108 | ||
99 | 109 | ||
@@ -102,7 +112,7 @@ inline wchar_t *MyWcpCpy(wchar_t *dest, const wchar_t *src) | |||
102 | { | 112 | { |
103 | for (;;) | 113 | for (;;) |
104 | { | 114 | { |
105 | wchar_t c = *src; | 115 | const wchar_t c = *src; |
106 | *dest = c; | 116 | *dest = c; |
107 | if (c == 0) | 117 | if (c == 0) |
108 | return dest; | 118 | return dest; |
@@ -225,7 +235,7 @@ bool StringsAreEqualNoCase_Ascii(const char *s1, const char *s2) throw(); | |||
225 | bool StringsAreEqualNoCase_Ascii(const wchar_t *s1, const char *s2) throw(); | 235 | bool StringsAreEqualNoCase_Ascii(const wchar_t *s1, const char *s2) throw(); |
226 | bool StringsAreEqualNoCase_Ascii(const wchar_t *s1, const wchar_t *s2) throw(); | 236 | bool StringsAreEqualNoCase_Ascii(const wchar_t *s1, const wchar_t *s2) throw(); |
227 | 237 | ||
228 | #define MY_STRING_DELETE(_p_) delete []_p_; | 238 | #define MY_STRING_DELETE(_p_) { delete [](_p_); } |
229 | // #define MY_STRING_DELETE(_p_) my_delete(_p_); | 239 | // #define MY_STRING_DELETE(_p_) my_delete(_p_); |
230 | 240 | ||
231 | 241 | ||
@@ -312,7 +322,7 @@ public: | |||
312 | explicit AString(char c); | 322 | explicit AString(char c); |
313 | explicit AString(const char *s); | 323 | explicit AString(const char *s); |
314 | AString(const AString &s); | 324 | AString(const AString &s); |
315 | ~AString() { MY_STRING_DELETE(_chars); } | 325 | ~AString() { MY_STRING_DELETE(_chars) } |
316 | 326 | ||
317 | unsigned Len() const { return _len; } | 327 | unsigned Len() const { return _len; } |
318 | bool IsEmpty() const { return _len == 0; } | 328 | bool IsEmpty() const { return _len == 0; } |
@@ -322,6 +332,7 @@ public: | |||
322 | char *Ptr_non_const() const { return _chars; } | 332 | char *Ptr_non_const() const { return _chars; } |
323 | const char *Ptr() const { return _chars; } | 333 | const char *Ptr() const { return _chars; } |
324 | const char *Ptr(unsigned pos) const { return _chars + pos; } | 334 | const char *Ptr(unsigned pos) const { return _chars + pos; } |
335 | const char *Ptr(int pos) const { return _chars + (unsigned)pos; } | ||
325 | const char *RightPtr(unsigned num) const { return _chars + _len - num; } | 336 | const char *RightPtr(unsigned num) const { return _chars + _len - num; } |
326 | char Back() const { return _chars[(size_t)_len - 1]; } | 337 | char Back() const { return _chars[(size_t)_len - 1]; } |
327 | 338 | ||
@@ -379,6 +390,8 @@ public: | |||
379 | void Add_OptSpaced(const char *s); | 390 | void Add_OptSpaced(const char *s); |
380 | void Add_LF(); | 391 | void Add_LF(); |
381 | void Add_Slash(); | 392 | void Add_Slash(); |
393 | void Add_Dot(); | ||
394 | void Add_Minus(); | ||
382 | void Add_PathSepar() { operator+=(CHAR_PATH_SEPARATOR); } | 395 | void Add_PathSepar() { operator+=(CHAR_PATH_SEPARATOR); } |
383 | 396 | ||
384 | AString &operator+=(const char *s); | 397 | AString &operator+=(const char *s); |
@@ -389,6 +402,10 @@ public: | |||
389 | 402 | ||
390 | void AddFrom(const char *s, unsigned len); // no check | 403 | void AddFrom(const char *s, unsigned len); // no check |
391 | void SetFrom(const char *s, unsigned len); // no check | 404 | void SetFrom(const char *s, unsigned len); // no check |
405 | void SetFrom(const char* s, int len) // no check | ||
406 | { | ||
407 | SetFrom(s, (unsigned)len); // no check | ||
408 | } | ||
392 | void SetFrom_CalcLen(const char *s, unsigned len); | 409 | void SetFrom_CalcLen(const char *s, unsigned len); |
393 | 410 | ||
394 | AString Mid(unsigned startIndex, unsigned count) const { return AString(count, _chars + startIndex); } | 411 | AString Mid(unsigned startIndex, unsigned count) const { return AString(count, _chars + startIndex); } |
@@ -419,9 +436,13 @@ public: | |||
419 | int Find(char c) const { return FindCharPosInString(_chars, c); } | 436 | int Find(char c) const { return FindCharPosInString(_chars, c); } |
420 | int Find(char c, unsigned startIndex) const | 437 | int Find(char c, unsigned startIndex) const |
421 | { | 438 | { |
422 | int pos = FindCharPosInString(_chars + startIndex, c); | 439 | const int pos = FindCharPosInString(_chars + startIndex, c); |
423 | return pos < 0 ? -1 : (int)startIndex + pos; | 440 | return pos < 0 ? -1 : (int)startIndex + pos; |
424 | } | 441 | } |
442 | int Find(char c, int startIndex) const | ||
443 | { | ||
444 | return Find(c, (unsigned)startIndex); | ||
445 | } | ||
425 | 446 | ||
426 | int ReverseFind(char c) const throw(); | 447 | int ReverseFind(char c) const throw(); |
427 | int ReverseFind_Dot() const throw() { return ReverseFind('.'); } | 448 | int ReverseFind_Dot() const throw() { return ReverseFind('.'); } |
@@ -460,6 +481,11 @@ public: | |||
460 | _chars[index] = 0; | 481 | _chars[index] = 0; |
461 | } | 482 | } |
462 | } | 483 | } |
484 | void DeleteFrom(int index) | ||
485 | { | ||
486 | DeleteFrom((unsigned)index); | ||
487 | } | ||
488 | |||
463 | 489 | ||
464 | void Wipe_and_Empty() | 490 | void Wipe_and_Empty() |
465 | { | 491 | { |
@@ -474,7 +500,7 @@ public: | |||
474 | 500 | ||
475 | class AString_Wipe: public AString | 501 | class AString_Wipe: public AString |
476 | { | 502 | { |
477 | CLASS_NO_COPY(AString_Wipe) | 503 | Z7_CLASS_NO_COPY(AString_Wipe) |
478 | public: | 504 | public: |
479 | AString_Wipe(): AString() {} | 505 | AString_Wipe(): AString() {} |
480 | // AString_Wipe(const AString &s): AString(s) {} | 506 | // AString_Wipe(const AString &s): AString(s) {} |
@@ -582,7 +608,7 @@ public: | |||
582 | explicit UString(const AString &s); | 608 | explicit UString(const AString &s); |
583 | UString(const wchar_t *s); | 609 | UString(const wchar_t *s); |
584 | UString(const UString &s); | 610 | UString(const UString &s); |
585 | ~UString() { MY_STRING_DELETE(_chars); } | 611 | ~UString() { MY_STRING_DELETE(_chars) } |
586 | 612 | ||
587 | unsigned Len() const { return _len; } | 613 | unsigned Len() const { return _len; } |
588 | bool IsEmpty() const { return _len == 0; } | 614 | bool IsEmpty() const { return _len == 0; } |
@@ -591,6 +617,7 @@ public: | |||
591 | operator const wchar_t *() const { return _chars; } | 617 | operator const wchar_t *() const { return _chars; } |
592 | wchar_t *Ptr_non_const() const { return _chars; } | 618 | wchar_t *Ptr_non_const() const { return _chars; } |
593 | const wchar_t *Ptr() const { return _chars; } | 619 | const wchar_t *Ptr() const { return _chars; } |
620 | const wchar_t *Ptr(int pos) const { return _chars + (unsigned)pos; } | ||
594 | const wchar_t *Ptr(unsigned pos) const { return _chars + pos; } | 621 | const wchar_t *Ptr(unsigned pos) const { return _chars + pos; } |
595 | const wchar_t *RightPtr(unsigned num) const { return _chars + _len - num; } | 622 | const wchar_t *RightPtr(unsigned num) const { return _chars + _len - num; } |
596 | wchar_t Back() const { return _chars[(size_t)_len - 1]; } | 623 | wchar_t Back() const { return _chars[(size_t)_len - 1]; } |
@@ -599,6 +626,14 @@ public: | |||
599 | 626 | ||
600 | wchar_t *GetBuf() { return _chars; } | 627 | wchar_t *GetBuf() { return _chars; } |
601 | 628 | ||
629 | /* | ||
630 | wchar_t *GetBuf_GetMaxAvail(unsigned &availBufLen) | ||
631 | { | ||
632 | availBufLen = _limit; | ||
633 | return _chars; | ||
634 | } | ||
635 | */ | ||
636 | |||
602 | wchar_t *GetBuf(unsigned minLen) | 637 | wchar_t *GetBuf(unsigned minLen) |
603 | { | 638 | { |
604 | if (minLen > _limit) | 639 | if (minLen > _limit) |
@@ -650,6 +685,7 @@ public: | |||
650 | void Add_Space(); | 685 | void Add_Space(); |
651 | void Add_Space_if_NotEmpty(); | 686 | void Add_Space_if_NotEmpty(); |
652 | void Add_LF(); | 687 | void Add_LF(); |
688 | void Add_Dot(); | ||
653 | void Add_PathSepar() { operator+=(WCHAR_PATH_SEPARATOR); } | 689 | void Add_PathSepar() { operator+=(WCHAR_PATH_SEPARATOR); } |
654 | 690 | ||
655 | UString &operator+=(const wchar_t *s); | 691 | UString &operator+=(const wchar_t *s); |
@@ -662,6 +698,7 @@ public: | |||
662 | 698 | ||
663 | UString Mid(unsigned startIndex, unsigned count) const { return UString(count, _chars + startIndex); } | 699 | UString Mid(unsigned startIndex, unsigned count) const { return UString(count, _chars + startIndex); } |
664 | UString Left(unsigned count) const { return UString(count, *this); } | 700 | UString Left(unsigned count) const { return UString(count, *this); } |
701 | UString Left(int count) const { return Left((unsigned)count); } | ||
665 | 702 | ||
666 | // void MakeUpper() { MyStringUpper(_chars); } | 703 | // void MakeUpper() { MyStringUpper(_chars); } |
667 | // void MakeUpper() { MyStringUpper_Ascii(_chars); } | 704 | // void MakeUpper() { MyStringUpper_Ascii(_chars); } |
@@ -720,10 +757,12 @@ public: | |||
720 | void Replace(wchar_t oldChar, wchar_t newChar) throw(); | 757 | void Replace(wchar_t oldChar, wchar_t newChar) throw(); |
721 | void Replace(const UString &oldString, const UString &newString); | 758 | void Replace(const UString &oldString, const UString &newString); |
722 | 759 | ||
760 | void Delete(int index) throw() { Delete((unsigned)index); } | ||
723 | void Delete(unsigned index) throw(); | 761 | void Delete(unsigned index) throw(); |
724 | void Delete(unsigned index, unsigned count) throw(); | 762 | void Delete(unsigned index, unsigned count) throw(); |
725 | void DeleteFrontal(unsigned num) throw(); | 763 | void DeleteFrontal(unsigned num) throw(); |
726 | void DeleteBack() { _chars[--_len] = 0; } | 764 | void DeleteBack() { _chars[--_len] = 0; } |
765 | void DeleteFrom(int index) { DeleteFrom((unsigned)index); } | ||
727 | void DeleteFrom(unsigned index) | 766 | void DeleteFrom(unsigned index) |
728 | { | 767 | { |
729 | if (index < _len) | 768 | if (index < _len) |
@@ -746,7 +785,7 @@ public: | |||
746 | 785 | ||
747 | class UString_Wipe: public UString | 786 | class UString_Wipe: public UString |
748 | { | 787 | { |
749 | CLASS_NO_COPY(UString_Wipe) | 788 | Z7_CLASS_NO_COPY(UString_Wipe) |
750 | public: | 789 | public: |
751 | UString_Wipe(): UString() {} | 790 | UString_Wipe(): UString() {} |
752 | // UString_Wipe(const UString &s): UString(s) {} | 791 | // UString_Wipe(const UString &s): UString(s) {} |
@@ -834,7 +873,7 @@ public: | |||
834 | UString2(): _chars(NULL), _len(0) {} | 873 | UString2(): _chars(NULL), _len(0) {} |
835 | UString2(const wchar_t *s); | 874 | UString2(const wchar_t *s); |
836 | UString2(const UString2 &s); | 875 | UString2(const UString2 &s); |
837 | ~UString2() { if (_chars) MY_STRING_DELETE(_chars); } | 876 | ~UString2() { if (_chars) { MY_STRING_DELETE(_chars) } } |
838 | 877 | ||
839 | unsigned Len() const { return _len; } | 878 | unsigned Len() const { return _len; } |
840 | bool IsEmpty() const { return _len == 0; } | 879 | bool IsEmpty() const { return _len == 0; } |
@@ -912,7 +951,7 @@ typedef CObjectVector<CSysString> CSysStringVector; | |||
912 | 951 | ||
913 | #ifdef USE_UNICODE_FSTRING | 952 | #ifdef USE_UNICODE_FSTRING |
914 | 953 | ||
915 | #define __FTEXT(quote) L##quote | 954 | #define MY_FTEXT(quote) L##quote |
916 | 955 | ||
917 | typedef wchar_t FChar; | 956 | typedef wchar_t FChar; |
918 | typedef UString FString; | 957 | typedef UString FString; |
@@ -923,9 +962,9 @@ typedef CObjectVector<CSysString> CSysStringVector; | |||
923 | FString fas2fs(const AString &s); | 962 | FString fas2fs(const AString &s); |
924 | AString fs2fas(const FChar *s); | 963 | AString fs2fas(const FChar *s); |
925 | 964 | ||
926 | #else | 965 | #else // USE_UNICODE_FSTRING |
927 | 966 | ||
928 | #define __FTEXT(quote) quote | 967 | #define MY_FTEXT(quote) quote |
929 | 968 | ||
930 | typedef char FChar; | 969 | typedef char FChar; |
931 | 970 | ||
@@ -979,9 +1018,9 @@ typedef CObjectVector<CSysString> CSysStringVector; | |||
979 | FString us2fs(const wchar_t *s); | 1018 | FString us2fs(const wchar_t *s); |
980 | #define fs2fas(_x_) (_x_) | 1019 | #define fs2fas(_x_) (_x_) |
981 | 1020 | ||
982 | #endif | 1021 | #endif // USE_UNICODE_FSTRING |
983 | 1022 | ||
984 | #define FTEXT(quote) __FTEXT(quote) | 1023 | #define FTEXT(quote) MY_FTEXT(quote) |
985 | 1024 | ||
986 | #define FCHAR_PATH_SEPARATOR FTEXT(CHAR_PATH_SEPARATOR) | 1025 | #define FCHAR_PATH_SEPARATOR FTEXT(CHAR_PATH_SEPARATOR) |
987 | #define FSTRING_PATH_SEPARATOR FTEXT(STRING_PATH_SEPARATOR) | 1026 | #define FSTRING_PATH_SEPARATOR FTEXT(STRING_PATH_SEPARATOR) |
@@ -993,6 +1032,18 @@ typedef const FChar *CFSTR; | |||
993 | 1032 | ||
994 | typedef CObjectVector<FString> FStringVector; | 1033 | typedef CObjectVector<FString> FStringVector; |
995 | 1034 | ||
1035 | |||
1036 | class CStringFinder | ||
1037 | { | ||
1038 | AString _temp; | ||
1039 | public: | ||
1040 | // list - is list of low case Ascii strings separated by space " ". | ||
1041 | // the function returns true, if it can find exact word (str) in (list). | ||
1042 | bool FindWord_In_LowCaseAsciiList_NoCase(const char *list, const wchar_t *str); | ||
1043 | }; | ||
1044 | |||
1045 | void SplitString(const UString &srcString, UStringVector &destStrings); | ||
1046 | |||
996 | #endif | 1047 | #endif |
997 | 1048 | ||
998 | 1049 | ||
@@ -1000,10 +1051,10 @@ typedef CObjectVector<FString> FStringVector; | |||
1000 | #if defined(_WIN32) | 1051 | #if defined(_WIN32) |
1001 | // #include <wchar.h> | 1052 | // #include <wchar.h> |
1002 | // WCHAR_MAX is defined as ((wchar_t)-1) | 1053 | // WCHAR_MAX is defined as ((wchar_t)-1) |
1003 | #define _WCHART_IS_16BIT 1 | 1054 | #define Z7_WCHART_IS_16BIT 1 |
1004 | #elif (defined(WCHAR_MAX) && (WCHAR_MAX <= 0xffff)) \ | 1055 | #elif (defined(WCHAR_MAX) && (WCHAR_MAX <= 0xffff)) \ |
1005 | || (defined(__SIZEOF_WCHAR_T__) && (__SIZEOF_WCHAR_T__ == 2)) | 1056 | || (defined(__SIZEOF_WCHAR_T__) && (__SIZEOF_WCHAR_T__ == 2)) |
1006 | #define _WCHART_IS_16BIT 1 | 1057 | #define Z7_WCHART_IS_16BIT 1 |
1007 | #endif | 1058 | #endif |
1008 | 1059 | ||
1009 | #if WCHAR_PATH_SEPARATOR == L'\\' | 1060 | #if WCHAR_PATH_SEPARATOR == L'\\' |