ctkCaseInsensitiveString.cpp 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /*=============================================================================
  2. Library: CTK
  3. Copyright (c) German Cancer Research Center,
  4. Division of Medical and Biological Informatics
  5. Licensed under the Apache License, Version 2.0 (the "License");
  6. you may not use this file except in compliance with the License.
  7. You may obtain a copy of the License at
  8. http://www.apache.org/licenses/LICENSE-2.0
  9. Unless required by applicable law or agreed to in writing, software
  10. distributed under the License is distributed on an "AS IS" BASIS,
  11. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. See the License for the specific language governing permissions and
  13. limitations under the License.
  14. =============================================================================*/
  15. #include "ctkCaseInsensitiveString.h"
  16. #include <QHash> // for qHash(const QString&)
  17. //----------------------------------------------------------------------------
  18. ctkCaseInsensitiveString::ctkCaseInsensitiveString()
  19. {
  20. }
  21. //----------------------------------------------------------------------------
  22. ctkCaseInsensitiveString::ctkCaseInsensitiveString(const char* str)
  23. : str(str)
  24. {
  25. }
  26. //----------------------------------------------------------------------------
  27. ctkCaseInsensitiveString::ctkCaseInsensitiveString(const QString& str)
  28. : str(str)
  29. {
  30. }
  31. //----------------------------------------------------------------------------
  32. ctkCaseInsensitiveString::ctkCaseInsensitiveString(const ctkCaseInsensitiveString& str)
  33. : str(str.str)
  34. {
  35. }
  36. //----------------------------------------------------------------------------
  37. ctkCaseInsensitiveString& ctkCaseInsensitiveString::operator=(const ctkCaseInsensitiveString& str)
  38. {
  39. this->str = str.str;
  40. return *this;
  41. }
  42. //----------------------------------------------------------------------------
  43. bool ctkCaseInsensitiveString::operator==(const ctkCaseInsensitiveString& str) const
  44. {
  45. return this->str.toLower() == str.str.toLower();
  46. }
  47. //----------------------------------------------------------------------------
  48. bool ctkCaseInsensitiveString::operator<(const ctkCaseInsensitiveString& str) const
  49. {
  50. return this->str.toLower() < str.str.toLower();
  51. }
  52. //----------------------------------------------------------------------------
  53. ctkCaseInsensitiveString::operator QString() const
  54. {
  55. return this->str;
  56. }
  57. //----------------------------------------------------------------------------
  58. uint qHash(const ctkCaseInsensitiveString& str)
  59. {
  60. return qHash(QString(str).toLower());
  61. }
  62. //----------------------------------------------------------------------------
  63. QDataStream& operator<<(QDataStream &out, const ctkCaseInsensitiveString& str)
  64. {
  65. out << QString(str);
  66. return out;
  67. }
  68. //----------------------------------------------------------------------------
  69. QDataStream& operator>>(QDataStream &in, ctkCaseInsensitiveString& str)
  70. {
  71. QString inStr;
  72. in >> inStr;
  73. str = inStr;
  74. return in;
  75. }