Author: hyperion
Date: Mon Jun 1 19:14:37 2009
New Revision: 41234
URL:
http://svn.reactos.org/svn/reactos?rev=41234&view=rev
Log:
added include/reactos/kjk
added include/reactos/kjk/argv_parser.h
added include/reactos/kjk/null_output_iterator.h
added include/reactos/kjk/stringz_iterator.h
Some internal libraries I use in code I haven't committed yet
Added:
trunk/reactos/include/reactos/kjk/ (with props)
trunk/reactos/include/reactos/kjk/argv_parser.h (with props)
trunk/reactos/include/reactos/kjk/null_output_iterator.h (with props)
trunk/reactos/include/reactos/kjk/stringz_iterator.h (with props)
Propchange: trunk/reactos/include/reactos/kjk/
------------------------------------------------------------------------------
--- bugtraq:logregex (added)
+++ bugtraq:logregex Mon Jun 1 19:14:37 2009
@@ -1,0 +1,2 @@
+([Ii]ssue|[Bb]ug)s? #?(\d+)(,? ?#?(\d+))*(,? ?(and |or )?#?(\d+))?
+(\d+)
Propchange: trunk/reactos/include/reactos/kjk/
------------------------------------------------------------------------------
bugtraq:message = See issue #%BUGID% for more details.
Propchange: trunk/reactos/include/reactos/kjk/
------------------------------------------------------------------------------
bugtraq:url =
http://www.reactos.org/bugzilla/show_bug.cgi?id=%BUGID%
Propchange: trunk/reactos/include/reactos/kjk/
------------------------------------------------------------------------------
tsvn:logminsize = 10
Added: trunk/reactos/include/reactos/kjk/argv_parser.h
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/include/reactos/kjk/argv_p…
==============================================================================
--- trunk/reactos/include/reactos/kjk/argv_parser.h (added)
+++ trunk/reactos/include/reactos/kjk/argv_parser.h [iso-8859-1] Mon Jun 1 19:14:37 2009
@@ -1,0 +1,159 @@
+/*
+ Copyright (c) 2009 KJK::Hyperion
+
+ Permission is hereby granted, free of charge, to any person obtaining a
+ copy of this software and associated documentation files (the "Software"),
+ to deal in the Software without restriction, including without limitation
+ the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ and/or sell copies of the Software, and to permit persons to whom the
+ Software is furnished to do so, subject to the following conditions:
+
+ The above copyright notice and this permission notice shall be included in
+ all copies or substantial portions of the Software.
+
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ DEALINGS IN THE SOFTWARE.
+*/
+
+#ifndef KJK_ARGV_PARSER_H_
+#define KJK_ARGV_PARSER_H_
+
+#include <iterator>
+#include <kjk/null_output_iterator.h>
+
+namespace kjk
+{
+ namespace details
+ {
+ template<class Traits>
+ bool is_separator(typename Traits::int_type c)
+ {
+ return Traits::eq_int_type(c, ' ') || Traits::eq_int_type(c, '\t');
+ }
+ }
+
+ template<class Elem, class Traits, class InIter, class OutIter>
+ InIter copy_argument(InIter cur, InIter end, OutIter arg)
+ {
+ typename Traits::int_type c;
+ bool quoting = false;
+
+ while(cur != end)
+ {
+ c = Traits::to_int_type(*cur);
+
+ if(!details::is_separator<Traits>(c))
+ break;
+
+ ++ cur;
+ }
+
+ while(cur != end)
+ {
+ typedef typename std::iterator_traits<InIter>::difference_type difference_type;
+ difference_type backslashes(0);
+
+ do
+ {
+ c = Traits::to_int_type(*cur);
+ ++ cur;
+
+ if(Traits::eq_int_type(c, '\\'))
+ ++ backslashes;
+ else
+ break;
+ }
+ while(cur != end);
+
+ if(Traits::eq_int_type(c, '"'))
+ {
+ // c == '"'
+
+ if((backslashes % 2) == 0)
+ {
+ // 2N backslashes + "" in quote = N backslashes, literal "
+ if(quoting && cur != end &&
Traits::eq_int_type(Traits::to_int_type(*cur), '"'))
+ {
+ c = '"';
+ ++ cur;
+ }
+ // 2N backslashes + " = N backslashes, toggle quoting
+ else
+ {
+ quoting = !quoting;
+ c = Traits::eof();
+ }
+
+ }
+ // 2N+1 backslashes + " = N backslashes, literal "
+
+ backslashes /= 2;
+ }
+
+ // Flush backslashes
+ for(difference_type i = 0; i < backslashes; ++ i)
+ *arg ++ = Traits::to_char_type('\\');
+
+ // Handle current character, unless it was a special quote
+ if(c != Traits::eof())
+ {
+ if(details::is_separator<Traits>(c) && !quoting)
+ break;
+ else
+ *arg ++ = Traits::to_char_type(c);
+ }
+ }
+
+ while(cur != end)
+ {
+ c = Traits::to_int_type(*cur);
+
+ if(!details::is_separator<Traits>(c))
+ break;
+
+ ++ cur;
+ }
+
+ return cur;
+ }
+
+ template<class InIter, class OutIter>
+ InIter copy_argument(InIter cur, InIter end, OutIter arg)
+ {
+ return copy_argument
+ <
+ typename std::iterator_traits<InIter>::value_type,
+ typename std::char_traits<typename
std::iterator_traits<InIter>::value_type>,
+ InIter,
+ OutIter
+ >
+ (cur, end, arg);
+ }
+
+ template<class Elem, class Traits, class InIter>
+ InIter skip_argument(InIter cur, InIter end)
+ {
+ return copy_argument(cur, end, null_output_iterator<Elem>());
+ }
+
+ template<class InIter>
+ InIter skip_argument(InIter cur, InIter end)
+ {
+ return copy_argument
+ <
+ typename std::iterator_traits<InIter>::value_type,
+ typename std::char_traits<typename
std::iterator_traits<InIter>::value_type>,
+ InIter
+ >
+ (cur, end, null_output_iterator<typename
std::iterator_traits<InIter>::value_type>());
+ }
+}
+
+#endif
+
+// EOF
Propchange: trunk/reactos/include/reactos/kjk/argv_parser.h
------------------------------------------------------------------------------
svn:eol-style = native
Added: trunk/reactos/include/reactos/kjk/null_output_iterator.h
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/include/reactos/kjk/null_o…
==============================================================================
--- trunk/reactos/include/reactos/kjk/null_output_iterator.h (added)
+++ trunk/reactos/include/reactos/kjk/null_output_iterator.h [iso-8859-1] Mon Jun 1
19:14:37 2009
@@ -1,0 +1,51 @@
+/*
+ Copyright (c) 2009 KJK::Hyperion
+
+ Permission is hereby granted, free of charge, to any person obtaining a
+ copy of this software and associated documentation files (the "Software"),
+ to deal in the Software without restriction, including without limitation
+ the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ and/or sell copies of the Software, and to permit persons to whom the
+ Software is furnished to do so, subject to the following conditions:
+
+ The above copyright notice and this permission notice shall be included in
+ all copies or substantial portions of the Software.
+
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ DEALINGS IN THE SOFTWARE.
+*/
+
+#ifndef KJK_NULL_OUTPUT_ITERATOR_H_
+#define KJK_NULL_OUTPUT_ITERATOR_H_
+
+#include <cstddef>
+#include <iterator>
+
+namespace kjk
+{
+ template<class Type>
+ struct null_output_reference
+ {
+ const Type& operator=(const Type& x) { return x; }
+ };
+
+ template<class Type, class Distance = std::ptrdiff_t, class Pointer = Type *>
+ struct null_output_iterator: public std::iterator<std::output_iterator_tag, Type,
Distance, Pointer, null_output_reference<Type> >
+ {
+ null_output_iterator() {}
+ null_output_iterator(const null_output_iterator&) {}
+ const null_output_iterator& operator=(const null_output_iterator&) { return
*this; }
+ const null_output_iterator& operator++() { return *this; }
+ null_output_iterator operator++(int) { return null_output_iterator(); }
+ null_output_reference<Type> operator*() { return
null_output_reference<Type>(); }
+ };
+}
+
+#endif
+
+// EOF
Propchange: trunk/reactos/include/reactos/kjk/null_output_iterator.h
------------------------------------------------------------------------------
svn:eol-style = native
Added: trunk/reactos/include/reactos/kjk/stringz_iterator.h
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/include/reactos/kjk/string…
==============================================================================
--- trunk/reactos/include/reactos/kjk/stringz_iterator.h (added)
+++ trunk/reactos/include/reactos/kjk/stringz_iterator.h [iso-8859-1] Mon Jun 1 19:14:37
2009
@@ -1,0 +1,130 @@
+/*
+ Copyright (c) 2009 KJK::Hyperion
+
+ Permission is hereby granted, free of charge, to any person obtaining a
+ copy of this software and associated documentation files (the "Software"),
+ to deal in the Software without restriction, including without limitation
+ the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ and/or sell copies of the Software, and to permit persons to whom the
+ Software is furnished to do so, subject to the following conditions:
+
+ The above copyright notice and this permission notice shall be included in
+ all copies or substantial portions of the Software.
+
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ DEALINGS IN THE SOFTWARE.
+*/
+
+#ifndef KJK_STRINGZ_ITERATOR_H_
+#define KJK_STRINGZ_ITERATOR_H_
+
+#include <cstddef>
+#include <iterator>
+
+namespace kjk
+{
+ template<class Type, class Traits = std::char_traits<Type> > class
stringz_iterator;
+
+ template<class CharT> stringz_iterator<CharT> stringz_begin(const CharT *);
+ template<class Traits, class CharT> stringz_iterator<CharT, Traits>
stringz_begin(const CharT *);
+
+ template<class CharT> stringz_iterator<CharT> stringz_end(const CharT *);
+ template<class Traits, class CharT> stringz_iterator<CharT, Traits>
stringz_end(const CharT *);
+
+ template<class Type, class Traits>
+ class stringz_iterator: public std::iterator<std::forward_iterator_tag, Type,
std::ptrdiff_t, const Type *, const Type&>
+ {
+ private:
+ template<class CharT2> friend stringz_iterator<CharT2> stringz_begin(const
CharT2 *);
+ template<class Traits2, class CharT2> friend stringz_iterator<CharT2,
Traits2> stringz_begin(const CharT2 *);
+
+ template<class CharT2> friend stringz_iterator<CharT2> stringz_end(const
CharT2 *);
+ template<class Traits2, class CharT2> friend stringz_iterator<CharT2,
Traits2> stringz_end(const CharT2 *);
+
+ // FIXME: this sucks because GCC sucks
+ typedef const Type * pointer_;
+ typedef const Type& reference_;
+
+ pointer_ m_p;
+
+ static pointer_ set_pointer(pointer_ p)
+ {
+ if(p != 0 && Traits::eq_int_type(Traits::to_int_type(*p), 0))
+ return 0;
+ else
+ return p;
+ }
+
+ explicit stringz_iterator(pointer_ p): m_p(set_pointer(p)) { }
+
+ public:
+ stringz_iterator(): m_p() {}
+ stringz_iterator(const stringz_iterator& That): m_p(set_pointer(That.m_p)) { }
+
+ const stringz_iterator& operator=(const stringz_iterator& That)
+ {
+ m_p = set_pointer(That.m_p);
+ return *this;
+ }
+
+ bool operator==(const stringz_iterator& That) const
+ {
+ return m_p == That.m_p;
+ }
+
+ bool operator!=(const stringz_iterator& That) const
+ {
+ return m_p != That.m_p;
+ }
+
+ reference_ operator*() const { return *m_p; }
+
+ const stringz_iterator& operator++()
+ {
+ m_p = set_pointer(m_p + 1);
+ return *this;
+ }
+
+ stringz_iterator operator++(int)
+ {
+ stringz_iterator oldValue(*this);
+ ++ (*this);
+ return oldValue;
+ }
+
+ pointer_ base() const { return m_p; }
+ };
+
+ template<class CharT>
+ stringz_iterator<CharT> stringz_begin(const CharT * p)
+ {
+ return stringz_iterator<CharT>(p);
+ }
+
+ template<class Traits, class CharT>
+ stringz_iterator<CharT> stringz_begin(const CharT * p)
+ {
+ return stringz_iterator<CharT, Traits>(p);
+ }
+
+ template<class CharT>
+ stringz_iterator<CharT> stringz_end(const CharT *)
+ {
+ return stringz_iterator<CharT>(0);
+ }
+
+ template<class Traits, class CharT>
+ stringz_iterator<CharT> stringz_end(const CharT *)
+ {
+ return stringz_iterator<CharT, Traits>(0);
+ }
+}
+
+#endif
+
+// EOF
Propchange: trunk/reactos/include/reactos/kjk/stringz_iterator.h
------------------------------------------------------------------------------
svn:eol-style = native