home *** CD-ROM | disk | FTP | other *** search
/ PC Media 7 / PC MEDIA CD07.iso / share / prog / cm / cmstring.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1994-09-06  |  20.9 KB  |  942 lines

  1. // CmString.cpp
  2. // -----------------------------------------------------------------
  3. // Compendium - C++ Container Class Library
  4. // Copyright (C) 1992-1994, Glenn M. Poorman, All rights reserved
  5. // -----------------------------------------------------------------
  6. // Character string implementation.
  7. // -----------------------------------------------------------------
  8.  
  9. #include <ctype.h>
  10. #include <string.h>
  11. #include <cm/include/cmstring.h>
  12. #include <stdio.h>
  13.  
  14.  
  15. // Define "stricmp" and "strnicmp" for machines that don't support it.
  16. //
  17. #if !defined(__TURBOC__)
  18.   int stricmp(const char* a, const char* b)
  19.   {
  20.     CmString A(a), B(b);
  21.     A.toUpper(); B.toUpper();
  22.     return strcmp(A, B);
  23.   }
  24.   int strnicmp(const char* a, const char* b, int n)
  25.   {
  26.     CmString A(a), B(b);
  27.     A.toUpper(); B.toUpper();
  28.     return strncmp(A, B, n);
  29.   }
  30. #endif
  31.  
  32.  
  33. // Initialize the case sensitive compare flag.
  34. //
  35. Bool CmString::_caseSensitive = TRUE;
  36.  
  37.  
  38. // "CmString" is the default string constructor.
  39. //
  40. CmString::CmString(const char *letters)
  41. {
  42.   _text = NULL;
  43.   copy(letters);
  44. }
  45.  
  46.  
  47. // "CmString" constructs a string of size N and fills the string with
  48. // N copies of the specified character.
  49. //
  50. CmString::CmString(int N, char C)
  51. {
  52.   _text = new char[N+1];
  53.   if (_text)
  54.   {
  55.     for (int ii = 0; ii < N; ii++)
  56.       _text[ii] = C;
  57.     _text[N] = '\0';
  58.   }
  59. }
  60.  
  61.  
  62. // "CmString" constructs a string from the specified substring.
  63. //
  64. CmString::CmString(const CmSubString& S)
  65. {
  66.   _text = (S._sl > 0) ? new char[S._sl+1] : NULL;
  67.   if (_text)
  68.   {
  69.     strncpy(_text, S._sp, S._sl);
  70.     _text[S._sl] = '\0';
  71.   }
  72. }
  73.  
  74.  
  75. // "CmString" is the string copy constructor.
  76. //
  77. CmString::CmString(const CmString &S)
  78. {
  79.   _text = NULL;
  80.   copy(S._text);
  81. }
  82.  
  83.  
  84. // "~CmString" is the string destructor.
  85. //
  86. CmString::~CmString()
  87. {
  88.   delete[] _text;
  89. }
  90.  
  91.  
  92. // "index" returns the first occurrence of the specified character
  93. // in the string.
  94. //
  95. int CmString::index(char chr) const
  96. {
  97.   int pos = -1;
  98.   if (_text  && strlen(_text) > 0)
  99.   {
  100.     int ii = 0, ln = strlen(_text);
  101.     while (ii < ln && pos == -1)
  102.       if (chr == _text[ii++]) pos = ii - 1;
  103.   }
  104.   return pos;
  105. }
  106.  
  107.  
  108. // "LeftJustify" left justifies the string within itself.
  109. //
  110. void CmString::leftJustify()
  111. {
  112.   int   lnth    = strlen(_text);
  113.   char *letters = new char[lnth+1];
  114.   strcpy(letters, _text);
  115.  
  116.   int ii = 0;
  117.   while (isspace(letters[ii])) ii++;
  118.   if (ii == lnth)
  119.     _text = NULL;
  120.   else if (ii > 0)
  121.   {
  122.     for (int jj = 0; jj < (lnth-ii); jj++)
  123.       letters[jj] = letters[ii + jj];
  124.     letters[lnth - ii] = '\0';
  125.   }
  126.  
  127.   copy(letters);
  128.   delete[] letters;
  129. }
  130.  
  131.  
  132. // "rightJustify" rights justifies the string within itself.
  133. //
  134. void CmString::rightJustify()
  135. {
  136.   if (!_text) return;
  137.  
  138.   int   lnth    = strlen(_text);
  139.   char *letters = new char[lnth+1];
  140.   strcpy(letters, _text);
  141.  
  142.   int ii = lnth-1;
  143.   while (isspace(letters[ii]) && ii >= 0) ii--;
  144.  
  145.   if (ii == lnth-1) return;
  146.  
  147.   if (ii < 0)
  148.   {
  149.     copy(NULL);
  150.     return;
  151.   }
  152.  
  153.   int howmany = ii + 1, jj = lnth;
  154.   while (ii >= 0)
  155.     letters[jj--] = letters[ii--];
  156.  
  157.   for (ii = 0; ii < howmany; ii++)
  158.     letters[ii] = ' ';
  159.  
  160.   copy(letters);
  161.   delete[] letters;
  162. }
  163.  
  164.  
  165. // "trim" trims the leading and trailing blank characters from the
  166. // string.
  167. //
  168. void CmString::trim()
  169. {
  170.   char* p = _text;
  171.   while (isspace(*p)) p++;
  172.   if (p != _text) strcpy(_text, p);
  173.   int cc = strlen(_text);
  174.   if (cc) for (p = _text + cc - 1; isspace(*p); p--) *p = '\0';
  175.   int lnth = strlen(_text);
  176.   char* newText = (lnth > 0) ? new char[lnth + 1] : NULL;
  177.   if (lnth > 0) strcpy(newText, _text);
  178.   delete[] _text;
  179.   _text = newText;
  180. }
  181.  
  182.  
  183. // "toLower" converts all characters in this string to lower case.
  184. //
  185. void CmString::toLower()
  186. {
  187.   int   i = strlen(_text);
  188.   char *q = _text;
  189.   while (i--) { if (*q >= 'A' && *q <= 'Z') *q = *q - 'A' + 'a'; q++; }
  190. }
  191.  
  192.  
  193. // "toUpper" converts all characters in this string to upper case.
  194. //
  195. void CmString::toUpper()
  196. {
  197.   int   i = strlen(_text);
  198.   char *q = _text;
  199.   while (i--) { if (*q >= 'a' && *q <= 'z') *q = *q - 'a' + 'A'; q++; }
  200. }
  201.  
  202.  
  203. // "()" substring operator returns a substring of this string.
  204. //
  205. CmSubString CmString::operator()(int start, int stop)
  206. {
  207.   int st = (start < 0) ? 0 : ((start >= length()) ? length() - 1 : start);
  208.   int en = (stop  < 0) ? 0 : ((stop  >= length()) ? length() - 1 : stop);
  209.   if (start > stop) start = stop;
  210.   return CmSubString(*this, st, en);
  211. }
  212.  
  213.  
  214. // "()" substring operator returns a substring of this string.
  215. //
  216. const CmSubString CmString::operator()(int start, int stop) const
  217. {
  218.   int st = (start < 0) ? 0 : ((start >= length()) ? length() - 1 : start);
  219.   int en = (stop  < 0) ? 0 : ((stop  >= length()) ? length() - 1 : stop);
  220.   if (start > stop) start = stop;
  221.   return CmSubString(*this, st, en);
  222. }
  223.  
  224.  
  225. // "isEqual" checks to see if the input object is a string and it they
  226. // are equal.
  227. //
  228. Bool CmString::isEqual(CmObject* pObj) const
  229. {
  230.   if (pObj->isA("CmString")) return (*this == ((CmString&) *pObj));
  231.   else                       return CmObject::isEqual(pObj);
  232. }
  233.  
  234.  
  235. // "compare" does a comparison of the input object and this string and
  236. // returns -1 if this is < object, 0 if equal, 1 if this is greater.
  237. //
  238. int CmString::compare(CmObject* pObj) const
  239. {
  240.   if (!pObj->isA("CmString")) return CmObject::compare(pObj);
  241.   CmString& str = (CmString&) *pObj;
  242.   return ((str == *this) ? 0 : ((*this > str) ? 1 : -1));
  243. }
  244.  
  245.  
  246. // "hash" hashes the character string.
  247. //
  248. unsigned CmString::hash(unsigned m) const
  249. {
  250.   unsigned h;
  251.   char* v = _text;
  252.   for (h = 0; *v != '\0'; v++) h = (64 * h + *v) % m;
  253.   return h;
  254. }
  255.  
  256.  
  257. // "readFrom" reads text into this string from the specified input
  258. // stream operator.
  259. //
  260. void CmString::readFrom(istream& is)
  261. {
  262.   char buff[1024];
  263.   is.getline(buff, sizeof(buff));
  264.   copy(buff);
  265. }
  266.  
  267.  
  268. // "write" writes the string length and text to the specified reserve
  269. // binary file.
  270. //
  271. Bool CmString::write(CmReserveFile& file) const
  272. {
  273.   return file.write(_text);
  274. }
  275.  
  276.  
  277. // "read" reads the string length and text from the specified reserve
  278. // binary file.
  279. //
  280. Bool CmString::read(CmReserveFile& file)
  281. {
  282.   int lnth;
  283.   if (!file.read(lnth)) return FALSE;
  284.   if (lnth == 0)
  285.   {
  286.     copy(NULL);
  287.     return TRUE;
  288.   }
  289.  
  290.   char* s = (lnth > 0) ? new char[lnth] : NULL;
  291.   if (!s) return FALSE;
  292.   if (!file.read(s, (unsigned) lnth)) return FALSE;
  293.   copy(s);
  294.   delete[] s;
  295.   return TRUE;
  296. }
  297.  
  298.  
  299. // "+" operator concatenates this string and an input string returning the
  300. // resultant string.
  301. //
  302. CmString CmString::operator+(const CmString &S) const
  303. {
  304.   CmString NewString = *this;
  305.   NewString.append(S);
  306.   return NewString;
  307. }
  308.  
  309.  
  310. // "+=" operator concatenates an input string on to the end of this string.
  311. //
  312. CmString& CmString::operator+=(const CmString &S)
  313. {
  314.   append(S);
  315.   return *this;
  316. }
  317.  
  318.  
  319. // "+" operator concatenates this string and an input string returning the
  320. // resultant string.
  321. //
  322. CmString CmString::operator+(const char* s) const
  323. {
  324.   CmString NewString = *this;
  325.   NewString.append(CmString(s));
  326.   return NewString;
  327. }
  328.  
  329.  
  330. // "+=" operator concatenates an input string on to the end of this string.
  331. //
  332. CmString& CmString::operator+=(const char* s)
  333. {
  334.   append(CmString(s));
  335.   return *this;
  336. }
  337.  
  338. // "+" operator concatenates the input strings returning the result.
  339. //
  340. CmString operator+(const char* s, const CmString& S)
  341. {
  342.   CmString NewString = s;
  343.   NewString.append(S);
  344.   return NewString;
  345. }
  346.  
  347.  
  348. // "copy" copies a character array into this string.
  349. //
  350. void CmString::copy(const char *letters)
  351. {
  352.   if (_text) delete[] _text;
  353.   if (letters)
  354.   {
  355.     _text = new char[strlen(letters)+1];
  356.     strcpy(_text, letters);
  357.   }
  358.   else
  359.     _text = NULL;
  360. }
  361.  
  362.  
  363. // "append" appends the contents of an input string onto the end of this
  364. // string.
  365. //
  366. void CmString::append(const CmString &S)
  367. {
  368.   int   len1    = (_text) ? strlen(_text) : 0;
  369.   int   len2    = (S._text) ? strlen(S._text) : 0;
  370.   int   lnth    = len1 + len2;
  371.   char *letters = (lnth > 0) ? new char[lnth + 1] : NULL;
  372.  
  373.   if (len1 && !len2)
  374.     strcpy(letters, _text);
  375.   else if (len2 && !len1)
  376.     strcpy(letters, S._text);
  377.   else if (len1 && len2)
  378.   {
  379.     strcpy(letters, _text);
  380.     letters = strcat(letters, S._text);
  381.   }
  382.   else
  383.     letters = NULL;
  384.  
  385.   if (_text) delete[] _text;
  386.   _text = letters;
  387. }
  388.  
  389.  
  390. // "<" checks if the specified string is less than this.
  391. //
  392. Bool CmString::operator<(const CmString& S) const
  393. {
  394.   if (CmString::caseSensitive())
  395.     return (strcmp(_text, S._text) < 0);
  396.   else
  397.     return (stricmp(_text, S._text) < 0);
  398. }
  399.  
  400.  
  401. // "<=" checks if the specified string is less than or equal to this.
  402. //
  403. Bool CmString::operator<=(const CmString& S) const
  404. {
  405.   if (CmString::caseSensitive())
  406.     return (strcmp(_text, S._text) <= 0);
  407.   else
  408.     return (stricmp(_text, S._text) <= 0);
  409. }
  410.  
  411.  
  412. // ">" checks if the specified string is greater than this.
  413. //
  414. Bool CmString::operator>(const CmString& S) const
  415. {
  416.   if (CmString::caseSensitive())
  417.     return (strcmp(_text, S._text) > 0);
  418.   else
  419.     return (stricmp(_text, S._text) > 0);
  420. }
  421.  
  422.  
  423. // ">=" checks if the specified string is greater than or equal to this.
  424. //
  425. Bool CmString::operator>=(const CmString& S) const
  426. {
  427.   if (CmString::caseSensitive())
  428.     return (strcmp(_text, S._text) >= 0);
  429.   else
  430.     return (stricmp(_text, S._text) >= 0);
  431. }
  432.  
  433.  
  434. // "==" checks if the specified string is equal to this.
  435. //
  436. Bool CmString::operator==(const CmString& S) const
  437. {
  438.   if (CmString::caseSensitive())
  439.     return (strcmp(_text, S._text) == 0);
  440.   else
  441.     return (stricmp(_text, S._text) == 0);
  442. }
  443.  
  444.  
  445. // "!=" checks if the specified string is not equal to this.
  446. //
  447. Bool CmString::operator!=(const CmString& S) const
  448. {
  449.   if (CmString::caseSensitive())
  450.     return (strcmp(_text, S._text) != 0);
  451.   else
  452.     return (stricmp(_text, S._text) != 0);
  453. }
  454.  
  455.  
  456. // "<" checks if the specified string is less than this.
  457. //
  458. Bool CmString::operator<(const char* s) const
  459. {
  460.   if (CmString::caseSensitive())
  461.     return (strcmp(_text, s) < 0);
  462.   else
  463.     return (stricmp(_text, s) < 0);
  464. }
  465.  
  466.  
  467. // "<=" checks if the specified string is less than or equal to this.
  468. //
  469. Bool CmString::operator<=(const char* s) const
  470. {
  471.   if (CmString::caseSensitive())
  472.     return (strcmp(_text, s) <= 0);
  473.   else
  474.     return (stricmp(_text, s) <= 0);
  475. }
  476.  
  477.  
  478. // ">" checks if the specified string is greater than this.
  479. //
  480. Bool CmString::operator>(const char* s) const
  481. {
  482.   if (CmString::caseSensitive())
  483.     return (strcmp(_text, s) > 0);
  484.   else
  485.     return (stricmp(_text, s) > 0);
  486. }
  487.  
  488.  
  489. // ">=" checks if the specified string is greater than or equal to this.
  490. //
  491. Bool CmString::operator>=(const char* s) const
  492. {
  493.   if (CmString::caseSensitive())
  494.     return (strcmp(_text, s) >= 0);
  495.   else
  496.     return (stricmp(_text, s) >= 0);
  497. }
  498.  
  499.  
  500. // "==" checks if the specified string is equal to this.
  501. //
  502. Bool CmString::operator==(const char* s) const
  503. {
  504.   if (CmString::caseSensitive())
  505.     return (strcmp(_text, s) == 0);
  506.   else
  507.     return (stricmp(_text, s) == 0);
  508. }
  509.  
  510.  
  511. // "!=" checks if the specified string is not equal to this.
  512. //
  513. Bool CmString::operator!=(const char* s) const
  514. {
  515.   if (CmString::caseSensitive())
  516.     return (strcmp(_text, s) != 0);
  517.   else
  518.     return (stricmp(_text, s) != 0);
  519. }
  520.  
  521.  
  522. // "<" checks if string B is less than string A.
  523. //
  524. Bool operator<(const char* s, const CmString& S)
  525. {
  526.   if (CmString::caseSensitive())
  527.     return (strcmp(s, S._text) < 0);
  528.   else
  529.     return (stricmp(s, S._text) < 0);
  530. }
  531.  
  532.  
  533. // "<=" checks if string B is less than ior equal to string A.
  534. //
  535. Bool operator<=(const char* s, const CmString& S)
  536. {
  537.   if (CmString::caseSensitive())
  538.     return (strcmp(s, S._text) <= 0);
  539.   else
  540.     return (stricmp(s, S._text) <= 0);
  541. }
  542.  
  543.  
  544. // ">" checks if string B is greater than string A.
  545. //
  546. Bool operator>(const char* s, const CmString& S)
  547. {
  548.   if (CmString::caseSensitive())
  549.     return (strcmp(s, S._text) > 0);
  550.   else
  551.     return (stricmp(s, S._text) > 0);
  552. }
  553.  
  554.  
  555. // ">=" checks if string B is greater than or equal to string A.
  556. //
  557. Bool operator>=(const char* s, const CmString& S)
  558. {
  559.   if (CmString::caseSensitive())
  560.     return (strcmp(s, S._text) >= 0);
  561.   else
  562.     return (stricmp(s, S._text) >= 0);
  563. }
  564.  
  565.  
  566. // "==" checks if string B is equal to string A.
  567. //
  568. Bool operator==(const char* s, const CmString& S)
  569. {
  570.   if (CmString::caseSensitive())
  571.     return (strcmp(s, S._text) == 0);
  572.   else
  573.     return (stricmp(s, S._text) == 0);
  574. }
  575.  
  576.  
  577. // "!=" checks if string B is not equal to string A.
  578. //
  579. Bool operator!=(const char* s, const CmString& S)
  580. {
  581.   if (CmString::caseSensitive())
  582.     return (strcmp(s, S._text) != 0);
  583.   else
  584.     return (stricmp(s, S._text) != 0);
  585. }
  586.  
  587.  
  588. // "=" assignment copies the contents of the specified string into
  589. // this substring.
  590. //
  591. CmString& CmSubString::operator=(const CmString& S)
  592. {
  593.   if (_sl == S.length()) strncpy(_sp, S._text, _sl);
  594.   else                   replace(S._text, S.length());
  595.   return *_st;
  596. }
  597.  
  598.  
  599. // "=" assignment copies the contents of the specified substring into
  600. // this substring.
  601. //
  602. CmString& CmSubString::operator=(const CmSubString& S)
  603. {
  604.   if (_sl == S._sl) strncpy(_sp, S._sp, _sl);
  605.   else              replace(S._sp, S._sl);
  606.   return *_st;
  607. }
  608.  
  609.  
  610. // "=" assignment copies the contents of the specified string into
  611. // this substring.
  612. //
  613. CmString& CmSubString::operator=(const char* s)
  614. {
  615.   int cslen = strlen(s);
  616.   if (_sl == cslen) strncpy(_sp, s, _sl);
  617.   else              replace(s, cslen);
  618.   return *_st;
  619. }
  620.  
  621.  
  622. // "<<" outputs this substring to the specified stream.
  623. //
  624. ostream& operator<<(ostream& os, const CmSubString& S)
  625. {
  626.   char *p = S._sp;
  627.   for (int ii = 0; ii < S._sl; ii++)
  628.     os << *(p++);
  629.   return os;
  630. }
  631.  
  632.  
  633. // "CmSubString" constructs a substring from the specified string,
  634. // starting position, and ending position.
  635. //
  636. CmSubString::CmSubString(const CmString& S, int start, int stop)
  637. {
  638.   _sp = &(S._text[start]);
  639.   _sl = stop - start + 1;
  640.   _st = &((CmString&)S);
  641. }
  642.  
  643.  
  644. // "CmSubString" constructs a substring from the specified substring.
  645. //
  646. CmSubString::CmSubString(const CmSubString& S)
  647. {
  648.   _sp = S._sp;
  649.   _sl = S._sl;
  650.   _st = S._st;
  651. }
  652.  
  653.  
  654. // "replace" replaces the contents of this substring with the specified
  655. // string.
  656. //
  657. void CmSubString::replace(const char* src, int srclen)
  658. {
  659.   int tot = (srclen == _sl) ? srclen : ((srclen < _sl) ? srclen : _sl);
  660.   strncpy(_sp, src, tot);
  661. }
  662.  
  663.  
  664. // "<" checks if the specified string is less than this.
  665. //
  666. Bool CmSubString::operator<(const CmString& S) const
  667. {
  668.   if (CmString::caseSensitive())
  669.     return (strncmp(_sp, S._text, _sl) < 0);
  670.   else
  671.     return (strnicmp(_sp, S._text, _sl) < 0);
  672. }
  673.  
  674.  
  675. // "<=" checks if the specified string is less than or equal to this.
  676. //
  677. Bool CmSubString::operator<=(const CmString& S) const
  678. {
  679.   if (CmString::caseSensitive())
  680.     return (strncmp(_sp, S._text, _sl) <= 0);
  681.   else
  682.     return (strnicmp(_sp, S._text, _sl) <= 0);
  683. }
  684.  
  685.  
  686. // ">" checks if the specified string is greater than this.
  687. //
  688. Bool CmSubString::operator>(const CmString& S) const
  689. {
  690.   if (CmString::caseSensitive())
  691.     return (strncmp(_sp, S._text, _sl) > 0);
  692.   else
  693.     return (strnicmp(_sp, S._text, _sl) > 0);
  694. }
  695.  
  696.  
  697. // ">=" checks if the specified string is greater than or equal to this.
  698. //
  699. Bool CmSubString::operator>=(const CmString& S) const
  700. {
  701.   if (CmString::caseSensitive())
  702.     return (strncmp(_sp, S._text, _sl) >= 0);
  703.   else
  704.     return (strnicmp(_sp, S._text, _sl) >= 0);
  705. }
  706.  
  707.  
  708. // "==" checks if the specified string is equal to this.
  709. //
  710. Bool CmSubString::operator==(const CmString& S) const
  711. {
  712.   if (CmString::caseSensitive())
  713.     return (strncmp(_sp, S._text, _sl) == 0);
  714.   else
  715.     return (strnicmp(_sp, S._text, _sl) == 0);
  716. }
  717.  
  718.  
  719. // "!=" checks if the specified string is not equal to this.
  720. //
  721. Bool CmSubString::operator!=(const CmString& S) const
  722. {
  723.   if (CmString::caseSensitive())
  724.     return (strncmp(_sp, S._text, _sl) != 0);
  725.   else
  726.     return (strnicmp(_sp, S._text, _sl) != 0);
  727. }
  728.  
  729.  
  730. // "<" checks if the specified string is less than this.
  731. //
  732. Bool CmSubString::operator<(const CmSubString& S) const
  733. {
  734.   if (CmString::caseSensitive())
  735.     return (strncmp(_sp, S._sp, _sl) < 0);
  736.   else
  737.     return (strnicmp(_sp, S._sp, _sl) < 0);
  738. }
  739.  
  740.  
  741. // "<=" checks if the specified string is less than or equal to this.
  742. //
  743. Bool CmSubString::operator<=(const CmSubString& S) const
  744. {
  745.   if (CmString::caseSensitive())
  746.     return (strncmp(_sp, S._sp, _sl) <= 0);
  747.   else
  748.     return (strnicmp(_sp, S._sp, _sl) <= 0);
  749. }
  750.  
  751.  
  752. // ">" checks if the specified string is greater than this.
  753. //
  754. Bool CmSubString::operator>(const CmSubString& S) const
  755. {
  756.   if (CmString::caseSensitive())
  757.     return (strncmp(_sp, S._sp, _sl) > 0);
  758.   else
  759.     return (strnicmp(_sp, S._sp, _sl) > 0);
  760. }
  761.  
  762.  
  763. // ">=" checks if the specified string is greater than or equal to this.
  764. //
  765. Bool CmSubString::operator>=(const CmSubString& S) const
  766. {
  767.   if (CmString::caseSensitive())
  768.     return (strncmp(_sp, S._sp, _sl) >= 0);
  769.   else
  770.     return (strnicmp(_sp, S._sp, _sl) >= 0);
  771. }
  772.  
  773.  
  774. // "==" checks if the specified string is equal to this.
  775. //
  776. Bool CmSubString::operator==(const CmSubString& S) const
  777. {
  778.   if (CmString::caseSensitive())
  779.     return (strncmp(_sp, S._sp, _sl) == 0);
  780.   else
  781.     return (strnicmp(_sp, S._sp, _sl) == 0);
  782. }
  783.  
  784.  
  785. // "!=" checks if the specified string is not equal to this.
  786. //
  787. Bool CmSubString::operator!=(const CmSubString& S) const
  788. {
  789.   if (CmString::caseSensitive())
  790.     return (strncmp(_sp, S._sp, _sl) != 0);
  791.   else
  792.     return (strnicmp(_sp, S._sp, _sl) != 0);
  793. }
  794.  
  795.  
  796. // "<" checks if the specified string is less than this.
  797. //
  798. Bool CmSubString::operator<(const char* s) const
  799. {
  800.   if (CmString::caseSensitive())
  801.     return (strncmp(_sp, s, _sl) < 0);
  802.   else
  803.     return (strnicmp(_sp, s, _sl) < 0);
  804. }
  805.  
  806.  
  807. // "<=" checks if the specified string is less than or equal to this.
  808. //
  809. Bool CmSubString::operator<=(const char* s) const
  810. {
  811.   if (CmString::caseSensitive())
  812.     return (strncmp(_sp, s, _sl) <= 0);
  813.   else
  814.     return (strnicmp(_sp, s, _sl) <= 0);
  815. }
  816.  
  817.  
  818. // ">" checks if the specified string is greater than this.
  819. //
  820. Bool CmSubString::operator>(const char* s) const
  821. {
  822.   if (CmString::caseSensitive())
  823.     return (strncmp(_sp, s, _sl) > 0);
  824.   else
  825.     return (strnicmp(_sp, s, _sl) > 0);
  826. }
  827.  
  828.  
  829. // ">=" checks if the specified string is greater than or equal to this.
  830. //
  831. Bool CmSubString::operator>=(const char* s) const
  832. {
  833.   if (CmString::caseSensitive())
  834.     return (strncmp(_sp, s, _sl) >= 0);
  835.   else
  836.     return (strnicmp(_sp, s, _sl) >= 0);
  837. }
  838.  
  839.  
  840. // "==" checks if the specified string is equal to this.
  841. //
  842. Bool CmSubString::operator==(const char* s) const
  843. {
  844.   if (CmString::caseSensitive())
  845.     return (strncmp(_sp, s, _sl) == 0);
  846.   else
  847.     return (strnicmp(_sp, s, _sl) == 0);
  848. }
  849.  
  850.  
  851. // "!=" checks if the specified string is not equal to this.
  852. //
  853. Bool CmSubString::operator!=(const char* s) const
  854. {
  855.   if (CmString::caseSensitive())
  856.     return (strncmp(_sp, s, _sl) != 0);
  857.   else
  858.     return (strnicmp(_sp, s, _sl) != 0);
  859. }
  860.  
  861.  
  862. // "<" checks if the the sub-string is less than the string.
  863. //
  864. Bool operator<(const char* s, const CmSubString& S)
  865. {
  866.   if (CmString::caseSensitive())
  867.     return (strncmp(s, S._sp, S._sl) < 0);
  868.   else
  869.     return (strnicmp(s, S._sp, S._sl) < 0);
  870. }
  871.  
  872.  
  873. // "<=" checks if the the sub-string is less than or equal to the string.
  874. //
  875. Bool operator<=(const char* s, const CmSubString& S)
  876. {
  877.   if (CmString::caseSensitive())
  878.     return (strncmp(s, S._sp, S._sl) <= 0);
  879.   else
  880.     return (strnicmp(s, S._sp, S._sl) <= 0);
  881. }
  882.  
  883.  
  884. // ">" checks if the the sub-string is greater than the string.
  885. //
  886. Bool operator>(const char* s, const CmSubString& S)
  887. {
  888.   if (CmString::caseSensitive())
  889.     return (strncmp(s, S._sp, S._sl) > 0);
  890.   else
  891.     return (strnicmp(s, S._sp, S._sl) > 0);
  892. }
  893.  
  894.  
  895. // ">=" checks if the the sub-string is greater than or equal to the string.
  896. //
  897. Bool operator>=(const char* s, const CmSubString& S)
  898. {
  899.   if (CmString::caseSensitive())
  900.     return (strncmp(s, S._sp, S._sl) >= 0);
  901.   else
  902.     return (strnicmp(s, S._sp, S._sl) >= 0);
  903. }
  904.  
  905.  
  906. // "==" checks if the the sub-string is equal to the string.
  907. //
  908. Bool operator==(const char* s, const CmSubString& S)
  909. {
  910.   if (CmString::caseSensitive())
  911.     return (strncmp(s, S._sp, S._sl) == 0);
  912.   else
  913.     return (strnicmp(s, S._sp, S._sl) == 0);
  914. }
  915.  
  916.  
  917. // "!=" checks if the the sub-string is not equal to the string.
  918. //
  919. Bool operator!=(const char* s, const CmSubString& S)
  920. {
  921.   if (CmString::caseSensitive())
  922.     return (strncmp(s, S._sp, S._sl) != 0);
  923.   else
  924.     return (strnicmp(s, S._sp, S._sl) != 0);
  925. }
  926.  
  927.  
  928. // "caseSensitive" sets the case sensitive compare flag.
  929. //
  930. void CmString::caseSensitive(Bool f)
  931. {
  932.   CmString::_caseSensitive = f;
  933. }
  934.  
  935.  
  936. // "caseSensitive" returns the case sensitive compare flag.
  937. //
  938. Bool CmString::caseSensitive()
  939. {
  940.   return CmString::_caseSensitive;
  941. }
  942.