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