From 93e2ebb1e771bf5a4bfd250def96f61b3df91b04 Mon Sep 17 00:00:00 2001 From: patacongo Date: Fri, 2 Nov 2012 16:35:37 +0000 Subject: More uClibc++ build fixes git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@5299 42af7a65-404d-4744-a932-0658087f49c3 --- misc/uClibc++/include/uClibc++/deque | 1912 ++++++++++++---------- misc/uClibc++/include/uClibc++/string | 1981 +++++++++++++---------- misc/uClibc++/libxx/uClibc++/Make.defs | 17 +- misc/uClibc++/libxx/uClibc++/eh_terminate.cxx | 4 - misc/uClibc++/libxx/uClibc++/func_exception.cxx | 16 +- misc/uClibc++/libxx/uClibc++/stdexcept.cxx | 93 +- misc/uClibc++/libxx/uClibc++/string.cxx | 128 +- 7 files changed, 2311 insertions(+), 1840 deletions(-) (limited to 'misc') diff --git a/misc/uClibc++/include/uClibc++/deque b/misc/uClibc++/include/uClibc++/deque index ff07ab51c..19be5c8bb 100644 --- a/misc/uClibc++/include/uClibc++/deque +++ b/misc/uClibc++/include/uClibc++/deque @@ -1,22 +1,21 @@ -/* Copyright (C) 2004 Garrett A. Kajmowicz - This file is part of the uClibc++ Library. - This library 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 2.1 of the License, or (at your option) any later version. - - This library 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 library; if not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +/* Copyright (C) 2004 Garrett A. Kajmowicz + This file is part of the uClibc++ Library. + This library 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 2.1 of the License, or (at your option) any later version. + + This library 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 library; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ - #include #include #include @@ -26,854 +25,1039 @@ #ifndef __STD_HEADER_DEQUE #define __STD_HEADER_DEQUE - -namespace std{ - template > class deque; - template bool operator==(const deque& x, const deque& y); - template bool operator< (const deque& x, const deque& y); - template bool operator!=(const deque& x, const deque& y); - template bool operator> (const deque& x, const deque& y); - template bool operator>=(const deque& x, const deque& y); - template bool operator<=(const deque& x, const deque& y); - template void swap(deque& x, deque& y); - - template class _UCXXEXPORT deque { - public: - friend bool operator==<>(const deque& x, const deque& y); - friend class deque_iter; - friend class deque_citer; - class deque_iter; - class deque_citer; - - typedef typename Allocator::reference reference; - typedef typename Allocator::const_reference const_reference; - typedef deque_iter iterator; - typedef deque_citer const_iterator; - typedef typename Allocator::size_type size_type; - typedef typename Allocator::difference_type difference_type; - typedef T value_type; - typedef Allocator allocator_type; - typedef typename Allocator::pointer pointer; - typedef typename Allocator::const_pointer const_pointer; - typedef std::reverse_iterator reverse_iterator; - typedef std::reverse_iterator const_reverse_iterator; - - explicit deque(const Allocator& al = Allocator()); - explicit deque(size_type n, const T& value = T(), const Allocator& al = Allocator()); - template deque(InputIterator first, InputIterator last, const Allocator& = Allocator()); - deque(const deque& x); - ~deque(); - - deque& operator=(const deque& x); - template void assign(InputIterator first, InputIterator last); - template void assign(Size n, const U& u = U()); - allocator_type get_allocator() const; - - iterator begin(); - const_iterator begin() const; - iterator end(); - const_iterator end() const; - reverse_iterator rbegin(); - const_reverse_iterator rbegin() const; - reverse_iterator rend(); - const_reverse_iterator rend() const; - - size_type size() const; - size_type max_size() const; - void resize(size_type sz, T c = T()); - bool empty() const; - - reference operator[](size_type n); - const_reference operator[](size_type n) const; - reference at(size_type n); - const_reference at(size_type n) const; - reference front(); - const_reference front() const; - reference back(); - const_reference back() const; - - void push_front(const T& x); - void push_back(const T& x); - iterator insert(iterator position, const T& x = T()); - void insert(iterator position, size_type n, const T& x); - template void insert (iterator position, InputIterator first, InputIterator last); - void pop_front(); - void pop_back(); - - iterator erase(iterator position); - iterator erase(iterator first, iterator last); - void swap(deque&); - void clear(); - - protected: - void reserve(size_type n); - inline size_type array_element(size_type deque_element) const{ - if(deque_element < (data_size - first_element)){ - return first_element + deque_element; - } - return deque_element - (data_size - first_element); - } - inline size_type first_subtract(size_type sub_size) const{ - if(sub_size > first_element){ - return (data_size - first_element) - sub_size; - } - return first_element - sub_size; - } - - T * data; - size_type data_size; //Physical size of array - size_type elements; //Elements in array - size_type first_element; //Element number of array 0..n - size_type last_element; //Element number of array 0..n - Allocator a; - - }; - - - template class _UCXXEXPORT deque::deque_iter - : public std::iterator< - random_access_iterator_tag, - T, - typename Allocator::difference_type, - typename Allocator::pointer, - typename Allocator::reference - > - { - friend class deque; - protected: - deque * container; - typename Allocator::size_type element; - - public: - deque_iter() : container(0), element(0) { } - deque_iter(const deque_iter & d) : container (d.container), element(d.element) { } - deque_iter(deque * c, typename Allocator::size_type e) - : container(c), element(e) - { - return; - } - ~deque_iter() { } - deque_iter & operator=(const deque_iter & d){ - container = d.container; - element = d.element; - return *this; - } - T & operator*(){ - return container->data[container->array_element(element)]; - } - T * operator->(){ - return container->data + container->array_element(element); - } - const T & operator*() const{ - return container->data[container->array_element(element)]; - } - const T * operator->() const{ - return container->data + container->array_element(element); - } - bool operator==(const deque_iter & d) const{ - if(container == d.container && element == d.element){ - return true; - } - return false; - } - bool operator==(const deque_citer & d) const{ - if(container == d.container && element == d.element){ - return true; - } - return false; - } - bool operator!=(const deque_iter & d) const{ - if(container != d.container || element != d.element){ - return true; - } - return false; - } - bool operator!=(const deque_citer & d) const{ - if(container != d.container || element != d.element){ - return true; - } - return false; - } - bool operator<(const deque_iter & d) const{ - if(element < d.element){ - return true; - } - return false; - } - bool operator<(const deque_citer & d) const{ - if(element < d.element){ - return true; - } - return false; - } - bool operator<=(const deque_iter & d) const{ - if(element <= d.element){ - return true; - } - return false; - } - bool operator<=(const deque_citer & d) const{ - if(element <= d.element){ - return true; - } - return false; - } - bool operator>(const deque_iter & d) const{ - if(element > d.element){ - return true; - } - return false; - } - bool operator>(const deque_citer & d) const{ - if(element > d.element){ - return true; - } - return false; - } - bool operator>=(const deque_iter & d) const{ - if(element >= d.element){ - return true; - } - return false; - } - bool operator>=(const deque_citer & d) const{ - if(element >= d.element){ - return true; - } - return false; - } - deque_iter & operator++(){ - ++element; - return *this; - } - deque_iter operator++(int){ - deque_iter temp(container, element); - ++element; - return temp; - } - deque_iter operator+(typename Allocator::size_type n){ - deque_iter temp(container, element + n); - return temp; - } - deque_iter & operator+=(typename Allocator::size_type n){ - element += n; - return *this; - } - deque_iter & operator--(){ - --element; - return *this; - } - deque_iter operator--(int){ - deque_iter temp(container, element); - --element; - return temp; - } - deque_iter operator-(typename Allocator::size_type n){ - deque_iter temp(container, element - n); - return temp; - } - deque_iter & operator-=(typename Allocator::size_type n){ - element -= n; - return *this; - } - typename Allocator::size_type operator-(const deque_iter & d){ - return element - d.element; - } - - }; - - template class _UCXXEXPORT deque::deque_citer - : public std::iterator< - random_access_iterator_tag, - T, - typename Allocator::difference_type, - typename Allocator::const_pointer, - typename Allocator::const_reference - > - { - friend class deque; - protected: - const deque * container; - typename Allocator::size_type element; - - public: - deque_citer() : container(0), element(0) { } - deque_citer(const deque_citer & d) : container (d.container), element(d.element) { } - deque_citer(const deque_iter & d) : container (d.container), element(d.element) { } - deque_citer(const deque * c, typename Allocator::size_type e) - : container(c), element(e) - { - return; - } - ~deque_citer() { } - deque_citer & operator=(const deque_iter & d){ - container = d.container; - element = d.element; - return *this; - } - const T & operator*() const{ - return container->data[container->array_element(element)]; - } - const T * operator->() const{ - return container->data + container->array_element(element); - } - bool operator==(const deque_citer & d) const{ - if(container == d.container && element == d.element){ - return true; - } - return false; - } - bool operator==(const deque_iter & d) const{ - if(container == d.container && element == d.element){ - return true; - } - return false; - } - bool operator!=(const deque_citer & d) const{ - if(container != d.container || element != d.element){ - return true; - } - return false; - } - bool operator!=(const deque_iter & d) const{ - if(container != d.container || element != d.element){ - return true; - } - return false; - } - bool operator<(const deque_citer & d) const{ - if(element < d.element){ - return true; - } - return false; - } - bool operator<(const deque_iter & d) const{ - if(element < d.element){ - return true; - } - return false; - } - bool operator<=(const deque_citer & d) const{ - if(element <= d.element){ - return true; - } - return false; - } - bool operator<=(const deque_iter & d) const{ - if(element <= d.element){ - return true; - } - return false; - } - bool operator>(const deque_citer & d) const{ - if(element > d.element){ - return true; - } - return false; - } - bool operator>(const deque_iter & d) const{ - if(element > d.element){ - return true; - } - return false; - } - bool operator>=(const deque_citer & d){ - if(element >= d.element){ - return true; - } - return false; - } - bool operator>=(const deque_iter & d){ - if(element >= d.element){ - return true; - } - return false; - } - deque_citer & operator++(){ - ++element; - return *this; - } - deque_citer operator++(int){ - deque_citer temp(container, element); - ++element; - return temp; - } - deque_citer operator+(typename Allocator::size_type n){ - deque_citer temp(container, element + n); - return temp; - } - deque_citer & operator+=(typename Allocator::size_type n){ - element += n; - return *this; - } - deque_citer & operator--(){ - --element; - return *this; - } - deque_citer operator--(int){ - deque_citer temp(container, element); - --element; - return temp; - } - deque_citer operator-(typename Allocator::size_type n){ - deque_citer temp(container, element - n); - return temp; - } - deque_citer & operator-=(typename Allocator::size_type n){ - element -= n; - return *this; - } - typename Allocator::size_type operator-(const deque_citer & d){ - return element - d.element; - } - - }; - - template deque::deque(const Allocator& al) - : data(0), - data_size(0), elements(0), first_element(0), last_element(0), a(al) - { - data_size = __UCLIBCXX_STL_BUFFER_SIZE__; - data = a.allocate(data_size); - first_element = data_size /2; - last_element = first_element; - } - - - template deque::deque( - size_type n, const T& value, const Allocator& al) - : data(0), - elements(n), first_element(0), last_element(0), a(al) - { - data_size = elements + __UCLIBCXX_STL_BUFFER_SIZE__; - data = a.allocate(data_size); - first_element = (data_size - elements) / 2; - last_element = first_element; - - for(n=first_element ; n < last_element; ++n ){ - a.construct(data+n, value); - } - } - - - template template - deque::deque(InputIterator first, InputIterator last, const Allocator& al) - : data(0), - data_size(0), elements(0), first_element(0), last_element(0), a(al) - { - data_size = __UCLIBCXX_STL_BUFFER_SIZE__; - data = a.allocate(data_size); - first_element = data_size / 4; //Note sure how big, but let's add a little space... - last_element = first_element; - while(first != last){ - push_back(*first); - ++first; - } - } - - - template deque::deque(const deque& x) - : data(0), - elements(0), first_element(0), last_element(0), a(x.a) - { - data_size = x.elements + __UCLIBCXX_STL_BUFFER_SIZE__; - data = a.allocate(data_size); - first_element = (data_size - x.elements) / 2; - last_element = first_element; - for(size_type i=0; i < x.elements; ++i){ - push_back(x[i]); - } - } - - - template deque::~deque(){ - clear(); - a.deallocate(data, data_size); - } - - template deque& deque:: - operator=(const deque& x) - { - if(&x == this){ - return *this; - } - resize(x.elements); - for(size_t i = 0; i < elements; ++i){ - data[array_element(i)] = x[i]; - } - return *this; - } - - - template template void - deque::assign(InputIterator first, InputIterator last) - { - clear(); - while(first !=last){ - push_back(*first); - ++first; - } - } - - - template template void - deque::assign(Size n, const U& u) - { - if(&u == this){ - return; - } - clear(); - for(size_type i = 0; i < n; ++i){ - push_back(u); - } - } - - - template typename deque::allocator_type - deque::get_allocator() const - { - return a; - } - - template typename - deque::iterator deque::begin() - { - return deque_iter(this, 0); - } - - - template typename deque::const_iterator - deque::begin() const - { - return deque_citer(this, 0); - } - - template typename - deque::iterator deque::end() - { - return deque_iter(this, elements); - } - - template typename - deque::const_iterator deque::end() const - { - return deque_citer(this, elements); - } - - template typename - deque::reverse_iterator deque::rbegin() - { - return reverse_iterator(end()); - } - - template typename - deque::const_reverse_iterator deque::rbegin() const - { - return const_reverse_iterator(end()); - } - - template typename - deque::reverse_iterator deque::rend() - { - return reverse_iterator(begin()); - } - - template typename - deque::const_reverse_iterator deque::rend() const - { - return const_reverse_iterator(begin()); - } - - template typename - deque::size_type deque::size() const - { - return elements; - } - - template typename - deque::size_type deque::max_size() const - { - return ((size_type)(-1)) / sizeof(T); - } - - template void deque::resize(size_type sz, T c){ - reserve(sz); - while(sz > size()){ - push_back(c); - } - while(sz < size()){ - pop_back(); - } - } - - template bool deque::empty() const{ - return (elements == 0); - } - - template typename - deque::reference deque::operator[](size_type n) - { - return data[array_element(n)]; - } - - template typename - deque::const_reference deque::operator[](size_type n) const - { - return data[array_element(n)]; - } - - template typename - deque::reference deque::at(size_type n) - { - if(n > elements){ - __throw_out_of_range("Out of deque range"); - } - return data[array_element(n)]; - } - - template typename - deque::const_reference deque::at(size_type n) const - { - if(n > elements){ - __throw_out_of_range("Out of deque range"); - } - return data[array_element(n)]; - } - - template typename - deque::reference deque::front() - { - return data[first_element]; - } - - template typename - deque::const_reference deque::front() const - { - return data[first_element]; - } - - template typename - deque::reference deque::back() - { - return data[array_element(elements-1)]; - } - - template typename - deque::const_reference deque::back() const - { - return data[array_element(elements-1)]; - } - - template void deque::push_front(const T& x){ - reserve(elements + 1); - first_element = first_subtract(1); - a.construct(data + first_element, x); - ++elements; - } - - template void deque::push_back(const T& x){ - reserve(elements + 1); - a.construct(data + last_element, x); - ++elements; - last_element = array_element(elements); - } - - template typename - deque::iterator deque::insert(iterator position, const T& x) - { - reserve(elements+1); - if(position.element > (elements/2)){ - //Push all elements back 1 - push_back(x); - for(size_type i = elements-1; i > position.element; --i){ - at(i) = at(i-1); - } - }else{ - //Push all elements forward 1 - push_front(x); - for(size_type i = 0; i < position.element; ++i){ - at(i) = at(i+1); - } - } - at(position.element) = x; - return deque_iter(this, position.element); - } - - template void deque:: - insert(typename deque::iterator position, size_type n, const T& x) - { - reserve(elements + n); - for(size_t i =0; i < n; ++i){ - position = insert(position, x); - } - } - - template template - void deque::insert (iterator position, InputIterator first, InputIterator last) - { - while(first != last){ - position = insert(position, *first); - ++first; - } - } - - template void deque::pop_front(){ - if(elements == 0){ - __throw_out_of_range("deque pop_front"); - } - a.destroy(data + first_element); - first_element = array_element(1); - --elements; - } - - template void deque::pop_back(){ - last_element = array_element(elements - 1); - a.destroy(data + last_element); - --elements; - } - - template typename - deque::iterator deque::erase(typename deque::iterator position) - { - if(position.element > (elements /2)){ - for(size_type i = position.element; i < elements - 1; ++i){ - at(i) = at(i+1); - } - pop_back(); - }else{ - for(size_type i = position.element; i > 0; --i){ - at(i) = at(i-1); - } - pop_front(); - } - return deque_iter(this, position.element); - } - - template typename deque::iterator - deque:: - erase(typename deque::iterator first, typename deque::iterator last) - { - //Shift backwards - size_type num_move = last.element - first.element; - if( first.element > (elements - last.element) ){ - for(size_type i = last.element; i < elements ; ++i){ - at(i-num_move) = at(i); - } - for(size_type i = 0; i < num_move ; ++i){ - pop_back(); - } - }else{ - for(size_type i = 0; i < first.element ; ++i){ - at(last.element - i - 1) = at(first.element - i - 1); - } - for(size_type i = 0; i < num_move ; ++i){ - pop_front(); - } - } - return deque_iter(this, first.element); - } - - template void deque::swap(deque& x) - { - T * temp_data; - typename deque::size_type temp_size; - - //Swap data pointers - temp_data = x.data; - x.data = data; - data = temp_data; - - //Swap array sizes - temp_size = x.data_size; - x.data_size = data_size; - data_size = temp_size; - - //Swap num array elements - temp_size = x.elements; - x.elements = elements; - elements = temp_size; - - //Swap first_pointer - temp_size = x.first_element; - x.first_element = first_element; - first_element = temp_size; - - //Swap last_pointer - temp_size = x.last_element; - x.last_element = last_element; - last_element = temp_size; - } - - template void deque::clear() - { - while(elements > 0 ){ - pop_back(); - } - } - - - template void deque::reserve(typename deque::size_type n) - { - if(data_size >= n){ - return; - } - - size_type size_temp; - size_type first_temp; - T * data_temp; - size_temp = n + __UCLIBCXX_STL_BUFFER_SIZE__; //Reserve extra 'cause we can - data_temp = a.allocate(size_temp); - - first_temp = (size_temp - elements) / 2; - for(size_type i = 0; i < elements; ++i){ - a.construct(data_temp + first_temp + i, data[array_element(i)]); - a.destroy(data + array_element(i)); - } - - //Now shuffle pointers - a.deallocate(data, data_size); - data = data_temp; - data_size = size_temp; - first_element = first_temp; - last_element = first_element + elements; - } - - - template _UCXXEXPORT - bool - operator==(const deque& x, const deque& y) - { - if(x.elements != y.elements){ - return false; - } - for(typename deque::size_type i = 0; i < x.elements; ++i){ - if(x[i] < y[i] || y[i] < x[i]){ - return false; - } - } - return true; - } - - template bool operator< (const deque& x, const deque& y); - template _UCXXEXPORT - bool - operator!=(const deque& x, const deque& y) - { - if(x == y){ - return false; - } - return true; - } - template bool operator> (const deque& x, const deque& y); - template bool operator>=(const deque& x, const deque& y); - template bool operator<=(const deque& x, const deque& y); - template _UCXXEXPORT void swap(deque& x, deque& y){ - x.swap(y); - } - - - -} +namespace std +{ + template > class deque; + template bool operator==(const deque& x, const deque& y); + template bool operator< (const deque& x, const deque& y); + template bool operator!=(const deque& x, const deque& y); + template bool operator> (const deque& x, const deque& y); + template bool operator>=(const deque& x, const deque& y); + template bool operator<=(const deque& x, const deque& y); + template void swap(deque& x, deque& y); + + template class _UCXXEXPORT deque { + public: + friend bool operator==<>(const deque& x, const deque& y); + friend class deque_iter; + friend class deque_citer; + class deque_iter; + class deque_citer; + + typedef typename Allocator::reference reference; + typedef typename Allocator::const_reference const_reference; + typedef deque_iter iterator; + typedef deque_citer const_iterator; + typedef typename Allocator::size_type size_type; + typedef typename Allocator::difference_type difference_type; + typedef T value_type; + typedef Allocator allocator_type; + typedef typename Allocator::pointer pointer; + typedef typename Allocator::const_pointer const_pointer; + typedef std::reverse_iterator reverse_iterator; + typedef std::reverse_iterator const_reverse_iterator; + + explicit deque(const Allocator& al = Allocator()); + explicit deque(size_type n, const T& value = T(), const Allocator& al = Allocator()); + template deque(InputIterator first, InputIterator last, const Allocator& = Allocator()); + deque(const deque& x); + ~deque(); + + deque& operator=(const deque& x); + template void assign(InputIterator first, InputIterator last); + template void assign(Size n, const U& u = U()); + allocator_type get_allocator() const; + + iterator begin(); + const_iterator begin() const; + iterator end(); + const_iterator end() const; + reverse_iterator rbegin(); + const_reverse_iterator rbegin() const; + reverse_iterator rend(); + const_reverse_iterator rend() const; + + size_type size() const; + size_type max_size() const; + void resize(size_type sz, T c = T()); + bool empty() const; + + reference operator[](size_type n); + const_reference operator[](size_type n) const; + reference at(size_type n); + const_reference at(size_type n) const; + reference front(); + const_reference front() const; + reference back(); + const_reference back() const; + + void push_front(const T& x); + void push_back(const T& x); + iterator insert(iterator position, const T& x = T()); + void insert(iterator position, size_type n, const T& x); + template void insert (iterator position, InputIterator first, InputIterator last); + void pop_front(); + void pop_back(); + + iterator erase(iterator position); + iterator erase(iterator first, iterator last); + void swap(deque&); + void clear(); + + protected: + void reserve(size_type n); + + inline size_type array_element(size_type deque_element) const + { + if (deque_element < (data_size - first_element)) + { + return first_element + deque_element; + } + return deque_element - (data_size - first_element); + } + + inline size_type first_subtract(size_type sub_size) const + { + if (sub_size > first_element) + { + return (data_size - first_element) - sub_size; + } + return first_element - sub_size; + } + + T * data; + size_type data_size; //Physical size of array + size_type elements; //Elements in array + size_type first_element; //Element number of array 0..n + size_type last_element; //Element number of array 0..n + Allocator a; + + }; + + template class _UCXXEXPORT deque::deque_iter + : public std::iterator< + random_access_iterator_tag, + T, + typename Allocator::difference_type, + typename Allocator::pointer, + typename Allocator::reference + > + { + friend class deque; + protected: + deque * container; + typename Allocator::size_type element; + + public: + deque_iter() : container(0), element(0) { } + deque_iter(const deque_iter & d) : container (d.container), element(d.element) { } + + deque_iter(deque * c, typename Allocator::size_type e) + : container(c), element(e) + { + return; + } + + ~deque_iter() { } + + deque_iter & operator=(const deque_iter & d) + { + container = d.container; + element = d.element; + return *this; + } + + T & operator*() + { + return container->data[container->array_element(element)]; + } + + T * operator->() + { + return container->data + container->array_element(element); + } + + const T & operator*() const + { + return container->data[container->array_element(element)]; + } + + const T * operator->() const + { + return container->data + container->array_element(element); + } + + bool operator==(const deque_iter & d) const + { + if (container == d.container && element == d.element) + { + return true; + } + + return false; + } + + bool operator==(const deque_citer & d) const + { + if (container == d.container && element == d.element){ + return true; + } + return false; + } + + bool operator!=(const deque_iter & d) const + { + if (container != d.container || element != d.element) + { + return true; + } + return false; + } + + bool operator!=(const deque_citer & d) const + { + if (container != d.container || element != d.element) + { + return true; + } + return false; + } + + bool operator<(const deque_iter & d) const + { + if (element < d.element){ + return true; + } + return false; + } + + bool operator<(const deque_citer & d) const + { + if (element < d.element){ + return true; + } + return false; + } + + bool operator<=(const deque_iter & d) const + { + if (element <= d.element){ + return true; + } + return false; + } + + bool operator<=(const deque_citer & d) const + { + if (element <= d.element){ + return true; + } + return false; + } + + bool operator>(const deque_iter & d) const + { + if (element > d.element) + { + return true; + } + + return false; + } + + bool operator>(const deque_citer & d) const + { + if (element > d.element) + { + return true; + } + + return false; + } + + bool operator>=(const deque_iter & d) const + { + if (element >= d.element) + { + return true; + } + + return false; + } + + bool operator>=(const deque_citer & d) const + { + if (element >= d.element) + { + return true; + } + + return false; + } + + deque_iter & operator++() + { + ++element; + return *this; + } + + deque_iter operator++(int) + { + deque_iter temp(container, element); + ++element; + return temp; + } + + deque_iter operator+(typename Allocator::size_type n) + { + deque_iter temp(container, element + n); + return temp; + } + + deque_iter & operator+=(typename Allocator::size_type n) + { + element += n; + return *this; + } + + deque_iter & operator--() + { + --element; + return *this; + } + + deque_iter operator--(int) + { + deque_iter temp(container, element); + --element; + return temp; + } + + deque_iter operator-(typename Allocator::size_type n) + { + deque_iter temp(container, element - n); + return temp; + } + + deque_iter & operator-=(typename Allocator::size_type n) + { + element -= n; + return *this; + } + + typename Allocator::size_type operator-(const deque_iter & d) + { + return element - d.element; + } + + }; + + template class _UCXXEXPORT deque::deque_citer + : public std::iterator< + random_access_iterator_tag, + T, + typename Allocator::difference_type, + typename Allocator::const_pointer, + typename Allocator::const_reference + > + { + friend class deque; + protected: + const deque * container; + typename Allocator::size_type element; + + public: + deque_citer() : container(0), element(0) { } + deque_citer(const deque_citer & d) : container (d.container), element(d.element) { } + deque_citer(const deque_iter & d) : container (d.container), element(d.element) { } + + deque_citer(const deque * c, typename Allocator::size_type e) + : container(c), element(e) + { + return; + } + + ~deque_citer() { } + + deque_citer & operator=(const deque_iter & d) + { + container = d.container; + element = d.element; + return *this; + } + + const T & operator*() const + { + return container->data[container->array_element(element)]; + } + + const T * operator->() const + { + return container->data + container->array_element(element); + } + + bool operator==(const deque_citer & d) const + { + if (container == d.container && element == d.element) + { + return true; + } + return false; + } + + bool operator==(const deque_iter & d) const + { + if (container == d.container && element == d.element) + { + return true; + } + return false; + } + + bool operator!=(const deque_citer & d) const + { + if (container != d.container || element != d.element) + { + return true; + } + return false; + } + + bool operator!=(const deque_iter & d) const + { + if (container != d.container || element != d.element) + { + return true; + } + + return false; + } + + bool operator<(const deque_citer & d) const + { + if (element < d.element){ + return true; + } + return false; + } + + bool operator<(const deque_iter & d) const + { + if (element < d.element){ + return true; + } + return false; + } + + bool operator<=(const deque_citer & d) const + { + if (element <= d.element){ + return true; + } + return false; + } + + bool operator<=(const deque_iter & d) const + { + if (element <= d.element){ + return true; + } + return false; + } + + bool operator>(const deque_citer & d) const + { + if (element > d.element){ + return true; + } + return false; + } + + bool operator>(const deque_iter & d) const + { + if (element > d.element){ + return true; + } + return false; + } + + bool operator>=(const deque_citer & d) + { + if (element >= d.element) + { + return true; + } + return false; + } + + bool operator>=(const deque_iter & d) + { + if (element >= d.element){ + return true; + } + return false; + } + + deque_citer & operator++() + { + ++element; + return *this; + } + + deque_citer operator++(int) + { + deque_citer temp(container, element); + ++element; + return temp; + } + + deque_citer operator+(typename Allocator::size_type n) + { + deque_citer temp(container, element + n); + return temp; + } + + deque_citer & operator+=(typename Allocator::size_type n) + { + element += n; + return *this; + } + + deque_citer & operator--() + { + --element; + return *this; + } + + deque_citer operator--(int) + { + deque_citer temp(container, element); + --element; + return temp; + } + + deque_citer operator-(typename Allocator::size_type n) + { + deque_citer temp(container, element - n); + return temp; + } + + deque_citer & operator-=(typename Allocator::size_type n) + { + element -= n; + return *this; + } + + typename Allocator::size_type operator-(const deque_citer & d) + { + return element - d.element; + } + + }; + + template deque::deque(const Allocator& al) + : data(0), + data_size(0), elements(0), first_element(0), last_element(0), a(al) + { + data_size = __UCLIBCXX_STL_BUFFER_SIZE__; + data = a.allocate(data_size); + first_element = data_size /2; + last_element = first_element; + } + + + template deque::deque( + size_type n, const T& value, const Allocator& al) + : data(0), + elements(n), first_element(0), last_element(0), a(al) + { + data_size = elements + __UCLIBCXX_STL_BUFFER_SIZE__; + data = a.allocate(data_size); + first_element = (data_size - elements) / 2; + last_element = first_element; + + for (n=first_element ; n < last_element; ++n) + { + a.construct(data+n, value); + } + } + + + template template + deque::deque(InputIterator first, InputIterator last, const Allocator& al) + : data(0), + data_size(0), elements(0), first_element(0), last_element(0), a(al) + { + data_size = __UCLIBCXX_STL_BUFFER_SIZE__; + data = a.allocate(data_size); + first_element = data_size / 4; //Note sure how big, but let's add a little space... + last_element = first_element; + while (first != last) + { + push_back(*first); + ++first; + } + } + + + template deque::deque(const deque& x) + : data(0), + elements(0), first_element(0), last_element(0), a(x.a) + { + data_size = x.elements + __UCLIBCXX_STL_BUFFER_SIZE__; + data = a.allocate(data_size); + first_element = (data_size - x.elements) / 2; + last_element = first_element; + for (size_type i=0; i < x.elements; ++i) + { + push_back(x[i]); + } + } + + + template deque::~deque() + { + clear(); + a.deallocate(data, data_size); + } + + template deque& deque:: + operator=(const deque& x) + { + if (&x == this) + { + return *this; + } + + resize(x.elements); + for (size_t i = 0; i < elements; ++i) + { + data[array_element(i)] = x[i]; + } + return *this; + } + + template template void + deque::assign(InputIterator first, InputIterator last) + { + clear(); + while (first !=last) + { + push_back(*first); + ++first; + } + } + + template template void + deque::assign(Size n, const U& u) + { + if (&u == this) + { + return; + } + + clear(); + for (size_type i = 0; i < n; ++i) + { + push_back(u); + } + } + + template typename deque::allocator_type + deque::get_allocator() const + { + return a; + } + + template typename + deque::iterator deque::begin() + { + return deque_iter(this, 0); + } + + template typename deque::const_iterator + deque::begin() const + { + return deque_citer(this, 0); + } + + template typename + deque::iterator deque::end() + { + return deque_iter(this, elements); + } + + template typename + deque::const_iterator deque::end() const + { + return deque_citer(this, elements); + } + + template typename + deque::reverse_iterator deque::rbegin() + { + return reverse_iterator(end()); + } + + template typename + deque::const_reverse_iterator deque::rbegin() const + { + return const_reverse_iterator(end()); + } + + template typename + deque::reverse_iterator deque::rend() + { + return reverse_iterator(begin()); + } + + template typename + deque::const_reverse_iterator deque::rend() const + { + return const_reverse_iterator(begin()); + } + + template typename + deque::size_type deque::size() const + { + return elements; + } + + template typename + deque::size_type deque::max_size() const + { + return ((size_type)(-1)) / sizeof(T); + } + + template void deque::resize(size_type sz, T c) + { + reserve(sz); + while (sz > size()) + { + push_back(c); + } + + while (sz < size()) + { + pop_back(); + } + } + + template bool deque::empty() const + { + return (elements == 0); + } + + template typename + deque::reference deque::operator[](size_type n) + { + return data[array_element(n)]; + } + + template typename + deque::const_reference deque::operator[](size_type n) const + { + return data[array_element(n)]; + } + + template typename + deque::reference deque::at(size_type n) + { + if (n > elements) + { +#ifdef CONFIG_UCLIBCXX_EXCEPTION + __throw_out_of_range("Out of deque range"); +#else + std::terminate(); +#endif + } + return data[array_element(n)]; + } + + template typename + deque::const_reference deque::at(size_type n) const + { + if (n > elements) + { +#ifdef CONFIG_UCLIBCXX_EXCEPTION + __throw_out_of_range("Out of deque range"); +#else + std::terminate(); +#endif + } + return data[array_element(n)]; + } + + template typename + deque::reference deque::front() + { + return data[first_element]; + } + + template typename + deque::const_reference deque::front() const + { + return data[first_element]; + } + + template typename + deque::reference deque::back() + { + return data[array_element(elements-1)]; + } + + template typename + deque::const_reference deque::back() const + { + return data[array_element(elements-1)]; + } + + template void deque::push_front(const T& x) + { + reserve(elements + 1); + first_element = first_subtract(1); + a.construct(data + first_element, x); + ++elements; + } + + template void deque::push_back(const T& x) + { + reserve(elements + 1); + a.construct(data + last_element, x); + ++elements; + last_element = array_element(elements); + } + + template typename + deque::iterator deque::insert(iterator position, const T& x) + { + reserve(elements+1); + if (position.element > (elements/2)) + { + //Push all elements back 1 + + push_back(x); + for (size_type i = elements-1; i > position.element; --i) + { + at(i) = at(i-1); + } + } + else + { + //Push all elements forward 1 + + push_front(x); + for (size_type i = 0; i < position.element; ++i){ + at(i) = at(i+1); + } + } + + at(position.element) = x; + return deque_iter(this, position.element); + } + + template void deque:: + insert(typename deque::iterator position, size_type n, const T& x) + { + reserve(elements + n); + for (size_t i =0; i < n; ++i){ + position = insert(position, x); + } + } + + template template + void deque::insert (iterator position, InputIterator first, InputIterator last) + { + while (first != last){ + position = insert(position, *first); + ++first; + } + } + + template void deque::pop_front() + { + if (elements == 0) + { +#ifdef CONFIG_UCLIBCXX_EXCEPTION + __throw_out_of_range("deque pop_front"); +#else + std::terminate(); +#endif + } + a.destroy(data + first_element); + first_element = array_element(1); + --elements; + } + + template void deque::pop_back() + { + last_element = array_element(elements - 1); + a.destroy(data + last_element); + --elements; + } + + template typename + deque::iterator deque::erase(typename deque::iterator position) + { + if (position.element > (elements /2)) + { + for (size_type i = position.element; i < elements - 1; ++i) + { + at(i) = at(i+1); + } + pop_back(); + } + else + { + for (size_type i = position.element; i > 0; --i) + { + at(i) = at(i-1); + } + pop_front(); + } + return deque_iter(this, position.element); + } + + template typename deque::iterator + deque:: + erase(typename deque::iterator first, typename deque::iterator last) + { + //Shift backwards + size_type num_move = last.element - first.element; + if (first.element > (elements - last.element)) + { + for (size_type i = last.element; i < elements ; ++i) + { + at(i-num_move) = at(i); + } + + for (size_type i = 0; i < num_move ; ++i) + { + pop_back(); + } + } + else + { + for (size_type i = 0; i < first.element ; ++i) + { + at(last.element - i - 1) = at(first.element - i - 1); + } + + for (size_type i = 0; i < num_move ; ++i) + { + pop_front(); + } + } + return deque_iter(this, first.element); + } + + template void deque::swap(deque& x) + { + T * temp_data; + typename deque::size_type temp_size; + + //Swap data pointers + + temp_data = x.data; + x.data = data; + data = temp_data; + + //Swap array sizes + + temp_size = x.data_size; + x.data_size = data_size; + data_size = temp_size; + + //Swap num array elements + + temp_size = x.elements; + x.elements = elements; + elements = temp_size; + + //Swap first_pointer + + temp_size = x.first_element; + x.first_element = first_element; + first_element = temp_size; + + //Swap last_pointer + + temp_size = x.last_element; + x.last_element = last_element; + last_element = temp_size; + } + + template void deque::clear() + { + while (elements > 0) + { + pop_back(); + } + } + + + template void deque::reserve(typename deque::size_type n) + { + if (data_size >= n) + { + return; + } + + size_type size_temp; + size_type first_temp; + T * data_temp; + size_temp = n + __UCLIBCXX_STL_BUFFER_SIZE__; //Reserve extra 'cause we can + data_temp = a.allocate(size_temp); + + first_temp = (size_temp - elements) / 2; + for (size_type i = 0; i < elements; ++i) + { + a.construct(data_temp + first_temp + i, data[array_element(i)]); + a.destroy(data + array_element(i)); + } + + //Now shuffle pointers + + a.deallocate(data, data_size); + data = data_temp; + data_size = size_temp; + first_element = first_temp; + last_element = first_element + elements; + } + + template _UCXXEXPORT + bool + operator==(const deque& x, const deque& y) + { + if (x.elements != y.elements){ + return false; + } + for (typename deque::size_type i = 0; i < x.elements; ++i){ + if (x[i] < y[i] || y[i] < x[i]){ + return false; + } + } + return true; + } + + template bool operator< (const deque& x, const deque& y); + template _UCXXEXPORT + bool + operator!=(const deque& x, const deque& y) + { + if (x == y){ + return false; + } + return true; + } + + template bool operator> (const deque& x, const deque& y); + template bool operator>=(const deque& x, const deque& y); + template bool operator<=(const deque& x, const deque& y); + template _UCXXEXPORT void swap(deque& x, deque& y){ + x.swap(y); + } +} // namespace #pragma GCC visibility pop diff --git a/misc/uClibc++/include/uClibc++/string b/misc/uClibc++/include/uClibc++/string index d04579414..f128e7e5a 100644 --- a/misc/uClibc++/include/uClibc++/string +++ b/misc/uClibc++/include/uClibc++/string @@ -1,21 +1,21 @@ -/* Copyright (C) 2004 Garrett A. Kajmowicz - - This file is part of the uClibc++ Library. - - This library 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 2.1 of the License, or (at your option) any later version. - - This library 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 library; if not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -*/ +/* Copyright (C) 2004 Garrett A. Kajmowicz + * + * This file is part of the uClibc++ Library. + * + * This library 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 2.1 of the License, or (at your option) any later version. + * + * This library 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 library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ #include #include @@ -25,7 +25,6 @@ #include #include - #ifdef __UCLIBCXX_HAS_WCHAR__ #include #include @@ -36,979 +35,1278 @@ #pragma GCC visibility push(default) -namespace std{ - - //Basic basic_string - - template, class A = allocator > class basic_string; - - typedef basic_string string; - #ifdef __UCLIBCXX_HAS_WCHAR__ - typedef basic_string wstring; - #endif +namespace std +{ + // Basic basic_string + template, class A = allocator > class basic_string; + typedef basic_string string; + #ifdef __UCLIBCXX_HAS_WCHAR__ + typedef basic_string wstring; + #endif //template, class A = allocator > class _UCXXEXPORT basic_string template class basic_string - : public std::vector + : public std::vector { public: - typedef Tr traits_type; - typedef typename Tr::char_type value_type; - typedef A allocator_type; - typedef typename A::size_type size_type; - typedef typename A::difference_type difference_type; - - typedef typename A::reference reference; - typedef typename A::const_reference const_reference; - typedef typename A::pointer pointer; - typedef typename A::const_pointer const_pointer; - - typedef typename vector::iterator iterator; - typedef typename vector::const_iterator const_iterator; - - typedef typename vector::reverse_iterator reverse_iterator; - typedef typename vector::const_reverse_iterator const_reverse_iterator; - - static const size_type npos = (size_type)-1; - - explicit _UCXXEXPORT basic_string(const A& al = A()) : vector(al){ return; } - - _UCXXEXPORT basic_string(const basic_string& str, size_type pos = 0, size_type n = npos, const A& al = A()); //Below - - _UCXXEXPORT basic_string(const Ch* s, size_type n, const A& al = A()) - : vector(al) - { - if(n == npos){ - __throw_out_of_range(); - } - if(s > 0){ - resize(n); - Tr::copy(vector::data, s, vector::elements); - } - } - - _UCXXEXPORT basic_string(const Ch* s, const A& al = A()); //Below - - _UCXXEXPORT basic_string(size_type n, Ch c, const A& al = A()) - : vector(n, c, al) - { - } - - template _UCXXEXPORT basic_string(InputIterator begin, InputIterator end, const A& a = A()) - :vector(begin, end) - { - - } - - _UCXXEXPORT ~basic_string() { - return; - } - - _UCXXEXPORT basic_string& operator=(const basic_string& str); //Below - - _UCXXEXPORT basic_string& operator=(const Ch* s){ - vector::clear(); - if(s!=0){ - size_type len = Tr::length(s); - resize(len); - Tr::copy( vector::data, s, len); - } - return *this; - } - - _UCXXEXPORT basic_string& operator=(Ch c){ - vector::clear(); - vector::push_back(c); - return *this; - } - - inline _UCXXEXPORT size_type length() const { return vector::size(); } - - void _UCXXEXPORT resize(size_type n, Ch c = Ch()){ - vector::resize(n, c); - } - - _UCXXEXPORT basic_string& operator+=(const basic_string& str){ - return append(str); - } - - _UCXXEXPORT basic_string& operator+=(const Ch * s){ - return append(s); - } - - _UCXXEXPORT basic_string& operator+=(Ch c){ - vector::push_back(c); - return *this; - } - - _UCXXEXPORT basic_string& append(const basic_string& str){ - size_t temp = vector::elements; - resize(vector::elements + str.elements); - Tr::copy( vector::data + temp, str.vector::data, str.elements); - - return *this; - } - - _UCXXEXPORT basic_string& append(const basic_string& str, size_type pos, size_type n){ - if(pos > str.size()){ - __throw_out_of_range(); - } - - size_type rlen = str.elements - pos; - if(rlen > n){ - rlen = n; - } - if(vector::elements > npos - rlen){ - __throw_length_error(); - } - size_t temp = vector::elements; - resize(vector::elements + rlen); - Tr::copy( vector::data + temp, str.vector::data + pos, rlen); - return *this; - } - - _UCXXEXPORT basic_string& append(const Ch* s, size_type n){ - size_t temp = vector::elements; - resize(vector::elements + n); - Tr::copy( vector::data + temp, s, n); - return *this; - } - - _UCXXEXPORT basic_string& append(const Ch* s){ - size_type strLen = Tr::length(s); - size_t temp = vector::elements; - resize(vector::elements + strLen); - Tr::copy( vector::data + temp, s, strLen); - return *this; - } - - _UCXXEXPORT basic_string& append(size_type n, Ch c){ - vector::resize(vector::elements + n, c); - return *this; - } - - _UCXXEXPORT basic_string& assign(const basic_string& str){ - operator=(str); - return *this; - } - - _UCXXEXPORT basic_string& assign(const basic_string& str, size_type pos, size_type n){ - if(pos > str.elements){ - __throw_out_of_range(); - } - size_type r = str.elements - pos; - if(r > n){ - r = n; - } - resize(r); - Tr::copy(vector::data, str.vector::data + pos, r); - return *this; - } - - _UCXXEXPORT basic_string& assign(const Ch* s, size_type n){ - resize(n); - Tr::copy(vector::data, s, n); - return *this; - } - - _UCXXEXPORT basic_string& assign(const Ch* s){ - size_type len = Tr::length(s); - return assign(s, len); - } - - _UCXXEXPORT basic_string& assign(size_type n, Ch c){ - vector::clear(); - vector::resize(n, Ch() ); - return *this; - } - - template _UCXXEXPORT basic_string& assign(InputIterator first, InputIterator last){ - vector::resize(0, Ch()); - while (first != last){ - append(*first); - ++first; - } - return *this; - } - - _UCXXEXPORT basic_string& insert(size_type pos1, const basic_string& str, size_type pos2=0, size_type n=npos){ - if(pos1 > vector::elements || pos2 > str.elements){ - __throw_out_of_range(); - } - size_type r = str.elements - pos2; - if( r > n){ - r = n; - } - if(vector::elements > npos - r){ - __throw_length_error(); - } - size_type temp = vector::elements; - resize(vector::elements + r); - Tr::move(vector::data + pos1 + r, vector::data + pos1, temp - pos1); - Tr::copy(vector::data + pos1, str.vector::data + pos2, r); - return *this; - } - - _UCXXEXPORT basic_string& insert(size_type pos, const Ch* s, size_type n){ - if(pos > vector::elements){ - __throw_out_of_range(); - } - if(vector::elements > npos - n){ - __throw_length_error(); - } - size_type temp = vector::elements; - resize(vector::elements + n); - Tr::move(vector::data + pos + n, vector::data + pos, temp - pos); - Tr::copy(vector::data + pos, s, n); - return *this; - } - - inline _UCXXEXPORT basic_string& insert(size_type pos, const Ch* s){ - size_type len = Tr::length(s); - return insert(pos, s, len); - } - - _UCXXEXPORT basic_string& insert(size_type pos, size_type n, Ch c){ - if(pos > vector::elements){ - __throw_out_of_range(); - } - if(vector::elements > npos - n){ - __throw_length_error(); - } - size_type temp = vector::elements; - resize(vector::elements + n); - Tr::move(vector::data + pos + n, vector::data + pos, temp - pos); - Tr::assign(vector::data + pos, n, c); - return *this; - } - - using vector::insert; -// void insert(iterator p, size_type n, charT c); -// template void insert(iterator p, InputIterator first, InputIterator last); - - _UCXXEXPORT basic_string& erase(size_type pos = 0, size_type n = npos){ - size_type xlen = vector::elements - pos; - - if(xlen > n){ - xlen = n; - } - size_type temp = vector::elements; - - Tr::move(vector::data + pos, vector::data + pos + xlen, temp - pos - xlen); - resize(temp - xlen); - return *this; - } - - _UCXXEXPORT iterator erase(iterator position){ - if(position == vector::end()){ - return position; - } - - ++position; - - iterator temp = position; - - while(position != vector::end()){ - *(position-1) = *position; - ++position; - } - vector::pop_back(); - return temp; - } - - _UCXXEXPORT iterator erase(iterator first, iterator last){ - size_t count = last - first; - - iterator temp = last; - - while(last != vector::end()){ - *(last - count) = *last; - ++last; - } - - resize( vector::elements-count); - - return temp; - } - - _UCXXEXPORT basic_string& - replace(size_type pos1, size_type n1, const basic_string& str, size_type pos2=0, size_type n2=npos) - { - if(pos1 > vector::elements){ - __throw_out_of_range(); - } - size_type xlen = vector::elements - pos1; - if(xlen > n1){ - xlen = n1; - } - size_type rlen = str.elements - pos2; - if(rlen > n2){ - rlen = n2; - } - if((vector::elements - xlen) >= (npos - rlen)){ - __throw_length_error(); - } - - size_t temp = vector::elements; - - if(rlen > xlen){ //Only if making larger - resize(temp - xlen + rlen); - } - - //Final length = vector::elements - xlen + rlen - //Initial block is of size pos1 - //Block 2 is of size len - - Tr::move(vector::data + pos1 + rlen, vector::data + pos1 + xlen, temp - pos1 - xlen); - Tr::copy(vector::data + pos1, str.vector::data + pos2, rlen); - resize(temp - xlen + rlen); - return *this; - } - - _UCXXEXPORT basic_string& replace(size_type pos, size_type n1, const Ch* s, size_type n2){ - return replace(pos,n1,basic_string(s,n2)); - - } - - inline _UCXXEXPORT basic_string& replace(size_type pos, size_type n1, const Ch* s){ - return replace(pos,n1,basic_string(s)); - } - - _UCXXEXPORT basic_string& replace(size_type pos, size_type n1, size_type n2, Ch c){ - return replace(pos,n1,basic_string(n2,c)); - } -// _UCXXEXPORT basic_string& replace(iterator i1, iterator i2, const basic_string& str); -// _UCXXEXPORT basic_string& replace(iterator i1, iterator i2, const Ch* s, size_type n); -// _UCXXEXPORT basic_string& replace(iterator i1, iterator i2, const Ch* s); -// _UCXXEXPORT basic_string& replace(iterator i1, iterator i2, size_type n, Ch c); -/* template _UCXXEXPORT basic_string& replace(iterator i1, iterator i2, - InputIterator j1, InputIterator j2);*/ - - size_type _UCXXEXPORT copy(Ch* s, size_type n, size_type pos = 0) const{ - if(pos > vector::elements){ - __throw_out_of_range(); - } - size_type r = vector::elements - pos; - if(r > n){ - r = n; - } - Tr::copy(s, vector::data + pos, r); - return r; - } - - _UCXXEXPORT void swap(basic_string& s){ - //Data pointers - - vector::swap(s); - } - - _UCXXEXPORT const Ch* c_str() const{ - const_cast *>(this)->reserve(vector::elements+1); - vector::data[vector::elements] = 0; //Add 0 at the end - return vector::data; - } - - _UCXXEXPORT const Ch* data() const{ - return vector::data; - } - _UCXXEXPORT allocator_type get_allocator() const{ - return vector::a; - } - - _UCXXEXPORT size_type find (const basic_string& str, size_type pos = 0) const; //Below - - _UCXXEXPORT size_type find (const Ch* s, size_type pos, size_type n) const{ - return find(basic_string(s,n), pos); - } - _UCXXEXPORT size_type find (const Ch* s, size_type pos = 0) const{ - return find(basic_string(s), pos); - } - _UCXXEXPORT size_type find (Ch c, size_type pos = 0) const{ - for(size_type i = pos; i < length(); ++i){ - if(this->operator[](i) == c){ - return i; - } - } - return npos; - } - _UCXXEXPORT size_type rfind(const basic_string& str, size_type pos = npos) const{ - if(pos >= length()){ - pos = length(); - } - for(size_type i = pos; i > 0; --i){ - if(str == substr(i-1, str.length())){ - return i-1; - } - } - return npos; - } - _UCXXEXPORT size_type rfind(const Ch* s, size_type pos, size_type n) const{ - return rfind(basic_string(s,n),pos); - } - _UCXXEXPORT size_type rfind(const Ch* s, size_type pos = npos) const{ - return rfind(basic_string(s),pos); - } - _UCXXEXPORT size_type rfind(Ch c, size_type pos = npos) const{ - return rfind(basic_string(1,c),pos); - } - - _UCXXEXPORT size_type find_first_of(const basic_string& str, size_type pos = 0) const{ - for(size_type i = pos; i < length(); ++i){ - for(size_type j = 0; j < str.length() ; ++j){ - if( Tr::eq(str[j], this->operator[](i)) ){ - return i; - } - } - } - return npos; - } - - _UCXXEXPORT size_type find_first_of(const Ch* s, size_type pos, size_type n) const{ - return find_first_of(basic_string(s,n),pos); - } - _UCXXEXPORT size_type find_first_of(const Ch* s, size_type pos = 0) const{ - return find_first_of(basic_string(s),pos); - } - _UCXXEXPORT size_type find_first_of(Ch c, size_type pos = 0) const{ - for(size_type i = pos; i< length(); ++i){ - if( Tr::eq(this->operator[](i), c) ){ - return i; - } - } - return npos; - } - - _UCXXEXPORT size_type find_last_of (const basic_string& str, size_type pos = npos) const{ - if(pos > length()){ - pos = length(); - } - for(size_type i = pos; i >0 ; --i){ - for(size_type j = 0 ; j < str.length(); ++j){ - if( Tr::eq(this->operator[](i-1), str[j]) ){ - return i-1; - } - } - } - return npos; - } - _UCXXEXPORT size_type find_last_of (const Ch* s, size_type pos, size_type n) const{ - return find_last_of(basic_string(s,n),pos); - } - _UCXXEXPORT size_type find_last_of (const Ch* s, size_type pos = npos) const{ - return find_last_of(basic_string(s),pos); - } - _UCXXEXPORT size_type find_last_of (Ch c, size_type pos = npos) const{ - if(pos > length()){ - pos = length(); - } - for(size_type i = pos; i >0 ; --i){ - if( Tr::eq(this->operator[](i-1), c) ){ - return i-1; - } - } - return npos; - } - - _UCXXEXPORT size_type find_first_not_of(const basic_string& str, size_type pos = 0) const{ - bool foundCharacter; - for(size_type i = pos; i < length(); ++i){ - foundCharacter = false; - for(size_type j = 0; j < str.length() ; ++j){ - if( Tr::eq(str[j], this->operator[](i)) ){ - foundCharacter = true; - } - } - if(foundCharacter == false){ - return i; - } - } - return npos; - } - - _UCXXEXPORT size_type find_first_not_of(const Ch* s, size_type pos, size_type n) const{ - return find_first_not_of(basic_string(s,n),pos); - } - _UCXXEXPORT size_type find_first_not_of(const Ch* s, size_type pos = 0) const{ - return find_first_not_of(basic_string(s),pos); - } - _UCXXEXPORT size_type find_first_not_of(Ch c, size_type pos = 0) const{ - for(size_type i = pos; i < length() ; ++i){ - if(this->operator[](i) != c){ - return i; - } - } - return npos; - } - _UCXXEXPORT size_type find_last_not_of (const basic_string& str, size_type pos = npos) const{ - size_type xpos(length() - 1); - if(xpos > pos){ - xpos = pos; - } - - while(xpos != npos && npos != str.find_first_of(this->at(xpos))){ - --xpos; - } - - return xpos; - } - - _UCXXEXPORT size_type find_last_not_of (const Ch* s, size_type pos, size_type n) const{ - return find_last_not_of(basic_string(s,n),pos); - } - _UCXXEXPORT size_type find_last_not_of (const Ch* s, size_type pos = npos) const{ - return find_last_not_of(basic_string(s),pos); - } - _UCXXEXPORT size_type find_last_not_of (Ch c, size_type pos = npos) const{ - size_type xpos(length() - 1); - if(xpos > pos){ - xpos = pos; - } - while(xpos != npos && Tr::eq(this->at(xpos), c)){ - --xpos; - } - return xpos; - - } - - _UCXXEXPORT basic_string substr(size_type pos = 0, size_type n = npos) const; - - _UCXXEXPORT int compare(const basic_string& str) const{ - size_type rlen = vector::elements; - if(rlen > str.elements){ - rlen = str.elements; - } - int retval = Tr::compare(vector::data, str.vector::data, rlen); - if(retval == 0){ - if(vector::elements < str.elements){ - retval = -1; - } - if(vector::elements > str.elements){ - retval = 1; - } - } - return retval; - } - - _UCXXEXPORT int compare(size_type pos1, size_type n1, const basic_string& str, - size_type pos2=0, size_type n2=npos) const{ - size_type len1 = vector::elements - pos1; - if(len1 > n1){ - len1 = n1; - } - size_type len2 = str.vector::elements - pos2; - if(len2 > n2){ - len2 = n2; - } - size_type rlen = len1; - if(rlen > len2){ - rlen = len2; - } - int retval = Tr::compare(vector::data + pos1, str.vector::data + pos2, rlen); - if(retval == 0){ - if(len1 < len2){ - retval = -1; - } - if(len1 > len2){ - retval = 1; - } - } - return retval; - } - - _UCXXEXPORT int compare(const Ch* s) const{ - size_type slen = Tr::length(s); - size_type rlen = slen; - if(rlen > vector::elements){ - rlen=vector::elements; - } - int retval = Tr::compare(vector::data, s, rlen); - if(retval==0){ - if(vector::elements < slen){ - retval = -1; - } - if(vector::elements > slen){ - retval = 1; - } - } - return retval; - } - - _UCXXEXPORT int compare(size_type pos1, size_type n1, const Ch* s, size_type n2 = npos) const{ - size_type len1 = vector::elements - pos1; - if(len1 > n1){ - len1 = n1; - } - size_type slen = Tr::length(s); - size_type len2 = slen; - if(len2 > n2){ - len2 = n2; - } - size_type rlen = len1; - if(rlen > len2){ - rlen = len2; - } - int retval = Tr::compare(vector::data + pos1, s, rlen); - if(retval == 0){ - if(len1 < len2){ - retval = -1; - } - if(len1 > len2){ - retval = 1; - } - } - return retval; - } - + typedef Tr traits_type; + typedef typename Tr::char_type value_type; + typedef A allocator_type; + typedef typename A::size_type size_type; + typedef typename A::difference_type difference_type; + + typedef typename A::reference reference; + typedef typename A::const_reference const_reference; + typedef typename A::pointer pointer; + typedef typename A::const_pointer const_pointer; + + typedef typename vector::iterator iterator; + typedef typename vector::const_iterator const_iterator; + + typedef typename vector::reverse_iterator reverse_iterator; + typedef typename vector::const_reverse_iterator const_reverse_iterator; + + static const size_type npos = (size_type)-1; + + explicit _UCXXEXPORT basic_string(const A& al = A()) : vector(al){ return; } + + _UCXXEXPORT basic_string(const basic_string& str, size_type pos = 0, size_type n = npos, const A& al = A()); //Below + + _UCXXEXPORT basic_string(const Ch* s, size_type n, const A& al = A()) + : vector(al) + { + if (n == npos) + { +#ifdef CONFIG_UCLIBCXX_EXCEPTION + __throw_out_of_range(); +#else + std::terminate(); +#endif + } + + if (s > 0) + { + resize(n); + Tr::copy(vector::data, s, vector::elements); + } + } + + _UCXXEXPORT basic_string(const Ch* s, const A& al = A()); //Below + + _UCXXEXPORT basic_string(size_type n, Ch c, const A& al = A()) + : vector(n, c, al) + { + } + + template _UCXXEXPORT basic_string(InputIterator begin, InputIterator end, const A& a = A()) + :vector(begin, end) + { + + } + + _UCXXEXPORT ~basic_string() + { + return; + } + + _UCXXEXPORT basic_string& operator=(const basic_string& str); // Below + + _UCXXEXPORT basic_string& operator=(const Ch* s) + { + vector::clear(); + if (s != 0) + { + size_type len = Tr::length(s); + resize(len); + Tr::copy(vector::data, s, len); + } + + return *this; + } + + _UCXXEXPORT basic_string& operator=(Ch c) + { + vector::clear(); + vector::push_back(c); + return *this; + } + + inline _UCXXEXPORT size_type length() const { return vector::size(); } + + void _UCXXEXPORT resize(size_type n, Ch c = Ch()) + { + vector::resize(n, c); + } + + _UCXXEXPORT basic_string& operator+=(const basic_string& str) + { + return append(str); + } + + _UCXXEXPORT basic_string& operator+=(const Ch * s) + { + return append(s); + } + + _UCXXEXPORT basic_string& operator+=(Ch c) + { + vector::push_back(c); + return *this; + } + + _UCXXEXPORT basic_string& append(const basic_string& str) + { + size_t temp = vector::elements; + resize(vector::elements + str.elements); + Tr::copy(vector::data + temp, str.vector::data, str.elements); + + return *this; + } + + _UCXXEXPORT basic_string& append(const basic_string& str, size_type pos, size_type n) + { + if (pos > str.size()) + { +#ifdef CONFIG_UCLIBCXX_EXCEPTION + __throw_out_of_range(); +#else + std::terminate(); +#endif + } + + size_type rlen = str.elements - pos; + if (rlen > n) + { + rlen = n; + } + + if (vector::elements > npos - rlen) + { +#ifdef CONFIG_UCLIBCXX_EXCEPTION + __throw_length_error(); +#else + std::terminate(); +#endif + } + + size_t temp = vector::elements; + resize(vector::elements + rlen); + Tr::copy(vector::data + temp, str.vector::data + pos, rlen); + return *this; + } + + _UCXXEXPORT basic_string& append(const Ch* s, size_type n) + { + size_t temp = vector::elements; + resize(vector::elements + n); + Tr::copy(vector::data + temp, s, n); + return *this; + } + + _UCXXEXPORT basic_string& append(const Ch* s) + { + size_type strLen = Tr::length(s); + size_t temp = vector::elements; + resize(vector::elements + strLen); + Tr::copy(vector::data + temp, s, strLen); + return *this; + } + + _UCXXEXPORT basic_string& append(size_type n, Ch c) + { + vector::resize(vector::elements + n, c); + return *this; + } + + _UCXXEXPORT basic_string& assign(const basic_string& str) + { + operator=(str); + return *this; + } + + _UCXXEXPORT basic_string& assign(const basic_string& str, size_type pos, size_type n) + { + if (pos > str.elements) + { +#ifdef CONFIG_UCLIBCXX_EXCEPTION + __throw_out_of_range(); +#else + std::terminate(); +#endif + } + + size_type r = str.elements - pos; + if (r > n) + { + r = n; + } + + resize(r); + Tr::copy(vector::data, str.vector::data + pos, r); + return *this; + } + + _UCXXEXPORT basic_string& assign(const Ch* s, size_type n) + { + resize(n); + Tr::copy(vector::data, s, n); + return *this; + } + + _UCXXEXPORT basic_string& assign(const Ch* s) + { + size_type len = Tr::length(s); + return assign(s, len); + } + + _UCXXEXPORT basic_string& assign(size_type n, Ch c) + { + vector::clear(); + vector::resize(n, Ch()); + return *this; + } + + template _UCXXEXPORT basic_string& assign(InputIterator first, InputIterator last) + { + vector::resize(0, Ch()); + while (first != last) + { + append(*first); + ++first; + } + + return *this; + } + + _UCXXEXPORT basic_string& insert(size_type pos1, const basic_string& str, size_type pos2=0, size_type n=npos) + { + if (pos1 > vector::elements || pos2 > str.elements) + { +#ifdef CONFIG_UCLIBCXX_EXCEPTION + __throw_out_of_range(); +#else + std::terminate(); +#endif + } + + size_type r = str.elements - pos2; + if (r > n) + { + r = n; + } + + if (vector::elements > npos - r) + { +#ifdef CONFIG_UCLIBCXX_EXCEPTION + __throw_length_error(); +#else + std::terminate(); +#endif + } + + size_type temp = vector::elements; + resize(vector::elements + r); + Tr::move(vector::data + pos1 + r, vector::data + pos1, temp - pos1); + Tr::copy(vector::data + pos1, str.vector::data + pos2, r); + return *this; + } + + _UCXXEXPORT basic_string& insert(size_type pos, const Ch* s, size_type n) + { + if (pos > vector::elements) + { +#ifdef CONFIG_UCLIBCXX_EXCEPTION + __throw_out_of_range(); +#else + std::terminate(); +#endif + } + + if (vector::elements > npos - n) + { +#ifdef CONFIG_UCLIBCXX_EXCEPTION + __throw_length_error(); +#else + std::terminate(); +#endif + } + + size_type temp = vector::elements; + resize(vector::elements + n); + Tr::move(vector::data + pos + n, vector::data + pos, temp - pos); + Tr::copy(vector::data + pos, s, n); + return *this; + } + + inline _UCXXEXPORT basic_string& insert(size_type pos, const Ch* s) + { + size_type len = Tr::length(s); + return insert(pos, s, len); + } + + _UCXXEXPORT basic_string& insert(size_type pos, size_type n, Ch c) + { + if (pos > vector::elements) + { +#ifdef CONFIG_UCLIBCXX_EXCEPTION + __throw_out_of_range(); +#else + std::terminate(); +#endif + } + + if (vector::elements > npos - n) + { +#ifdef CONFIG_UCLIBCXX_EXCEPTION + __throw_length_error(); +#else + std::terminate(); +#endif + } + + size_type temp = vector::elements; + resize(vector::elements + n); + Tr::move(vector::data + pos + n, vector::data + pos, temp - pos); + Tr::assign(vector::data + pos, n, c); + return *this; + } + + using vector::insert; +// void insert(iterator p, size_type n, charT c); +// template void insert(iterator p, InputIterator first, InputIterator last); + + _UCXXEXPORT basic_string& erase(size_type pos = 0, size_type n = npos) + { + size_type xlen = vector::elements - pos; + + if (xlen > n) + { + xlen = n; + } + + size_type temp = vector::elements; + + Tr::move(vector::data + pos, vector::data + pos + xlen, temp - pos - xlen); + resize(temp - xlen); + return *this; + } + + _UCXXEXPORT iterator erase(iterator position) + { + if (position == vector::end()) + { + return position; + } + + ++position; + + iterator temp = position; + + while (position != vector::end()) + { + *(position-1) = *position; + ++position; + } + + vector::pop_back(); + return temp; + } + + _UCXXEXPORT iterator erase(iterator first, iterator last) + { + size_t count = last - first; + + iterator temp = last; + + while (last != vector::end()) + { + *(last - count) = *last; + ++last; + } + + resize(vector::elements-count); + + return temp; + } + + _UCXXEXPORT basic_string& + replace(size_type pos1, size_type n1, const basic_string& str, size_type pos2=0, size_type n2=npos) + { + if (pos1 > vector::elements) + { +#ifdef CONFIG_UCLIBCXX_EXCEPTION + __throw_out_of_range(); +#else + std::terminate(); +#endif + } + + size_type xlen = vector::elements - pos1; + if (xlen > n1) + { + xlen = n1; + } + + size_type rlen = str.elements - pos2; + if (rlen > n2) + { + rlen = n2; + } + + if ((vector::elements - xlen) >= (npos - rlen)) + { +#ifdef CONFIG_UCLIBCXX_EXCEPTION + __throw_length_error(); +#else + std::terminate(); +#endif + } + + size_t temp = vector::elements; + + if (rlen > xlen) + { + //Only if making larger + + resize(temp - xlen + rlen); + } + + //Final length = vector::elements - xlen + rlen + //Initial block is of size pos1 + //Block 2 is of size len + + Tr::move(vector::data + pos1 + rlen, vector::data + pos1 + xlen, temp - pos1 - xlen); + Tr::copy(vector::data + pos1, str.vector::data + pos2, rlen); + resize(temp - xlen + rlen); + return *this; + } + + _UCXXEXPORT basic_string& replace(size_type pos, size_type n1, const Ch* s, size_type n2) + { + return replace(pos,n1,basic_string(s,n2)); + } + + inline _UCXXEXPORT basic_string& replace(size_type pos, size_type n1, const Ch* s) + { + return replace(pos,n1,basic_string(s)); + } + + _UCXXEXPORT basic_string& replace(size_type pos, size_type n1, size_type n2, Ch c) + { + return replace(pos,n1,basic_string(n2,c)); + } + +// _UCXXEXPORT basic_string& replace(iterator i1, iterator i2, const basic_string& str); +// _UCXXEXPORT basic_string& replace(iterator i1, iterator i2, const Ch* s, size_type n); +// _UCXXEXPORT basic_string& replace(iterator i1, iterator i2, const Ch* s); +// _UCXXEXPORT basic_string& replace(iterator i1, iterator i2, size_type n, Ch c); +/* template _UCXXEXPORT basic_string& replace(iterator i1, iterator i2, + InputIterator j1, InputIterator j2);*/ + + size_type _UCXXEXPORT copy(Ch* s, size_type n, size_type pos = 0) const + { + if (pos > vector::elements) + { +#ifdef CONFIG_UCLIBCXX_EXCEPTION + __throw_out_of_range(); +#else + std::terminate(); +#endif + } + + size_type r = vector::elements - pos; + if (r > n) + { + r = n; + } + + Tr::copy(s, vector::data + pos, r); + return r; + } + + _UCXXEXPORT void swap(basic_string& s) + { + //Data pointers + + vector::swap(s); + } + + _UCXXEXPORT const Ch* c_str() const + { + const_cast *>(this)->reserve(vector::elements+1); + vector::data[vector::elements] = 0; //Add 0 at the end + return vector::data; + } + + _UCXXEXPORT const Ch* data() const + { + return vector::data; + } + + _UCXXEXPORT allocator_type get_allocator() const + { + return vector::a; + } + + _UCXXEXPORT size_type find (const basic_string& str, size_type pos = 0) const; //Below + + _UCXXEXPORT size_type find (const Ch* s, size_type pos, size_type n) const + { + return find(basic_string(s,n), pos); + } + + _UCXXEXPORT size_type find (const Ch* s, size_type pos = 0) const + { + return find(basic_string(s), pos); + } + + _UCXXEXPORT size_type find (Ch c, size_type pos = 0) const + { + for (size_type i = pos; i < length(); ++i) + { + if (this->operator[](i) == c) + { + return i; + } + } + + return npos; + } + + _UCXXEXPORT size_type rfind(const basic_string& str, size_type pos = npos) const + { + if (pos >= length()) + { + pos = length(); + } + + for (size_type i = pos; i > 0; --i) + { + if (str == substr(i-1, str.length())) + { + return i-1; + } + } + + return npos; + } + + _UCXXEXPORT size_type rfind(const Ch* s, size_type pos, size_type n) const + { + return rfind(basic_string(s,n),pos); + } + + _UCXXEXPORT size_type rfind(const Ch* s, size_type pos = npos) const + { + return rfind(basic_string(s),pos); + } + + _UCXXEXPORT size_type rfind(Ch c, size_type pos = npos) const + { + return rfind(basic_string(1,c),pos); + } + + _UCXXEXPORT size_type find_first_of(const basic_string& str, size_type pos = 0) const + { + for (size_type i = pos; i < length(); ++i) + { + for (size_type j = 0; j < str.length() ; ++j) + { + if (Tr::eq(str[j], this->operator[](i))) + { + return i; + } + } + } + + return npos; + } + + _UCXXEXPORT size_type find_first_of(const Ch* s, size_type pos, size_type n) const + { + return find_first_of(basic_string(s,n),pos); + } + + _UCXXEXPORT size_type find_first_of(const Ch* s, size_type pos = 0) const + { + return find_first_of(basic_string(s),pos); + } + + _UCXXEXPORT size_type find_first_of(Ch c, size_type pos = 0) const + { + for (size_type i = pos; i< length(); ++i) + { + if (Tr::eq(this->operator[](i), c)) + { + return i; + } + } + + return npos; + } + + _UCXXEXPORT size_type find_last_of (const basic_string& str, size_type pos = npos) const + { + if (pos > length()) + { + pos = length(); + } + + for (size_type i = pos; i >0 ; --i) + { + for (size_type j = 0 ; j < str.length(); ++j) + { + if (Tr::eq(this->operator[](i-1), str[j])) + { + return i-1; + } + } + } + + return npos; + } + + _UCXXEXPORT size_type find_last_of (const Ch* s, size_type pos, size_type n) const + { + return find_last_of(basic_string(s,n),pos); + } + + _UCXXEXPORT size_type find_last_of (const Ch* s, size_type pos = npos) const + { + return find_last_of(basic_string(s),pos); + } + + _UCXXEXPORT size_type find_last_of (Ch c, size_type pos = npos) const + { + if (pos > length()) + { + pos = length(); + } + + for (size_type i = pos; i >0 ; --i) + { + if (Tr::eq(this->operator[](i-1), c)) + { + return i-1; + } + } + + return npos; + } + + _UCXXEXPORT size_type find_first_not_of(const basic_string& str, size_type pos = 0) const + { + bool foundCharacter; + for (size_type i = pos; i < length(); ++i) + { + foundCharacter = false; + for (size_type j = 0; j < str.length() ; ++j) + { + if (Tr::eq(str[j], this->operator[](i))) + { + foundCharacter = true; + } + } + + if (foundCharacter == false) + { + return i; + } + } + + return npos; + } + + _UCXXEXPORT size_type find_first_not_of(const Ch* s, size_type pos, size_type n) const + { + return find_first_not_of(basic_string(s,n),pos); + } + + _UCXXEXPORT size_type find_first_not_of(const Ch* s, size_type pos = 0) const + { + return find_first_not_of(basic_string(s),pos); + } + + _UCXXEXPORT size_type find_first_not_of(Ch c, size_type pos = 0) const + { + for (size_type i = pos; i < length() ; ++i) + { + if (this->operator[](i) != c) + { + return i; + } + } + + return npos; + } + + _UCXXEXPORT size_type find_last_not_of (const basic_string& str, size_type pos = npos) const + { + size_type xpos(length() - 1); + if (xpos > pos) + { + xpos = pos; + } + + while (xpos != npos && npos != str.find_first_of(this->at(xpos))) + { + --xpos; + } + + return xpos; + } + + _UCXXEXPORT size_type find_last_not_of (const Ch* s, size_type pos, size_type n) const + { + return find_last_not_of(basic_string(s,n),pos); + } + + _UCXXEXPORT size_type find_last_not_of (const Ch* s, size_type pos = npos) const + { + return find_last_not_of(basic_string(s),pos); + } + + _UCXXEXPORT size_type find_last_not_of (Ch c, size_type pos = npos) const + { + size_type xpos(length() - 1); + if (xpos > pos) + { + xpos = pos; + } + + while (xpos != npos && Tr::eq(this->at(xpos), c)) + { + --xpos; + } + + return xpos; + } + + _UCXXEXPORT basic_string substr(size_type pos = 0, size_type n = npos) const; + + _UCXXEXPORT int compare(const basic_string& str) const + { + size_type rlen = vector::elements; + if (rlen > str.elements) + { + rlen = str.elements; + } + + int retval = Tr::compare(vector::data, str.vector::data, rlen); + if (retval == 0) + { + if (vector::elements < str.elements) + { + retval = -1; + } + + if (vector::elements > str.elements) + { + retval = 1; + } + } + + return retval; + } + + _UCXXEXPORT int compare(size_type pos1, size_type n1, const basic_string& str, + size_type pos2=0, size_type n2=npos) const + { + size_type len1 = vector::elements - pos1; + if (len1 > n1) + { + len1 = n1; + } + + size_type len2 = str.vector::elements - pos2; + if (len2 > n2) + { + len2 = n2; + } + + size_type rlen = len1; + if (rlen > len2) + { + rlen = len2; + } + + int retval = Tr::compare(vector::data + pos1, str.vector::data + pos2, rlen); + if (retval == 0) + { + if (len1 < len2) + { + retval = -1; + } + + if (len1 > len2) + { + retval = 1; + } + } + + return retval; + } + + _UCXXEXPORT int compare(const Ch* s) const + { + size_type slen = Tr::length(s); + size_type rlen = slen; + if (rlen > vector::elements) + { + rlen=vector::elements; + } + + int retval = Tr::compare(vector::data, s, rlen); + if (retval==0) + { + if (vector::elements < slen) + { + retval = -1; + } + + if (vector::elements > slen) + { + retval = 1; + } + } + + return retval; + } + + _UCXXEXPORT int compare(size_type pos1, size_type n1, const Ch* s, size_type n2 = npos) const + { + size_type len1 = vector::elements - pos1; + if (len1 > n1) + { + len1 = n1; + } + + size_type slen = Tr::length(s); + size_type len2 = slen; + if (len2 > n2) + { + len2 = n2; + } + + size_type rlen = len1; + if (rlen > len2) + { + rlen = len2; + } + + int retval = Tr::compare(vector::data + pos1, s, rlen); + if (retval == 0) + { + if (len1 < len2) + { + retval = -1; + } + + if (len1 > len2) + { + retval = 1; + } + } + + return retval; + } }; //Functions template _UCXXEXPORT basic_string::basic_string(const Ch* s, const A& al) - : vector(al) + : vector(al) { - if(s!=0){ - size_type temp = Tr::length(s); - append(s, temp); - } + if (s!=0) + { + size_type temp = Tr::length(s); + append(s, temp); + } } template _UCXXEXPORT basic_string:: - basic_string(const basic_string& str, size_type pos, size_type n, const A& al) - : vector(al) + basic_string(const basic_string& str, size_type pos, size_type n, const A& al) + : vector(al) { - if(pos>str.size()){ - __throw_out_of_range(); - } - size_type rlen = str.size() - pos; - if( rlen > n){ - rlen = n; - } - resize(rlen); - Tr::copy(vector::data, str.vector::data + pos, vector::elements); + if (pos>str.size()) + { +#ifdef CONFIG_UCLIBCXX_EXCEPTION + __throw_out_of_range(); +#else + std::terminate(); +#endif + } + + size_type rlen = str.size() - pos; + if (rlen > n) + { + rlen = n; + } + + resize(rlen); + Tr::copy(vector::data, str.vector::data + pos, vector::elements); } template _UCXXEXPORT basic_string& - basic_string::operator=(const basic_string & str) + basic_string::operator=(const basic_string & str) { - if(&str == this){ //Check if we are doing a=a - return *this; - } - vector::clear(); - resize(str.elements); - Tr::copy( vector::data, str.vector::data, str.elements); - return *this; -} + if (&str == this) + { + //Check if we are doing a=a + return *this; + } + + vector::clear(); + resize(str.elements); + Tr::copy(vector::data, str.vector::data, str.elements); + return *this; +} template _UCXXEXPORT typename basic_string::size_type - basic_string::find (const basic_string& str, size_type pos) const + basic_string::find (const basic_string& str, size_type pos) const { - if(str.length() > length()){ - return npos; - } - size_type max_string_start = 1 + length() - str.length(); - for(size_type i = pos; i < max_string_start; ++i){ - if(str == substr(i, str.length())){ - return i; - } - } - return npos; + if (str.length() > length()) + { + return npos; + } + + size_type max_string_start = 1 + length() - str.length(); + for (size_type i = pos; i < max_string_start; ++i) + { + if (str == substr(i, str.length())) + { + return i; + } + } + + return npos; } - template - _UCXXEXPORT basic_string basic_string::substr(size_type pos, size_type n) const + _UCXXEXPORT basic_string basic_string::substr(size_type pos, size_type n) const { - if(pos > vector::elements){ - __throw_out_of_range(); - } - size_type rlen = vector::elements - pos; - if(rlen > n){ - rlen = n; - } - return basic_string(vector::data + pos,rlen); -} - + if (pos > vector::elements) + { +#ifdef CONFIG_UCLIBCXX_EXCEPTION + __throw_out_of_range(); +#else + std::terminate(); +#endif + } + size_type rlen = vector::elements - pos; + if (rlen > n) + { + rlen = n; + } + return basic_string(vector::data + pos,rlen); +} #ifdef __UCLIBCXX_EXPAND_STRING_CHAR__ #ifndef __UCLIBCXX_COMPILE_STRING__ - #ifdef __UCLIBCXX_EXPAND_CONSTRUCTORS_DESTRUCTORS__ - template <> _UCXXEXPORT string::basic_string(const allocator &); - template <> _UCXXEXPORT string::basic_string(size_type n, char c, const allocator & ); - template <> _UCXXEXPORT string::basic_string(const char* s, const allocator& al); - template <> _UCXXEXPORT string::basic_string(const basic_string& str, size_type pos, size_type n, const allocator& al); - template <> _UCXXEXPORT string::~basic_string(); + template <> _UCXXEXPORT string::basic_string(const allocator &); + template <> _UCXXEXPORT string::basic_string(size_type n, char c, const allocator &); + template <> _UCXXEXPORT string::basic_string(const char* s, const allocator& al); + template <> _UCXXEXPORT string::basic_string(const basic_string& str, size_type pos, size_type n, const allocator& al); + template <> _UCXXEXPORT string::~basic_string(); #endif - template <> _UCXXEXPORT string & string::append(const char * s, size_type n); - + template <> _UCXXEXPORT string & string::append(const char * s, size_type n); - template <> _UCXXEXPORT string::size_type string::find(const string & str, size_type pos) const; - template <> _UCXXEXPORT string::size_type string::find(const char* s, size_type pos) const; - template <> _UCXXEXPORT string::size_type string::find (char c, size_type pos) const; + template <> _UCXXEXPORT string::size_type string::find(const string & str, size_type pos) const; + template <> _UCXXEXPORT string::size_type string::find(const char* s, size_type pos) const; + template <> _UCXXEXPORT string::size_type string::find (char c, size_type pos) const; - template <> _UCXXEXPORT string::size_type string::rfind(const string & str, size_type pos) const; - template <> _UCXXEXPORT string::size_type string::rfind(char c, size_type pos) const; - template <> _UCXXEXPORT string::size_type string::rfind(const char* s, size_type pos) const; + template <> _UCXXEXPORT string::size_type string::rfind(const string & str, size_type pos) const; + template <> _UCXXEXPORT string::size_type string::rfind(char c, size_type pos) const; + template <> _UCXXEXPORT string::size_type string::rfind(const char* s, size_type pos) const; - template <> _UCXXEXPORT string::size_type string::find_first_of(const string &, size_type) const; - template <> _UCXXEXPORT string::size_type string::find_first_of(const char *, size_type pos, size_type n) const; - template <> _UCXXEXPORT string::size_type string::find_first_of(const char*, size_type pos) const; - template <> _UCXXEXPORT string::size_type string::find_first_of(char c, size_type pos) const; + template <> _UCXXEXPORT string::size_type string::find_first_of(const string &, size_type) const; + template <> _UCXXEXPORT string::size_type string::find_first_of(const char *, size_type pos, size_type n) const; + template <> _UCXXEXPORT string::size_type string::find_first_of(const char*, size_type pos) const; + template <> _UCXXEXPORT string::size_type string::find_first_of(char c, size_type pos) const; - template <> _UCXXEXPORT string::size_type string::find_last_of (const string & , size_type pos) const; - template <> _UCXXEXPORT string::size_type string::find_last_of (const char* s, size_type pos, size_type n) const; - template <> _UCXXEXPORT string::size_type string::find_last_of (const char* s, size_type pos) const; - template <> _UCXXEXPORT string::size_type string::find_last_of (char c, size_type pos) const; + template <> _UCXXEXPORT string::size_type string::find_last_of (const string & , size_type pos) const; + template <> _UCXXEXPORT string::size_type string::find_last_of (const char* s, size_type pos, size_type n) const; + template <> _UCXXEXPORT string::size_type string::find_last_of (const char* s, size_type pos) const; + template <> _UCXXEXPORT string::size_type string::find_last_of (char c, size_type pos) const; - template <> _UCXXEXPORT string::size_type string::find_first_not_of(const string &, size_type) const; - template <> _UCXXEXPORT string::size_type string::find_first_not_of(const char*, size_type, size_type) const; - template <> _UCXXEXPORT string::size_type string::find_first_not_of(const char*, size_type) const; - template <> _UCXXEXPORT string::size_type string::find_first_not_of(char c, size_type) const; + template <> _UCXXEXPORT string::size_type string::find_first_not_of(const string &, size_type) const; + template <> _UCXXEXPORT string::size_type string::find_first_not_of(const char*, size_type, size_type) const; + template <> _UCXXEXPORT string::size_type string::find_first_not_of(const char*, size_type) const; + template <> _UCXXEXPORT string::size_type string::find_first_not_of(char c, size_type) const; - template <> _UCXXEXPORT int string::compare(const string & str) const; - template <> _UCXXEXPORT int string::compare( - size_type pos1, size_type n1, const string & str, size_type pos2, size_type n2) const; + template <> _UCXXEXPORT int string::compare(const string & str) const; + template <> _UCXXEXPORT int string::compare( + size_type pos1, size_type n1, const string & str, size_type pos2, size_type n2) const; - template <> _UCXXEXPORT string string::substr(size_type pos, size_type n) const; + template <> _UCXXEXPORT string string::substr(size_type pos, size_type n) const; - template <> _UCXXEXPORT string & string::operator=(const string & str); - template <> _UCXXEXPORT string & string::operator=(const char * s); + template <> _UCXXEXPORT string & string::operator=(const string & str); + template <> _UCXXEXPORT string & string::operator=(const char * s); #endif #endif - - - //typedef basic_string string; template _UCXXEXPORT basic_string - operator+(const basic_string& lhs, const basic_string& rhs) + operator+(const basic_string& lhs, const basic_string& rhs) { - basic_string temp(lhs); - temp.append(rhs); - return temp; + basic_string temp(lhs); + temp.append(rhs); + return temp; } template _UCXXEXPORT basic_string - operator+(const charT* lhs, const basic_string& rhs) + operator+(const charT* lhs, const basic_string& rhs) { - basic_string temp(lhs); - temp.append(rhs); - return temp; + basic_string temp(lhs); + temp.append(rhs); + return temp; } - template _UCXXEXPORT basic_string - operator+(charT lhs, const basic_string& rhs) + operator+(charT lhs, const basic_string& rhs) { - basic_string temp(1, lhs); - temp.append(rhs); - return temp; + basic_string temp(1, lhs); + temp.append(rhs); + return temp; } template _UCXXEXPORT basic_string - operator+(const basic_string& lhs, const charT* rhs) + operator+(const basic_string& lhs, const charT* rhs) { - basic_string temp(lhs); - temp.append(rhs); - return temp; + basic_string temp(lhs); + temp.append(rhs); + return temp; } template _UCXXEXPORT basic_string - operator+(const basic_string& lhs, charT rhs) + operator+(const basic_string& lhs, charT rhs) { - basic_string temp(lhs); - temp+=rhs; - return temp; + basic_string temp(lhs); + temp+=rhs; + return temp; } template _UCXXEXPORT bool - operator==(const basic_string& lhs, const basic_string& rhs) + operator==(const basic_string& lhs, const basic_string& rhs) { - if(lhs.compare(rhs) == 0){ - return true; - } - return false; + if (lhs.compare(rhs) == 0) + { + return true; + } + + return false; } template _UCXXEXPORT bool - operator==(const charT* lhs, const basic_string& rhs) + operator==(const charT* lhs, const basic_string& rhs) { - if(rhs.compare(lhs) == 0){ - return true; - } - return false; + if (rhs.compare(lhs) == 0) + { + return true; + } + + return false; } template _UCXXEXPORT bool - operator==(const basic_string& lhs, const charT* rhs) + operator==(const basic_string& lhs, const charT* rhs) { - if(lhs.compare(rhs)==0){ - return true; - } - return false; + if (lhs.compare(rhs)==0) + { + return true; + } + + return false; } template _UCXXEXPORT bool - operator!=(const basic_string& lhs, const basic_string& rhs) + operator!=(const basic_string& lhs, const basic_string& rhs) { - if(lhs.compare(rhs) !=0){ - return true; - } - return false; + if (lhs.compare(rhs) !=0) + { + return true; + } + + return false; } template _UCXXEXPORT bool - operator!=(const charT* lhs, const basic_string& rhs) + operator!=(const charT* lhs, const basic_string& rhs) { - basic_string temp(lhs); - return (temp != rhs); + basic_string temp(lhs); + return (temp != rhs); } template _UCXXEXPORT bool - operator!=(const basic_string& lhs, const charT* rhs) + operator!=(const basic_string& lhs, const charT* rhs) { - basic_string temp(rhs); - return (lhs != temp); + basic_string temp(rhs); + return (lhs != temp); } template _UCXXEXPORT bool - operator< (const basic_string& lhs, const basic_string& rhs) + operator< (const basic_string& lhs, const basic_string& rhs) { - if(lhs.compare(rhs) < 0){ - return true; - } - return false; + if (lhs.compare(rhs) < 0) + { + return true; + } + + return false; } template _UCXXEXPORT bool - operator< (const basic_string& lhs, const charT* rhs) + operator< (const basic_string& lhs, const charT* rhs) { - basic_string temp(rhs); - if(lhs.compare(rhs) < 0){ - return true; - } - return false; + basic_string temp(rhs); + if (lhs.compare(rhs) < 0) + { + return true; + } + + return false; } template _UCXXEXPORT bool - operator< (const charT* lhs, const basic_string& rhs) + operator< (const charT* lhs, const basic_string& rhs) { - basic_string temp(lhs); - if(temp.compare(rhs) < 0){ - return true; - } - return false; + basic_string temp(lhs); + if (temp.compare(rhs) < 0) + { + return true; + } + + return false; } template _UCXXEXPORT bool - operator> (const basic_string& lhs, const basic_string& rhs) + operator> (const basic_string& lhs, const basic_string& rhs) { - if(lhs.compare(rhs) > 0){ - return true; - } - return false; + if (lhs.compare(rhs) > 0) + { + return true; + } + + return false; } template _UCXXEXPORT bool - operator> (const basic_string& lhs, const charT* rhs) + operator> (const basic_string& lhs, const charT* rhs) { - basic_string temp(rhs); - if(lhs.compare(rhs) > 0){ - return true; - } - return false; + basic_string temp(rhs); + if (lhs.compare(rhs) > 0) + { + return true; + } + + return false; } template _UCXXEXPORT bool - operator> (const charT* lhs, const basic_string& rhs) + operator> (const charT* lhs, const basic_string& rhs) { - basic_string temp(lhs); - if(temp.compare(rhs) > 0){ - return true; - } - return false; + basic_string temp(lhs); + if (temp.compare(rhs) > 0) + { + return true; + } + + return false; } template _UCXXEXPORT bool - operator<=(const basic_string& lhs, const basic_string& rhs) + operator<=(const basic_string& lhs, const basic_string& rhs) { - if(lhs.compare(rhs) <=0){ - return true; - } - return false; + if (lhs.compare(rhs) <=0) + { + return true; + } + + return false; } template _UCXXEXPORT bool - operator<=(const basic_string& lhs, const charT* rhs) + operator<=(const basic_string& lhs, const charT* rhs) { - basic_string temp(rhs); - if(lhs.compare(temp) <=0 ){ - return true; - } - return false; + basic_string temp(rhs); + if (lhs.compare(temp) <=0) + { + return true; + } + + return false; } template _UCXXEXPORT bool - operator<=(const charT* lhs, const basic_string& rhs) + operator<=(const charT* lhs, const basic_string& rhs) { - basic_string temp(lhs); - if(temp.compare(rhs) <= 0){ - return true; - } - return false; + basic_string temp(lhs); + if (temp.compare(rhs) <= 0) + { + return true; + } + + return false; } template _UCXXEXPORT bool - operator>=(const basic_string& lhs, const basic_string& rhs) + operator>=(const basic_string& lhs, const basic_string& rhs) { - if(lhs.compare(rhs) >=0){ - return true; - } - return false; + if (lhs.compare(rhs) >=0) + { + return true; + } + + return false; } template _UCXXEXPORT bool - operator>=(const basic_string& lhs, const charT* rhs) + operator>=(const basic_string& lhs, const charT* rhs) { - basic_string temp(rhs); - if(lhs.compare(temp) >=0 ){ - return true; - } - return false; + basic_string temp(rhs); + if (lhs.compare(temp) >=0) + { + return true; + } + + return false; } template _UCXXEXPORT bool - operator>=(const charT* lhs, const basic_string& rhs) + operator>=(const charT* lhs, const basic_string& rhs) { - basic_string temp(lhs); - if(temp.compare(rhs) >=0 ){ - return true; - } - return false; + basic_string temp(lhs); + if (temp.compare(rhs) >=0) + { + return true; + } + + return false; } template _UCXXEXPORT void - swap(basic_string& lhs, basic_string& rhs) + swap(basic_string& lhs, basic_string& rhs) { - lhs.swap(rhs); + lhs.swap(rhs); } /*template _UCXXEXPORT basic_ostream& - operator<<(basic_ostream& os, const basic_string& str) + operator<<(basic_ostream& os, const basic_string& str) { - return os.write(str.data(), str.length()); + return os.write(str.data(), str.length()); }*/ #ifdef __UCLIBCXX_EXPAND_STRING_CHAR__ @@ -1031,12 +1329,9 @@ template <> _UCXXEXPORT string operator+(const string & lhs, const string & rhs) template <> _UCXXEXPORT bool operator> (const string & lhs, const string & rhs); template <> _UCXXEXPORT bool operator< (const string & lhs, const string & rhs); - #endif #endif - - -} +} // namespace #pragma GCC visibility pop diff --git a/misc/uClibc++/libxx/uClibc++/Make.defs b/misc/uClibc++/libxx/uClibc++/Make.defs index 2a877ee3e..b8f7a7092 100644 --- a/misc/uClibc++/libxx/uClibc++/Make.defs +++ b/misc/uClibc++/libxx/uClibc++/Make.defs @@ -37,13 +37,16 @@ CXXSRCS += algorithm.cxx associative_base.cxx bitset.cxx char_traits.cxx CXXSRCS += complex.cxx del_op.cxx del_opnt.cxx del_opv.cxx del_opvnt.cxx -CXXSRCS += deque.cxx exception.cxx fstream.cxx func_exception.cxx -CXXSRCS += iomanip.cxx ios.cxx iostream.cxx istream.cxx iterator.cxx -CXXSRCS += limits.cxx list.cxx locale.cxx map.cxx new_handler.cxx -CXXSRCS += new_op.cxx new_opnt.cxx new_opv.cxx new_opvnt.cxx numeric.cxx -CXXSRCS += ostream.cxx queue.cxx set.cxx sstream.cxx stack.cxx -CXXSRCS += stdexcept.cxx streambuf.cxx string.cxx typeinfo.cxx utility.cxx -CXXSRCS += valarray.cxx vector.cxx +CXXSRCS += deque.cxx fstream.cxx iomanip.cxx ios.cxx iostream.cxx +CXXSRCS += istream.cxx iterator.cxx limits.cxx list.cxx locale.cxx +CXXSRCS += map.cxx new_handler.cxx new_op.cxx new_opnt.cxx new_opv.cxx +CXXSRCS += new_opvnt.cxx numeric.cxx ostream.cxx queue.cxx set.cxx +CXXSRCS += sstream.cxx stack.cxx streambuf.cxx string.cxx typeinfo.cxx +CXXSRCS += utility.cxx valarray.cxx vector.cxx + +ifeq ($(CONFIG_UCLIBCXX_EXCEPTION),y) +CXXSRCS += exception.cxx func_exception.cxx stdexcept.cxx +endif ifneq ($(CONFIG_UCLIBCXX_HAVE_LIBSUPCXX),y) CXXSRCS += eh_alloc.cxx eh_globals.cxx eh_terminate.cxx diff --git a/misc/uClibc++/libxx/uClibc++/eh_terminate.cxx b/misc/uClibc++/libxx/uClibc++/eh_terminate.cxx index f64be60d9..1d1aa9eb7 100644 --- a/misc/uClibc++/libxx/uClibc++/eh_terminate.cxx +++ b/misc/uClibc++/libxx/uClibc++/eh_terminate.cxx @@ -20,8 +20,6 @@ #include #include -#ifdef CONFIG_UCLIBCXX_EXCEPTION - namespace std { _UCXXEXPORT static terminate_handler __terminate_handler = abort; @@ -71,5 +69,3 @@ namespace std terminate(); } } - -#endif diff --git a/misc/uClibc++/libxx/uClibc++/func_exception.cxx b/misc/uClibc++/libxx/uClibc++/func_exception.cxx index 9971871ef..d5bbe001f 100644 --- a/misc/uClibc++/libxx/uClibc++/func_exception.cxx +++ b/misc/uClibc++/libxx/uClibc++/func_exception.cxx @@ -22,8 +22,8 @@ #include #include -namespace std{ - +namespace std +{ #ifdef CONFIG_UCLIBCXX_EXCEPTION _UCXXEXPORT void __throw_bad_alloc() @@ -33,7 +33,7 @@ _UCXXEXPORT void __throw_bad_alloc() _UCXXEXPORT void __throw_out_of_range(const char * message) { - if(message == 0) + if (message == 0) { throw out_of_range(); } @@ -43,7 +43,7 @@ _UCXXEXPORT void __throw_out_of_range(const char * message) _UCXXEXPORT void __throw_overflow_error(const char * message) { - if(message == 0) + if (message == 0) { throw overflow_error(); } @@ -53,7 +53,7 @@ _UCXXEXPORT void __throw_overflow_error(const char * message) _UCXXEXPORT void __throw_length_error(const char * message) { - if(message == 0) + if (message == 0) { throw length_error(); } @@ -63,7 +63,7 @@ _UCXXEXPORT void __throw_length_error(const char * message) _UCXXEXPORT void __throw_invalid_argument(const char * message) { - if(message == 0) + if (message == 0) { throw invalid_argument(); } @@ -100,6 +100,4 @@ _UCXXEXPORT void __throw_invalid_argument(const char *) #endif - - -} +} // namespace diff --git a/misc/uClibc++/libxx/uClibc++/stdexcept.cxx b/misc/uClibc++/libxx/uClibc++/stdexcept.cxx index d372c0b77..73238526f 100644 --- a/misc/uClibc++/libxx/uClibc++/stdexcept.cxx +++ b/misc/uClibc++/libxx/uClibc++/stdexcept.cxx @@ -1,63 +1,64 @@ -/* Copyright (C) 2004 Garrett A. Kajmowicz - - This file is part of the uClibc++ Library. - - This library 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 2.1 of the License, or (at your option) any later version. - - This library 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 library; if not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -*/ +/* Copyright (C) 2004 Garrett A. Kajmowicz + * + * This file is part of the uClibc++ Library. + * + * This library 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 2.1 of the License, or (at your option) any later version. + * + * This library 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 library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ #include #include #ifdef CONFIG_UCLIBCXX_EXCEPTION -namespace std{ - - _UCXXEXPORT logic_error::logic_error() throw() : mstring(){ - - } - - _UCXXEXPORT logic_error::logic_error(const string& what_arg) : mstring(what_arg){ - - } - - _UCXXEXPORT const char * logic_error::what() const throw(){ - return mstring.c_str(); - } - - - _UCXXEXPORT out_of_range::out_of_range() : logic_error(){ +namespace std +{ + _UCXXEXPORT logic_error::logic_error() throw() : mstring() + { + } - } + _UCXXEXPORT logic_error::logic_error(const string& what_arg) : mstring(what_arg) + { + } - _UCXXEXPORT out_of_range::out_of_range(const string & what_arg) : logic_error(what_arg) { - - } + _UCXXEXPORT const char * logic_error::what() const throw() + { + return mstring.c_str(); + } - _UCXXEXPORT runtime_error::runtime_error() : mstring(){ + _UCXXEXPORT out_of_range::out_of_range() : logic_error() + { + } - } + _UCXXEXPORT out_of_range::out_of_range(const string & what_arg) : logic_error(what_arg) + { + } - _UCXXEXPORT runtime_error::runtime_error(const string& what_arg) : mstring(what_arg){ + _UCXXEXPORT runtime_error::runtime_error() : mstring() + { + } - } + _UCXXEXPORT runtime_error::runtime_error(const string& what_arg) : mstring(what_arg) + { + } - _UCXXEXPORT const char * runtime_error::what() const throw(){ - return mstring.c_str(); - } + _UCXXEXPORT const char * runtime_error::what() const throw() + { + return mstring.c_str(); + } -} +} // namespace #endif diff --git a/misc/uClibc++/libxx/uClibc++/string.cxx b/misc/uClibc++/libxx/uClibc++/string.cxx index 1edf69b5d..dc99fe29e 100644 --- a/misc/uClibc++/libxx/uClibc++/string.cxx +++ b/misc/uClibc++/libxx/uClibc++/string.cxx @@ -1,20 +1,20 @@ -/* Copyright (C) 2004 Garrett A. Kajmowicz +/* Copyright (C) 2004 Garrett A. Kajmowicz - This file is part of the uClibc++ Library. + This file is part of the uClibc++ Library. - This library 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 2.1 of the License, or (at your option) any later version. + This library 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 2.1 of the License, or (at your option) any later version. - This library 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. + This library 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 library; if not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #define __UCLIBCXX_COMPILE_STRING__ 1 @@ -26,87 +26,81 @@ #include #include -namespace std{ - +namespace std +{ #ifdef __UCLIBCXX_EXPAND_STRING_CHAR__ - #ifdef __UCLIBCXX_EXPAND_CONSTRUCTORS_DESTRUCTORS__ - template _UCXXEXPORT string::basic_string(const allocator &); - template _UCXXEXPORT string::basic_string(size_type n, char c, const allocator & ); - template _UCXXEXPORT string::basic_string(const char* s, const allocator& al); - template _UCXXEXPORT string::basic_string(const basic_string& str, size_type pos, size_type n, const allocator& al); - template _UCXXEXPORT string::~basic_string(); + template _UCXXEXPORT string::basic_string(const allocator &); + template _UCXXEXPORT string::basic_string(size_type n, char c, const allocator & ); + template _UCXXEXPORT string::basic_string(const char* s, const allocator& al); + template _UCXXEXPORT string::basic_string(const basic_string& str, size_type pos, size_type n, const allocator& al); + template _UCXXEXPORT string::~basic_string(); #endif // __UCLIBCXX_EXPAND_CONSTRUCTORS_DESTRUCTORS__ - template _UCXXEXPORT string & string::append(const char * s, size_type n); + template _UCXXEXPORT string & string::append(const char * s, size_type n); - template _UCXXEXPORT string::size_type string::find(const string & str, size_type pos) const; - template _UCXXEXPORT string::size_type string::find(const char* s, size_type pos) const; - template _UCXXEXPORT string::size_type string::find (char c, size_type pos) const; - template _UCXXEXPORT string::size_type string::rfind(const string & str, size_type pos) const; - template _UCXXEXPORT string::size_type string::rfind(char c, size_type pos) const; - template _UCXXEXPORT string::size_type string::rfind(const char* s, size_type pos) const; + template _UCXXEXPORT string::size_type string::find(const string & str, size_type pos) const; + template _UCXXEXPORT string::size_type string::find(const char* s, size_type pos) const; + template _UCXXEXPORT string::size_type string::find (char c, size_type pos) const; + template _UCXXEXPORT string::size_type string::rfind(const string & str, size_type pos) const; + template _UCXXEXPORT string::size_type string::rfind(char c, size_type pos) const; + template _UCXXEXPORT string::size_type string::rfind(const char* s, size_type pos) const; - template _UCXXEXPORT string::size_type string::find_first_of(const string &, size_type) const; - template _UCXXEXPORT string::size_type string::find_first_of(const char *, size_type pos, size_type n) const; - template _UCXXEXPORT string::size_type string::find_first_of(const char*, size_type pos) const; - template _UCXXEXPORT string::size_type string::find_first_of(char c, size_type pos) const; + template _UCXXEXPORT string::size_type string::find_first_of(const string &, size_type) const; + template _UCXXEXPORT string::size_type string::find_first_of(const char *, size_type pos, size_type n) const; + template _UCXXEXPORT string::size_type string::find_first_of(const char*, size_type pos) const; + template _UCXXEXPORT string::size_type string::find_first_of(char c, size_type pos) const; - template _UCXXEXPORT string::size_type string::find_last_of (const string & , size_type pos) const; - template _UCXXEXPORT string::size_type string::find_last_of (const char* s, size_type pos, size_type n) const; - template _UCXXEXPORT string::size_type string::find_last_of (const char* s, size_type pos) const; - template _UCXXEXPORT string::size_type string::find_last_of (char c, size_type pos) const; + template _UCXXEXPORT string::size_type string::find_last_of (const string & , size_type pos) const; + template _UCXXEXPORT string::size_type string::find_last_of (const char* s, size_type pos, size_type n) const; + template _UCXXEXPORT string::size_type string::find_last_of (const char* s, size_type pos) const; + template _UCXXEXPORT string::size_type string::find_last_of (char c, size_type pos) const; - template _UCXXEXPORT string::size_type string::find_first_not_of(const string &, size_type) const; - template _UCXXEXPORT string::size_type string::find_first_not_of(const char*, size_type, size_type) const; - template _UCXXEXPORT string::size_type string::find_first_not_of(const char*, size_type) const; - template _UCXXEXPORT string::size_type string::find_first_not_of(char c, size_type) const; + template _UCXXEXPORT string::size_type string::find_first_not_of(const string &, size_type) const; + template _UCXXEXPORT string::size_type string::find_first_not_of(const char*, size_type, size_type) const; + template _UCXXEXPORT string::size_type string::find_first_not_of(const char*, size_type) const; + template _UCXXEXPORT string::size_type string::find_first_not_of(char c, size_type) const; - template _UCXXEXPORT int string::compare(const string & str) const; -// template _UCXXEXPORT int string::compare(size_type pos1, size_type n1, const string & str) const; - template _UCXXEXPORT int string::compare( - size_type pos1, size_type n1, const string & str, size_type pos2, size_type n2) const; + template _UCXXEXPORT int string::compare(const string & str) const; +//template _UCXXEXPORT int string::compare(size_type pos1, size_type n1, const string & str) const; + template _UCXXEXPORT int string::compare( + size_type pos1, size_type n1, const string & str, size_type pos2, size_type n2) const; - template _UCXXEXPORT string string::substr(size_type pos, size_type n) const; + template _UCXXEXPORT string string::substr(size_type pos, size_type n) const; - template _UCXXEXPORT string & string::operator=(const string & str); - template _UCXXEXPORT string & string::operator=(const char * s); + template _UCXXEXPORT string & string::operator=(const string & str); + template _UCXXEXPORT string & string::operator=(const char * s); - template _UCXXEXPORT bool operator==(const string & lhs, const string & rhs); - template _UCXXEXPORT bool operator==(const char * lhs, const string & rhs); - template _UCXXEXPORT bool operator==(const string & lhs, const char * rhs); + template _UCXXEXPORT bool operator==(const string & lhs, const string & rhs); + template _UCXXEXPORT bool operator==(const char * lhs, const string & rhs); + template _UCXXEXPORT bool operator==(const string & lhs, const char * rhs); - template _UCXXEXPORT bool operator!=(const string & lhs, const string & rhs); - template _UCXXEXPORT bool operator!=(const char * lhs, const string & rhs); - template _UCXXEXPORT bool operator!=(const string & lhs, const char * rhs); + template _UCXXEXPORT bool operator!=(const string & lhs, const string & rhs); + template _UCXXEXPORT bool operator!=(const char * lhs, const string & rhs); + template _UCXXEXPORT bool operator!=(const string & lhs, const char * rhs); - template _UCXXEXPORT string operator+(const string & lhs, const char* rhs); - template _UCXXEXPORT string operator+(const char* lhs, const string & rhs); - template _UCXXEXPORT string operator+(const string & lhs, const string & rhs); + template _UCXXEXPORT string operator+(const string & lhs, const char* rhs); + template _UCXXEXPORT string operator+(const char* lhs, const string & rhs); + template _UCXXEXPORT string operator+(const string & lhs, const string & rhs); - template _UCXXEXPORT bool operator> (const string & lhs, const string & rhs); - template _UCXXEXPORT bool operator< (const string & lhs, const string & rhs); + template _UCXXEXPORT bool operator> (const string & lhs, const string & rhs); + template _UCXXEXPORT bool operator< (const string & lhs, const string & rhs); +// Functions dependent upon OSTREAM -//Functions dependent upon OSTREAM #ifdef __UCLIBCXX_EXPAND_OSTREAM_CHAR__ - template _UCXXEXPORT ostream & operator<<(ostream & os, const string & str); - #endif -//Functions dependent upon ISTREAM -#ifdef __UCLIBCXX_EXPAND_ISTREAM_CHAR__ +// Functions dependent upon ISTREAM +#ifdef __UCLIBCXX_EXPAND_ISTREAM_CHAR__ template _UCXXEXPORT istream & operator>>(istream & is, string & str); - - #endif - #endif -} +} // namespace -- cgit v1.2.3