Browse Source

Removed c_string from interface

master
Artyom Beilis 13 years ago
parent
commit
3d6c6097ff
4 changed files with 130 additions and 94 deletions
  1. +2
    -94
      cppcms/xss.h
  2. +125
    -0
      private/c_string.h
  3. +2
    -0
      src/xss.cpp
  4. +1
    -0
      tests/xss_test.cpp

+ 2
- 94
cppcms/xss.h View File

@@ -39,100 +39,8 @@ namespace cppcms {
/// \cond INTERNAL
namespace details {
class c_string {
public:
typedef char const *const_iterator;
char const *begin() const
{
return begin_;
}
char const *end() const
{
return end_;
}
c_string(char const *s)
{
begin_=s;
end_=s+strlen(s);
}

c_string(char const *b,char const *e) : begin_(b), end_(e) {}

c_string() : begin_(0),end_(0) {}

bool compare(c_string const &other) const
{
return std::lexicographical_compare(begin_,end_,other.begin_,other.end_,std::char_traits<char>::lt);
}

bool icompare(c_string const &other) const
{
return std::lexicographical_compare(begin_,end_,other.begin_,other.end_,ilt);
}

explicit c_string(std::string const &other)
{
container_ = other;
begin_ = container_.c_str();
end_ = begin_ + container_.size();
}
c_string(c_string const &other)
{
if(other.begin_ == other.end_) {
begin_ = end_ = 0;
}
else if(other.container_.empty()) {
begin_ = other.begin_;
end_ = other.end_;
}
else {
container_ = other.container_;
begin_ = container_.c_str();
end_ = begin_ + container_.size();
}
}
c_string const &operator=(c_string const &other)
{
if(other.begin_ == other.end_) {
begin_ = end_ = 0;
}
else if(other.container_.empty()) {
begin_ = other.begin_;
end_ = other.end_;
}
else {
container_ = other.container_;
begin_ = container_.c_str();
end_ = begin_ + container_.size();
}
return *this;
}

private:
static bool ilt(char left,char right)
{
unsigned char l = tolower(left);
unsigned char r = tolower(right);
return l < r;
}
static char tolower(char c)
{
if('A' <= c && c<='Z')
return c-'A' + 'a';
return c;
}
char const *begin_;
char const *end_;
std::string container_;
};
} // details
class c_string;
}
struct basic_rules_holder;
/// \endcond


+ 125
- 0
private/c_string.h View File

@@ -0,0 +1,125 @@
///////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2008-2010 Artyom Beilis (Tonkikh) <artyomtnk@yahoo.com>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//
///////////////////////////////////////////////////////////////////////////////
#ifndef CPPCMS_C_STRING_H
#define CPPCMS_C_STRING_H

#include <string.h>
#include <string>

namespace cppcms {
namespace xss {
namespace details {
class c_string {
public:
typedef char const *const_iterator;
char const *begin() const
{
return begin_;
}
char const *end() const
{
return end_;
}
c_string(char const *s)
{
begin_=s;
end_=s+strlen(s);
}

c_string(char const *b,char const *e) : begin_(b), end_(e) {}

c_string() : begin_(0),end_(0) {}

bool compare(c_string const &other) const
{
return std::lexicographical_compare(begin_,end_,other.begin_,other.end_,std::char_traits<char>::lt);
}

bool icompare(c_string const &other) const
{
return std::lexicographical_compare(begin_,end_,other.begin_,other.end_,ilt);
}

explicit c_string(std::string const &other)
{
container_ = other;
begin_ = container_.c_str();
end_ = begin_ + container_.size();
}
c_string(c_string const &other)
{
if(other.begin_ == other.end_) {
begin_ = end_ = 0;
}
else if(other.container_.empty()) {
begin_ = other.begin_;
end_ = other.end_;
}
else {
container_ = other.container_;
begin_ = container_.c_str();
end_ = begin_ + container_.size();
}
}
c_string const &operator=(c_string const &other)
{
if(other.begin_ == other.end_) {
begin_ = end_ = 0;
}
else if(other.container_.empty()) {
begin_ = other.begin_;
end_ = other.end_;
}
else {
container_ = other.container_;
begin_ = container_.c_str();
end_ = begin_ + container_.size();
}
return *this;
}

private:
static bool ilt(char left,char right)
{
unsigned char l = tolower(left);
unsigned char r = tolower(right);
return l < r;
}
static char tolower(char c)
{
if('A' <= c && c<='Z')
return c-'A' + 'a';
return c;
}
char const *begin_;
char const *end_;
std::string container_;
};
} // details
} // xss
} // cppcms

#endif

+ 2
- 0
src/xss.cpp View File

@@ -29,6 +29,8 @@

#include <iostream>

#include "c_string.h"

namespace cppcms { namespace xss {

using namespace details;


+ 1
- 0
tests/xss_test.cpp View File

@@ -19,6 +19,7 @@
#include <cppcms/xss.h>
#include <booster/locale/encoding.h>
#include "test.h"
#include "c_string.h"
#include <iostream>
#include <string.h>



Loading…
Cancel
Save