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
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121 #ifndef INC_MI32_FIXEDSTR_H
00122 #define INC_MI32_FIXEDSTR_H
00123
00124 #ifndef INC_MI32_STDDEFNS_H
00125 #include <mi32/stddefns.h>
00126 #endif
00127
00128 #ifndef INC_MI32_STDANSIC_H
00129 #include <mi32/stdansic.h>
00130 #endif
00131
00132 #ifndef INC_MI32_UCSTRING_H
00133 #include <mi32/ucstring.h>
00134 #endif
00135
00136 #ifndef INC_MI32_MEMBUF_H
00137 #include <mi32/membuf.h>
00138 #endif
00139
00140 #ifndef INC_MI32_INIDEFNS_H
00141 #include <mi32/inidefns.h>
00142 #endif
00143
00144 #ifndef INC_MI32_MISTRING_H
00145 #include <mi32/mistring.h>
00146 #endif
00147
00148
00149
00150
00151
00152 template <size_t _CT> class FIXEDSTRING {
00153 public:
00154
00155
00156 FIXEDSTRING (
00157 ) { Clear(); }
00158
00159
00160 FIXEDSTRING (
00161 const FIXEDSTRING& rhs
00162 ) { memcpy(m_String, rhs.m_String, sizeof(m_String)); }
00163
00164
00165 template <int _T2>
00166 FIXEDSTRING (
00167 const FIXEDSTRING<_T2>& rhs
00168 ) {
00169 Clear();
00170 ucstrncpy(m_String, rhs.GetReference(), _CT-1);
00171 }
00172
00173
00174 FIXEDSTRING (
00175 const UNICODE* string
00176 ) {
00177 Clear();
00178 if (string != 0) ucstrncpy(m_String, string, _CT - 1);
00179 }
00180
00181
00182 FIXEDSTRING (
00183 const MISTRING& string
00184 ) {
00185 Clear();
00186 ucstrncpy(m_String, string, _CT - 1);
00187 }
00188
00189
00190 FIXEDSTRING (
00191 TEXTID textid
00192 ) { Clear(); MISTRING str(textid); ucstrncpy(m_String,str,_CT-1); }
00193
00194
00195 ~FIXEDSTRING (
00196 ) { m_String[0] = 0; }
00197
00198
00199 FIXEDSTRING& operator= (
00200 const FIXEDSTRING& rhs
00201 ) {
00202 if (this != &rhs) {
00203 memcpy(m_String, rhs.m_String, sizeof(m_String));
00204 }
00205 return (*this);
00206 }
00207
00208
00209 template <int _T2>
00210 FIXEDSTRING<_CT>& operator= (
00211 const FIXEDSTRING<_T2>& rhs
00212 ) {
00213 Clear();
00214 ucstrncpy(m_String, rhs.GetReference(), _CT-1);
00215 return (*this);
00216 }
00217
00218
00219 FIXEDSTRING& operator= (
00220 const UNICODE* rhs
00221 ) {
00222 if (m_String != rhs) {
00223 Clear();
00224 if (rhs != 0) ucstrncpy(m_String, rhs, _CT - 1);
00225 }
00226 return (*this);
00227 }
00228
00229
00230 FIXEDSTRING& operator= (
00231 const MISTRING& rhs
00232 ) {
00233 Clear();
00234 ucstrncpy(m_String, rhs, _CT - 1);
00235 return (*this);
00236 }
00237
00238
00239 FIXEDSTRING& operator= (
00240 TEXTID textid
00241 ) { Clear(); MISTRING str(textid); ucstrncpy(m_String,str,_CT-1); return(*this); }
00242
00243
00244 template <int _T2>
00245 FIXEDSTRING<_CT>& operator+= (
00246 const FIXEDSTRING<_T2>& rhs
00247 ) {
00248 ucstrncat(m_String, static_cast<const UNICODE*>(rhs), _CT - (ucstrlen(m_String) + 1));
00249 return (*this);
00250 }
00251
00252
00253 FIXEDSTRING& operator+= (
00254 const UNICODE* rhs
00255 ) {
00256 if (rhs != 0) ucstrncat(m_String, rhs, _CT - (ucstrlen(m_String) + 1));
00257 return (*this);
00258 }
00259
00260
00261 bool operator== (
00262 const FIXEDSTRING& rhs
00263 ) const { return (Compare(rhs) == 0); }
00264
00265
00266 bool operator== (
00267 const UNICODE *rhs
00268 ) const { return (Compare(rhs) == 0); }
00269
00270
00271 bool operator!= (
00272 const FIXEDSTRING& rhs
00273 ) const { return (!(*this == rhs)); }
00274
00275
00276 bool operator!= (
00277 const UNICODE *rhs
00278 ) const { return (!(*this == rhs)); }
00279
00280
00281 bool operator< (
00282 const FIXEDSTRING& rhs
00283 ) const { return (Compare(rhs) < 0); }
00284
00285
00286 bool operator< (
00287 const UNICODE *rhs
00288 ) const { return (Compare(rhs) < 0); }
00289
00290
00291 bool operator<= (
00292 const FIXEDSTRING& rhs
00293 ) const { return (Compare(rhs) <= 0); }
00294
00295
00296 bool operator<= (
00297 const UNICODE *rhs
00298 ) const { return (Compare(rhs) <= 0); }
00299
00300
00301 bool operator> (
00302 const FIXEDSTRING& rhs
00303 ) const { return (Compare(rhs) > 0); }
00304
00305
00306 bool operator> (
00307 const UNICODE *rhs
00308 ) const { return (Compare(rhs) > 0); }
00309
00310
00311 bool operator>= (
00312 const FIXEDSTRING& rhs
00313 ) const { return (Compare(rhs) >= 0); }
00314
00315
00316 bool operator>= (
00317 const UNICODE *rhs
00318 ) const { return (Compare(rhs) >= 0); }
00319
00320
00321 operator const UNICODE* (
00322 ) const { return (m_String); }
00323
00324
00325
00326
00327
00328
00329 void Append (
00330 const char* name
00331 ) {
00332 UNICODE *p = ucstrchr(m_String, 0);
00333 strntouc(p, name, _CT - (p - m_String) - 1);
00334 return;
00335 }
00336
00337
00338 void Assign (
00339 const char* name
00340 ) { strntouc(m_String, name, _CT - 1); }
00341
00342
00343 void Assign (
00344 const char* name,
00345 size_t len
00346 ) { strntouc(m_String, name, MIN(_CT - 1, len)); }
00347
00348
00349 void Assign (
00350 const char* name,
00351 CHAR_ENCODING encoding
00352 ) {
00353 if (encoding == CHAR_ENCODING_ASCII) {
00354 strtouc(m_String, name);
00355 }
00356 else {
00357 MISTRING mistr(name, encoding);
00358 Clear();
00359 ucstrncpy(m_String, mistr, _CT - 1);
00360 }
00361 }
00362
00363
00364 void Assign (
00365 const UNICODE* name,
00366 size_t len
00367 ) { ucstrncpy(m_String, name, MIN(_CT - 1, len)); }
00368
00369
00370 void Clear (
00371 ) { memset(m_String, 0, sizeof(m_String)); }
00372
00373
00374
00375 int Compare (
00376 const FIXEDSTRING& str
00377 ) const { return (ucstrcmp(m_String, str.m_String)); }
00378
00379
00380
00381 int Compare (
00382 const UNICODE *str
00383 ) const { return (ucstrcmp(m_String, str)); }
00384
00385
00386
00387 int CompareNoCase (
00388 const FIXEDSTRING& str
00389 ) const { return (ucstricmp(m_String, str.m_String)); }
00390
00391
00392
00393 int CompareNoCase (
00394 const UNICODE *str
00395 ) const { return (ucstricmp(m_String, str)); }
00396
00397
00398 class UNIQUENAMEFILTER {
00399 public:
00400 UNIQUENAMEFILTER () {}
00401
00402
00403
00404 int Filter (const FIXEDSTRING<_CT>& string) { return (v_Filter(string)); }
00405 private:
00406 virtual int v_Filter (const FIXEDSTRING<_CT>& string) = 0;
00407 };
00408
00409
00410 ERRVALUE GenerateUniqueName (
00411 UNIQUENAMEFILTER& FilterInst
00412 ) {
00413 ERRVALUE err;
00414 if ((err = FilterInst.Filter(*this)) < 0) return (err);
00415 if (err > 0) return (0);
00416
00417
00418 int k = 0, len = GetLength();
00419 memset(&m_String[len], 0, (_CT - len) * sizeof(UNICODE));
00420 UNICODE* where = &m_String[len];
00421 if (len == (_CT-1)) where --;
00422 UNICODE* start = where;
00423 UINT8 count[_CT];
00424 memset(count, 0, _CT);
00425
00426 static char *AddArray = "1234567890abcdefghijklmnopqrstuvwxyz_?";
00427 do {
00428 *where = static_cast<UNICODE>(AddArray[k++]);
00429 if (*where == static_cast<UNICODE>('?')) {
00430 k = 1;
00431 *where = static_cast<UNICODE>(AddArray[0]);
00432 UNICODE *p;
00433 for (p = where - 1;(p >= start);--p) {
00434 *p = static_cast<UNICODE>(AddArray[count[p-m_String]++]);
00435 if (*p == static_cast<UNICODE>('?')) {
00436 *p = static_cast<UNICODE>(AddArray[0]);
00437 count[p-m_String] = 0;
00438 }
00439 else break;
00440 }
00441 if (p < start) {
00442 ++where;
00443 if (where - start == 4) return (EProgramError);
00444 memset(count, 0, _CT);
00445 if (where - m_String == (_CT-1)) {
00446 start --;
00447 where = start;
00448 if (start < m_String) return (EProgramError);
00449 }
00450 for (p = where;(p >= start);--p) *p = static_cast<UNICODE>(AddArray[0]);
00451 }
00452 }
00453 err = FilterInst.Filter(*this);
00454 } while (err == 0);
00455 if (err < 0) return (err);
00456 return (0);
00457 }
00458
00459
00460
00461 void* GetEncoded (
00462 CHAR_ENCODING encoding
00463 ) const {
00464 MISTRING tstr(m_String);
00465 return (tstr.GetEncoded(encoding));
00466 }
00467
00468
00469 size_t GetLength (
00470 ) const { return (ucstrlen(m_String)); }
00471
00472
00473 static size_t GetMaxSize (
00474 ) { return (_CT-1); }
00475
00476
00477 const UNICODE* GetReference (
00478 ) const { return (m_String); }
00479
00480
00481 const UNICODE* GetTail (
00482 int maxlen
00483 ) const { int len = ucstrlen(m_String); return ((len <= maxlen) ? m_String : (m_String + (len - maxlen))); }
00484
00485
00486 bool IsEmpty (
00487 ) const { return (m_String[0] == 0); }
00488
00489
00490
00491 bool IniRead (
00492 INIHANDLE inih,
00493 const char *group,
00494 const char*const field
00495 ) { return (::IniRead(inih, group, field, m_String, _CT * sizeof(UNICODE)) > 0); }
00496
00497
00498 void IniWrite (
00499 INIHANDLE inih,
00500 const char *group,
00501 const char*const field
00502 ) { ::IniWrite(inih, group, field, m_String); }
00503
00504
00505 void PadToEnd (
00506 char item
00507 ) {
00508 for (int j = ucstrlen(m_String);(j < _CT-1);++j) m_String[j] = item;
00509 m_String[_CT-1] = 0;
00510 }
00511
00512
00513 void SetLowerCase (
00514 ) { ucstrlwr(m_String); }
00515
00516
00517 void SetUpperCase (
00518 ) { ucstrupr(m_String); }
00519
00520
00521 void SwapBytes (
00522 ) { ::SwapBytes(m_String, _CT); }
00523
00524
00525 void Terminate (
00526 ) { m_String[_CT - 1] = 0; }
00527
00528
00529 void Truncate (
00530 size_t NewLength
00531 ) { if (NewLength < (_CT - 1)) m_String[NewLength] = 0; }
00532
00533 private:
00534 #ifndef GENERATING_DOXYGEN_OUTPUT
00535 UNICODE m_String[_CT];
00536 #endif // GENERATING_DOXYGEN_OUTPUT
00537 };
00538
00539
00540
00541
00542
00543 template <size_t _CT> class FIXEDSTRCHAR {
00544 public:
00545
00546
00547 FIXEDSTRCHAR (
00548 ) { Clear(); }
00549
00550
00551 FIXEDSTRCHAR (
00552 const FIXEDSTRCHAR& rhs
00553 ) { memcpy(m_String, rhs.m_String, sizeof(m_String)); }
00554
00555
00556 FIXEDSTRCHAR (
00557 const char* string
00558 ) { Clear(); strncpy(m_String, string, _CT - 1); }
00559
00560
00561 ~FIXEDSTRCHAR (
00562 ) { m_String[0] = 0; }
00563
00564
00565 FIXEDSTRCHAR& operator= (
00566 const FIXEDSTRCHAR& rhs
00567 ) {
00568 if (this != &rhs) {
00569 memcpy(m_String, rhs.m_String, sizeof(m_String));
00570 }
00571 return (*this);
00572 }
00573
00574
00575 FIXEDSTRCHAR& operator= (
00576 const char* rhs
00577 ) {
00578 if (m_String != rhs) {
00579 Clear();
00580 strncpy(m_String, rhs, _CT - 1);
00581 }
00582 return (*this);
00583 }
00584
00585
00586 FIXEDSTRCHAR& operator+= (
00587 const FIXEDSTRCHAR& rhs
00588 ) {
00589 strncat(m_String, rhs.m_String, _CT - (strlen(m_String) + 1));
00590 return (*this);
00591 }
00592
00593
00594 FIXEDSTRCHAR& operator+= (
00595 const char* rhs
00596 ) {
00597 strncat(m_String, rhs, _CT - (strlen(m_String) + 1));
00598 return (*this);
00599 }
00600
00601
00602 bool operator== (
00603 const FIXEDSTRCHAR& rhs
00604 ) const { return (Compare(rhs) == 0); }
00605
00606
00607 bool operator== (
00608 const char *rhs
00609 ) const { return (Compare(rhs) == 0); }
00610
00611
00612 bool operator!= (
00613 const FIXEDSTRCHAR& rhs
00614 ) const { return (!(*this == rhs)); }
00615
00616
00617 bool operator!= (
00618 const char *rhs
00619 ) const { return (!(*this == rhs)); }
00620
00621
00622 bool operator< (
00623 const FIXEDSTRCHAR& rhs
00624 ) const { return (Compare(rhs) < 0); }
00625
00626
00627 bool operator< (
00628 const char *rhs
00629 ) const { return (Compare(rhs) < 0); }
00630
00631
00632 bool operator<= (
00633 const FIXEDSTRCHAR& rhs
00634 ) const { return (Compare(rhs) <= 0); }
00635
00636
00637 bool operator<= (
00638 const char *rhs
00639 ) const { return (Compare(rhs) <= 0); }
00640
00641
00642 bool operator> (
00643 const FIXEDSTRCHAR& rhs
00644 ) const { return (Compare(rhs) > 0); }
00645
00646
00647 bool operator> (
00648 const char *rhs
00649 ) const { return (Compare(rhs) > 0); }
00650
00651
00652 bool operator>= (
00653 const FIXEDSTRCHAR& rhs
00654 ) const { return (Compare(rhs) >= 0); }
00655
00656
00657 bool operator>= (
00658 const char *rhs
00659 ) const { return (Compare(rhs) >= 0); }
00660
00661
00662 operator const char* (
00663 ) const { return (m_String); }
00664
00665
00666 void Assign (
00667 const char* name
00668 ) { strncpy(m_String, name, _CT - 1); }
00669
00670
00671 void Assign (
00672 const char* name,
00673 size_t len
00674 ) { strncpy(m_String, name, MIN(_CT - 1, len)); }
00675
00676
00677 void Clear (
00678 ) { memset(m_String, 0, sizeof(m_String)); }
00679
00680
00681
00682 int Compare (
00683 const FIXEDSTRCHAR& str
00684 ) const { return (strcmp(m_String, str.m_String)); }
00685
00686
00687
00688 int Compare (
00689 const char *str
00690 ) const { return (strcmp(m_String, str)); }
00691
00692
00693
00694 int CompareNoCase (
00695 const FIXEDSTRCHAR& str
00696 ) const { return (stricmp(m_String, str.m_String)); }
00697
00698
00699
00700 int CompareNoCase (
00701 const char *str
00702 ) const { return (stricmp(m_String, str)); }
00703
00704
00705 bool IsEmpty (
00706 ) const { return (m_String[0] == 0); }
00707
00708
00709
00710 bool IniRead (
00711 INIHANDLE inih,
00712 const char *group,
00713 const char*const field
00714 ) { return (::IniRead(inih, group, field, m_String, _CT * sizeof(char)) > 0); }
00715
00716
00717 void IniWrite (
00718 INIHANDLE inih,
00719 const char *group,
00720 const char*const field
00721 ) { ::IniWrite(inih, group, field, m_String); }
00722
00723
00724 size_t GetLength (
00725 ) const { return (strlen(m_String)); }
00726
00727
00728 size_t GetMaxSize (
00729 ) const { return (_CT-1); }
00730
00731
00732 const char* GetTail (
00733 int maxlen
00734 ) const { int len = strlen(m_String); return ((len <= maxlen) ? m_String : (m_String + (len - maxlen))); }
00735
00736
00737 void PadToEnd (
00738 char item
00739 ) {
00740 for (int j = strlen(m_String);(j < _CT-1);++j) m_String[j] = item;
00741 m_String[_CT-1] = 0;
00742 }
00743
00744
00745 void SetLowerCase (
00746 ) { strlwr(m_String); }
00747
00748
00749 void SetUpperCase (
00750 ) { strupr(m_String); }
00751
00752
00753 void Terminate (
00754 ) { m_String[_CT - 1] = 0; }
00755
00756
00757 void Truncate (
00758 size_t NewLength
00759 ) { if (NewLength >= 0 && NewLength < (_CT - 1)) m_String[NewLength] = 0; }
00760
00761 protected:
00762 #ifndef GENERATING_DOXYGEN_OUTPUT
00763 char m_String[_CT];
00764 #endif
00765 };
00766
00767 #endif