forked from boostorg/regex
Compare commits
41 Commits
overflow_f
...
svn-branch
Author | SHA1 | Date | |
---|---|---|---|
bba09dc13b | |||
5e951c6620 | |||
35212a4063 | |||
d70f98e658 | |||
18623d00af | |||
30074a601a | |||
4212c0d915 | |||
1297f92b8a | |||
cb5443477b | |||
1012d28c32 | |||
3a15c301db | |||
546dd9f6fb | |||
be28ad44c7 | |||
6eb35e2cf1 | |||
831156d759 | |||
d7d38da27f | |||
31b68369ae | |||
4c105a90a1 | |||
8928c7737e | |||
3704b9c595 | |||
5fdf2752ae | |||
c7dda1b549 | |||
6e9b9a7995 | |||
e5bc36d7c9 | |||
c9d1a42e05 | |||
e32c5d0888 | |||
370c429bd6 | |||
0915f19c03 | |||
37040f4bfd | |||
2cbd1c8882 | |||
37cd93fc82 | |||
b1af72fd23 | |||
299086b99c | |||
07eaac9e0e | |||
71fdd5eb44 | |||
31668ed4be | |||
f72c7518be | |||
2995393609 | |||
872b69bbc4 | |||
55588f72f9 | |||
4a16d482fc |
123
include/boost/regex/v4/regex_cstring.hpp
Normal file
123
include/boost/regex/v4/regex_cstring.hpp
Normal file
@ -0,0 +1,123 @@
|
||||
/*
|
||||
*
|
||||
* Copyright (c) 1998-2002
|
||||
* John Maddock
|
||||
*
|
||||
* Use, modification and distribution are subject to the
|
||||
* Boost Software License, Version 1.0. (See accompanying file
|
||||
* LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* LOCATION: see http://www.boost.org for most recent version.
|
||||
* FILE regex_cstring.hpp
|
||||
* VERSION see <boost/version.hpp>
|
||||
* DESCRIPTION: This is an internal header file, do not include directly.
|
||||
* String support and helper functions, for regular
|
||||
* expression library.
|
||||
*/
|
||||
|
||||
#ifndef BOOST_REGEX_CSTRING_HPP
|
||||
#define BOOST_REGEX_CSTRING_HPP
|
||||
|
||||
#ifndef BOOST_REGEX_CONFIG_HPP
|
||||
#include <boost/regex/config.hpp>
|
||||
#endif
|
||||
|
||||
#include <cstring>
|
||||
|
||||
namespace boost{
|
||||
namespace re_detail{
|
||||
|
||||
//
|
||||
// start by defining some template function aliases for C API functions:
|
||||
//
|
||||
|
||||
template <class charT>
|
||||
std::size_t BOOST_REGEX_CALL re_strlen(const charT *s)
|
||||
{
|
||||
std::size_t len = 0;
|
||||
while(*s)
|
||||
{
|
||||
++s;
|
||||
++len;
|
||||
}
|
||||
return len;
|
||||
}
|
||||
|
||||
inline std::size_t BOOST_REGEX_CALL re_strlen(const char *s)
|
||||
{
|
||||
return std::strlen(s);
|
||||
}
|
||||
|
||||
#ifndef BOOST_NO_WREGEX
|
||||
|
||||
inline std::size_t BOOST_REGEX_CALL re_strlen(const wchar_t *s)
|
||||
{
|
||||
return std::wcslen(s);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#ifndef BOOST_NO_WREGEX
|
||||
BOOST_REGEX_DECL void BOOST_REGEX_CALL re_transform(std::basic_string<wchar_t>& out, const std::basic_string<wchar_t>& in);
|
||||
#endif
|
||||
BOOST_REGEX_DECL void BOOST_REGEX_CALL re_transform(std::string& out, const std::string& in);
|
||||
|
||||
template <class charT>
|
||||
void BOOST_REGEX_CALL re_trunc_primary(std::basic_string<charT>& s)
|
||||
{
|
||||
for(unsigned int i = 0; i < s.size(); ++i)
|
||||
{
|
||||
if(s[i] <= 1)
|
||||
{
|
||||
s.erase(i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
inline char* BOOST_REGEX_CALL re_strcpy(char *s1, const char *s2)
|
||||
{
|
||||
#if defined(__BORLANDC__) && defined(strcpy)
|
||||
return ::strcpy(s1, s2);
|
||||
#else
|
||||
return std::strcpy(s1, s2);
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifndef BOOST_NO_WREGEX
|
||||
|
||||
inline wchar_t* BOOST_REGEX_CALL re_strcpy(wchar_t *s1, const wchar_t *s2)
|
||||
{
|
||||
return std::wcscpy(s1, s2);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
template <class charT>
|
||||
charT* BOOST_REGEX_CALL re_strdup(const charT* p)
|
||||
{
|
||||
charT* buf = new charT[re_strlen(p) + 1];
|
||||
re_strcpy(buf, p);
|
||||
return buf;
|
||||
}
|
||||
|
||||
template <class charT>
|
||||
inline void BOOST_REGEX_CALL re_strfree(charT* p)
|
||||
{
|
||||
delete[] p;
|
||||
}
|
||||
|
||||
} // namespace re_detail
|
||||
} // namespace boost
|
||||
|
||||
#endif // BOOST_REGEX_CSTRING_HPP
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
108
include/boost/regex/v4/regex_kmp.hpp
Normal file
108
include/boost/regex/v4/regex_kmp.hpp
Normal file
@ -0,0 +1,108 @@
|
||||
/*
|
||||
*
|
||||
* Copyright (c) 1998-2002
|
||||
* John Maddock
|
||||
*
|
||||
* Use, modification and distribution are subject to the
|
||||
* Boost Software License, Version 1.0. (See accompanying file
|
||||
* LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* LOCATION: see http://www.boost.org for most recent version.
|
||||
* FILE regex_kmp.hpp
|
||||
* VERSION see <boost/version.hpp>
|
||||
* DESCRIPTION: Provides Knuth Morris Pratt search operations.
|
||||
* Note this is an internal header file included
|
||||
* by regex.hpp, do not include on its own.
|
||||
*/
|
||||
|
||||
#ifndef BOOST_REGEX_KMP_HPP
|
||||
#define BOOST_REGEX_KMP_HPP
|
||||
|
||||
#ifdef BOOST_REGEX_CONFIG_HPP
|
||||
#include <boost/regex/config.hpp>
|
||||
#endif
|
||||
|
||||
|
||||
namespace boost{
|
||||
namespace re_detail{
|
||||
|
||||
#ifdef BOOST_HAS_ABI_HEADERS
|
||||
# include BOOST_ABI_PREFIX
|
||||
#endif
|
||||
|
||||
template <class charT>
|
||||
struct kmp_info
|
||||
{
|
||||
unsigned int size;
|
||||
unsigned int len;
|
||||
const charT* pstr;
|
||||
int kmp_next[1];
|
||||
};
|
||||
|
||||
template <class charT, class Allocator>
|
||||
void kmp_free(kmp_info<charT>* pinfo, const Allocator& a)
|
||||
{
|
||||
typedef typename boost::detail::rebind_allocator<char, Allocator>::type atype;
|
||||
atype(a).deallocate(reinterpret_cast<char*>(pinfo), pinfo->size);
|
||||
}
|
||||
|
||||
template <class iterator, class charT, class Trans, class Allocator>
|
||||
kmp_info<charT>* kmp_compile(iterator first, iterator last, charT, Trans translate, const Allocator& a)
|
||||
{
|
||||
typedef typename boost::detail::rebind_allocator<char, Allocator>::type atype;
|
||||
int i, j, m;
|
||||
i = 0;
|
||||
m = static_cast<int>(::boost::re_detail::distance(first, last));
|
||||
++m;
|
||||
unsigned int size = sizeof(kmp_info<charT>) + sizeof(int)*m + sizeof(charT)*m;
|
||||
--m;
|
||||
//
|
||||
// allocate struct and fill it in:
|
||||
//
|
||||
kmp_info<charT>* pinfo = reinterpret_cast<kmp_info<charT>*>(atype(a).allocate(size));
|
||||
BOOST_REGEX_NOEH_ASSERT(pinfo)
|
||||
pinfo->size = size;
|
||||
pinfo->len = m;
|
||||
charT* p = reinterpret_cast<charT*>(reinterpret_cast<char*>(pinfo) + sizeof(kmp_info<charT>) + sizeof(int)*(m+1));
|
||||
pinfo->pstr = p;
|
||||
while(first != last)
|
||||
{
|
||||
*p = translate(*first);
|
||||
++first;
|
||||
++p;
|
||||
}
|
||||
*p = 0;
|
||||
//
|
||||
// finally do regular kmp compile:
|
||||
//
|
||||
j = pinfo->kmp_next[0] = -1;
|
||||
while (i < m)
|
||||
{
|
||||
while ((j > -1) && (pinfo->pstr[i] != pinfo->pstr[j]))
|
||||
j = pinfo->kmp_next[j];
|
||||
++i;
|
||||
++j;
|
||||
if (pinfo->pstr[i] == pinfo->pstr[j])
|
||||
pinfo->kmp_next[i] = pinfo->kmp_next[j];
|
||||
else
|
||||
pinfo->kmp_next[i] = j;
|
||||
}
|
||||
|
||||
return pinfo;
|
||||
}
|
||||
|
||||
#ifdef BOOST_HAS_ABI_HEADERS
|
||||
# include BOOST_ABI_SUFFIX
|
||||
#endif
|
||||
|
||||
} // namepsace re_detail
|
||||
} // namespace boost
|
||||
|
||||
#endif // BOOST_REGEX_KMP_HPP
|
||||
|
||||
|
||||
|
||||
|
225
include/boost/regex/v4/regex_stack.hpp
Normal file
225
include/boost/regex/v4/regex_stack.hpp
Normal file
@ -0,0 +1,225 @@
|
||||
/*
|
||||
*
|
||||
* Copyright (c) 1998-2002
|
||||
* John Maddock
|
||||
*
|
||||
* Use, modification and distribution are subject to the
|
||||
* Boost Software License, Version 1.0. (See accompanying file
|
||||
* LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* LOCATION: see http://www.boost.org for most recent version.
|
||||
* FILE regex_stack.hpp
|
||||
* VERSION see <boost/version.hpp>
|
||||
* DESCRIPTION: Implements customised internal regex stacks.
|
||||
* Note this is an internal header file included
|
||||
* by regex.hpp, do not include on its own.
|
||||
*/
|
||||
|
||||
#ifndef BOOST_REGEX_STACK_HPP
|
||||
#define BOOST_REGEX_STACK_HPP
|
||||
|
||||
#ifndef BOOST_REGEX_CONFIG_HPP
|
||||
#include <boost/regex/config.hpp>
|
||||
#endif
|
||||
#ifndef BOOST_REGEX_RAW_BUFFER_HPP
|
||||
#include <boost/regex/v4/regex_raw_buffer.hpp>
|
||||
#endif
|
||||
|
||||
namespace boost{
|
||||
namespace re_detail{
|
||||
|
||||
#ifdef BOOST_HAS_ABI_HEADERS
|
||||
# include BOOST_ABI_PREFIX
|
||||
#endif
|
||||
|
||||
//
|
||||
// class jstack
|
||||
// simplified stack optimised for push/peek/pop
|
||||
// operations, we could use std::stack<std::vector<T>> instead...
|
||||
//
|
||||
template <class T, class Allocator = BOOST_DEFAULT_ALLOCATOR(T) >
|
||||
class jstack
|
||||
{
|
||||
public:
|
||||
typedef typename boost::detail::rebind_allocator<unsigned char, Allocator>::type allocator_type;
|
||||
private:
|
||||
typedef typename boost::detail::rebind_allocator<T, Allocator>::type T_alloc_type;
|
||||
typedef typename T_alloc_type::size_type size_type;
|
||||
typedef T value_type;
|
||||
struct node
|
||||
{
|
||||
node* next;
|
||||
T* start; // first item
|
||||
T* end; // last item
|
||||
T* last; // end of storage
|
||||
};
|
||||
|
||||
//
|
||||
// empty base member optimisation:
|
||||
struct data : public allocator_type
|
||||
{
|
||||
padding buf[(sizeof(T) * 16 + sizeof(padding) - 1) / sizeof(padding)];
|
||||
data(const Allocator& a) : allocator_type(a){}
|
||||
};
|
||||
|
||||
data alloc_inst;
|
||||
mutable node* m_stack;
|
||||
mutable node* unused;
|
||||
node base;
|
||||
size_type block_size;
|
||||
|
||||
void BOOST_REGEX_CALL pop_aux()const;
|
||||
void BOOST_REGEX_CALL push_aux();
|
||||
|
||||
public:
|
||||
jstack(size_type n = 64, const Allocator& a = Allocator());
|
||||
|
||||
~jstack();
|
||||
|
||||
node* BOOST_REGEX_CALL get_node()
|
||||
{
|
||||
node* new_stack = reinterpret_cast<node*>(alloc_inst.allocate(sizeof(node) + sizeof(T) * block_size));
|
||||
BOOST_REGEX_NOEH_ASSERT(new_stack)
|
||||
new_stack->last = reinterpret_cast<T*>(new_stack+1);
|
||||
new_stack->start = new_stack->end = new_stack->last + block_size;
|
||||
new_stack->next = 0;
|
||||
return new_stack;
|
||||
}
|
||||
|
||||
bool BOOST_REGEX_CALL empty()
|
||||
{
|
||||
return (m_stack->start == m_stack->end) && (m_stack->next == 0);
|
||||
}
|
||||
|
||||
bool BOOST_REGEX_CALL good()
|
||||
{
|
||||
return (m_stack->start != m_stack->end) || (m_stack->next != 0);
|
||||
}
|
||||
|
||||
T& BOOST_REGEX_CALL peek()
|
||||
{
|
||||
if(m_stack->start == m_stack->end)
|
||||
pop_aux();
|
||||
return *m_stack->end;
|
||||
}
|
||||
|
||||
const T& BOOST_REGEX_CALL peek()const
|
||||
{
|
||||
if(m_stack->start == m_stack->end)
|
||||
pop_aux();
|
||||
return *m_stack->end;
|
||||
}
|
||||
|
||||
void BOOST_REGEX_CALL pop()
|
||||
{
|
||||
if(m_stack->start == m_stack->end)
|
||||
pop_aux();
|
||||
::boost::re_detail::pointer_destroy(m_stack->end);
|
||||
++(m_stack->end);
|
||||
}
|
||||
|
||||
void BOOST_REGEX_CALL pop(T& t)
|
||||
{
|
||||
if(m_stack->start == m_stack->end)
|
||||
pop_aux();
|
||||
t = *m_stack->end;
|
||||
::boost::re_detail::pointer_destroy(m_stack->end);
|
||||
++(m_stack->end);
|
||||
}
|
||||
|
||||
void BOOST_REGEX_CALL push(const T& t)
|
||||
{
|
||||
if(m_stack->end == m_stack->last)
|
||||
push_aux();
|
||||
--(m_stack->end);
|
||||
pointer_construct(m_stack->end, t);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
template <class T, class Allocator>
|
||||
jstack<T, Allocator>::jstack(size_type n, const Allocator& a)
|
||||
: alloc_inst(a)
|
||||
{
|
||||
unused = 0;
|
||||
block_size = n;
|
||||
m_stack = &base;
|
||||
base.last = reinterpret_cast<T*>(alloc_inst.buf);
|
||||
base.end = base.start = base.last + 16;
|
||||
base.next = 0;
|
||||
}
|
||||
|
||||
template <class T, class Allocator>
|
||||
void BOOST_REGEX_CALL jstack<T, Allocator>::push_aux()
|
||||
{
|
||||
// make sure we have spare space on TOS:
|
||||
register node* new_node;
|
||||
if(unused)
|
||||
{
|
||||
new_node = unused;
|
||||
unused = new_node->next;
|
||||
new_node->next = m_stack;
|
||||
m_stack = new_node;
|
||||
}
|
||||
else
|
||||
{
|
||||
new_node = get_node();
|
||||
new_node->next = m_stack;
|
||||
m_stack = new_node;
|
||||
}
|
||||
}
|
||||
|
||||
template <class T, class Allocator>
|
||||
void BOOST_REGEX_CALL jstack<T, Allocator>::pop_aux()const
|
||||
{
|
||||
// make sure that we have a valid item
|
||||
// on TOS:
|
||||
BOOST_ASSERT(m_stack->next);
|
||||
register node* p = m_stack;
|
||||
m_stack = p->next;
|
||||
p->next = unused;
|
||||
unused = p;
|
||||
}
|
||||
|
||||
template <class T, class Allocator>
|
||||
jstack<T, Allocator>::~jstack()
|
||||
{
|
||||
node* condemned;
|
||||
while(good())
|
||||
pop();
|
||||
while(unused)
|
||||
{
|
||||
condemned = unused;
|
||||
unused = unused->next;
|
||||
alloc_inst.deallocate(reinterpret_cast<unsigned char*>(condemned), sizeof(node) + sizeof(T) * block_size);
|
||||
}
|
||||
while(m_stack != &base)
|
||||
{
|
||||
condemned = m_stack;
|
||||
m_stack = m_stack->next;
|
||||
alloc_inst.deallocate(reinterpret_cast<unsigned char*>(condemned), sizeof(node) + sizeof(T) * block_size);
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef BOOST_HAS_ABI_HEADERS
|
||||
# include BOOST_ABI_SUFFIX
|
||||
#endif
|
||||
|
||||
} // namespace re_detail
|
||||
} // namespace boost
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user