ChipMaster's trial hacks on C++CMS starting with v1.2.1. Not sure I'll follow on with the v2 since it looks to be breaking and mostly frivolous.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

115 lines
2.6 KiB

  1. ///////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright (C) 2008-2012 Artyom Beilis (Tonkikh) <artyomtnk@yahoo.com>
  4. //
  5. // See accompanying file COPYING.TXT file for licensing details.
  6. //
  7. ///////////////////////////////////////////////////////////////////////////////
  8. #ifndef CPPCMS_C_STRING_H
  9. #define CPPCMS_C_STRING_H
  10. #include <string.h>
  11. #include <string>
  12. namespace cppcms {
  13. namespace xss {
  14. namespace details {
  15. class c_string {
  16. public:
  17. typedef char const *const_iterator;
  18. char const *begin() const
  19. {
  20. return begin_;
  21. }
  22. char const *end() const
  23. {
  24. return end_;
  25. }
  26. c_string(char const *s)
  27. {
  28. begin_=s;
  29. end_=s+strlen(s);
  30. }
  31. c_string(char const *b,char const *e) : begin_(b), end_(e) {}
  32. c_string() : begin_(0),end_(0) {}
  33. bool compare(c_string const &other) const
  34. {
  35. return std::lexicographical_compare(begin_,end_,other.begin_,other.end_,std::char_traits<char>::lt);
  36. }
  37. bool icompare(c_string const &other) const
  38. {
  39. return std::lexicographical_compare(begin_,end_,other.begin_,other.end_,ilt);
  40. }
  41. explicit c_string(std::string const &other)
  42. {
  43. container_ = other;
  44. begin_ = container_.c_str();
  45. end_ = begin_ + container_.size();
  46. }
  47. c_string(c_string const &other)
  48. {
  49. if(other.begin_ == other.end_) {
  50. begin_ = end_ = 0;
  51. }
  52. else if(other.container_.empty()) {
  53. begin_ = other.begin_;
  54. end_ = other.end_;
  55. }
  56. else {
  57. container_ = other.container_;
  58. begin_ = container_.c_str();
  59. end_ = begin_ + container_.size();
  60. }
  61. }
  62. c_string const &operator=(c_string const &other)
  63. {
  64. if(other.begin_ == other.end_) {
  65. begin_ = end_ = 0;
  66. }
  67. else if(other.container_.empty()) {
  68. begin_ = other.begin_;
  69. end_ = other.end_;
  70. }
  71. else {
  72. container_ = other.container_;
  73. begin_ = container_.c_str();
  74. end_ = begin_ + container_.size();
  75. }
  76. return *this;
  77. }
  78. private:
  79. static bool ilt(char left,char right)
  80. {
  81. unsigned char l = tolower(left);
  82. unsigned char r = tolower(right);
  83. return l < r;
  84. }
  85. static char tolower(char c)
  86. {
  87. if('A' <= c && c<='Z')
  88. return c-'A' + 'a';
  89. return c;
  90. }
  91. char const *begin_;
  92. char const *end_;
  93. std::string container_;
  94. };
  95. } // details
  96. } // xss
  97. } // cppcms
  98. #endif