Stefan Scholz / ETL
Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers string_view.h Source File

string_view.h

Go to the documentation of this file.
00001 ///\file
00002 
00003 /******************************************************************************
00004 The MIT License(MIT)
00005 
00006 Embedded Template Library.
00007 https://github.com/ETLCPP/etl
00008 https://www.etlcpp.com
00009 
00010 Copyright(c) 2017 jwellbelove
00011 
00012 Permission is hereby granted, free of charge, to any person obtaining a copy
00013 of this software and associated documentation files(the "Software"), to deal
00014 in the Software without restriction, including without limitation the rights
00015 to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
00016 copies of the Software, and to permit persons to whom the Software is
00017 furnished to do so, subject to the following conditions :
00018 
00019 The above copyright notice and this permission notice shall be included in all
00020 copies or substantial portions of the Software.
00021 
00022 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00023 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00024 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
00025 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
00026 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
00027 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
00028 SOFTWARE.
00029 ******************************************************************************/
00030 
00031 #ifndef __ETL_STRING_VIEW__
00032 #define __ETL_STRING_VIEW__
00033 
00034 #include "platform.h "
00035 #include "memory.h "
00036 #include "iterator.h "
00037 #include "error_handler.h "
00038 #include "exception.h "
00039 #include "char_traits.h "
00040 #include "integral_limits.h "
00041 #include "hash.h "
00042 
00043 #include <algorithm>
00044 
00045 ///\defgroup array array
00046 /// A wrapper for arrays
00047 ///\ingroup containers
00048 
00049 #undef ETL_FILE
00050 #define ETL_FILE "42"
00051 
00052 #ifdef ETL_COMPILER_MICROSOFT
00053 #undef min
00054 #undef max
00055 #endif
00056 
00057 namespace etl
00058 {
00059   //***************************************************************************
00060   /// The base class for basic_string_view exceptions.
00061   //***************************************************************************
00062   class string_view_exception : public exception
00063   {
00064   public:
00065 
00066     string_view_exception(string_type reason_, string_type file_name_, numeric_type line_number_)
00067       : exception(reason_, file_name_, line_number_)
00068     {
00069     }
00070   };
00071 
00072   //***************************************************************************
00073   ///\ingroup stack
00074   /// The exception thrown when the index is out of bounds.
00075   //***************************************************************************
00076   class string_view_bounds : public string_view_exception
00077   {
00078   public:
00079 
00080     string_view_bounds(string_type file_name_, numeric_type line_number_)
00081       : string_view_exception(ETL_ERROR_TEXT("basic_string_view:bounds", ETL_FILE"A"), file_name_, line_number_)
00082     {
00083     }
00084   };
00085 
00086   //***************************************************************************
00087   ///\ingroup stack
00088   /// The exception thrown when the view is uninitialised.
00089   //***************************************************************************
00090   class string_view_uninitialised : public string_view_exception
00091   {
00092   public:
00093 
00094     string_view_uninitialised(string_type file_name_, numeric_type line_number_)
00095       : string_view_exception(ETL_ERROR_TEXT("basic_string_view:uninitialised", ETL_FILE"B"), file_name_, line_number_)
00096     {
00097     }
00098   };
00099 
00100   //***************************************************************************
00101   /// String view.
00102   //***************************************************************************
00103   template <typename T, typename TTraits = etl::char_traits<T> >
00104   class basic_string_view
00105   {
00106   public:
00107 
00108     typedef T                                     value_type;
00109     typedef TTraits                               traits_type;
00110     typedef std::size_t                           size_type;
00111     typedef const T&                              const_reference;
00112     typedef const T*                              const_pointer;
00113     typedef const T*                              const_iterator;
00114     typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
00115 
00116     enum
00117     {
00118       npos = etl::integral_limits<size_t>::max
00119     };
00120 
00121     //*************************************************************************
00122     /// Default constructor.
00123     //*************************************************************************
00124     basic_string_view()
00125       : mbegin(std::nullptr),
00126         mend(std::nullptr)
00127     {
00128     }
00129 
00130     //*************************************************************************
00131     /// Construct from T*.
00132     //*************************************************************************
00133     basic_string_view(const T* begin_)
00134       : mbegin(begin_),
00135         mend(begin_ + TTraits::length(begin_))
00136     {
00137     }
00138 
00139     //*************************************************************************
00140     /// Construct from pointer range.
00141     //*************************************************************************
00142     basic_string_view(const T* begin_, const T* end_)
00143       : mbegin(begin_),
00144         mend(end_)
00145     {
00146     }
00147 
00148     //*************************************************************************
00149     /// Construct from iterator/size.
00150     //*************************************************************************
00151     template <typename TSize, typename TDummy = typename etl::enable_if<etl::is_integral<TSize>::value, void>::type>
00152     basic_string_view(const T* begin_, TSize size_)
00153       : mbegin(begin_),
00154         mend(begin_ + size_)
00155     {
00156     }
00157 
00158     //*************************************************************************
00159     /// Copy constructor
00160     //*************************************************************************
00161     basic_string_view(const basic_string_view& other)
00162       : mbegin(other.mbegin),
00163         mend(other.mend)
00164     {
00165     }
00166 
00167     //*************************************************************************
00168     /// Returns a const reference to the first element.
00169     //*************************************************************************
00170     const_reference front() const
00171     {
00172       return *mbegin;
00173     }
00174 
00175     //*************************************************************************
00176     /// Returns a const reference to the last element.
00177     //*************************************************************************
00178     const_reference back() const
00179     {
00180       return *(mend - 1);
00181     }
00182 
00183     //*************************************************************************
00184     /// Returns a const pointer to the first element of the internal storage.
00185     //*************************************************************************
00186     const_pointer data() const
00187     {
00188       return mbegin;
00189     }
00190 
00191     //*************************************************************************
00192     /// Returns a const iterator to the beginning of the array.
00193     //*************************************************************************
00194     const_iterator begin() const
00195     {
00196       return mbegin;
00197     }
00198 
00199     //*************************************************************************
00200     /// Returns a const iterator to the beginning of the array.
00201     //*************************************************************************
00202     const_iterator cbegin() const
00203     {
00204       return mbegin;
00205     }
00206 
00207     //*************************************************************************
00208     /// Returns a const iterator to the end of the array.
00209     //*************************************************************************
00210     const_iterator end() const
00211     {
00212       return mend;
00213     }
00214 
00215     //*************************************************************************
00216     // Returns a const iterator to the end of the array.
00217     //*************************************************************************
00218     const_iterator cend() const
00219     {
00220       return mend;
00221     }
00222 
00223     //*************************************************************************
00224     /// Returns a const reverse iterator to the reverse beginning of the array.
00225     //*************************************************************************
00226     const_reverse_iterator rbegin() const
00227     {
00228       return const_reverse_iterator(mend);
00229     }
00230 
00231     //*************************************************************************
00232     /// Returns a const reverse iterator to the reverse beginning of the array.
00233     //*************************************************************************
00234     const_reverse_iterator crbegin() const
00235     {
00236       return const_reverse_iterator(mend);
00237     }
00238 
00239     //*************************************************************************
00240     /// Returns a const reverse iterator to the end of the array.
00241     //*************************************************************************
00242     const_reverse_iterator rend() const
00243     {
00244       return const_reverse_iterator(mbegin);
00245     }
00246 
00247     //*************************************************************************
00248     /// Returns a const reverse iterator to the end of the array.
00249     //*************************************************************************
00250     const_reverse_iterator crend() const
00251     {
00252       return const_reverse_iterator(mbegin);
00253     }
00254 
00255     //*************************************************************************
00256     // Capacity
00257     //*************************************************************************
00258 
00259     //*************************************************************************
00260     /// Returns <b>true</b> if the array size is zero.
00261     //*************************************************************************
00262     bool empty() const
00263     {
00264       return (mbegin == mend);
00265     }
00266 
00267     //*************************************************************************
00268     /// Returns the size of the array.
00269     //*************************************************************************
00270     size_t size() const
00271     {
00272       return (mend - mbegin);
00273     }
00274 
00275     //*************************************************************************
00276     /// Returns the size of the array.
00277     //*************************************************************************
00278     size_t length() const
00279     {
00280       return size();
00281     }
00282 
00283     //*************************************************************************
00284     /// Returns the maximum possible size of the array.
00285     //*************************************************************************
00286     size_t max_size() const
00287     {
00288       return size();
00289     }
00290 
00291     //*************************************************************************
00292     /// Assign from a view.
00293     //*************************************************************************
00294     etl::basic_string_view<T, TTraits>& operator=(const etl::basic_string_view<T, TTraits>& other)
00295     {
00296       mbegin = other.mbegin;
00297       mend = other.mend;
00298       return *this;
00299     }
00300 
00301     //*************************************************************************
00302     /// Assign from iterators
00303     //*************************************************************************
00304     template <typename TIterator,
00305               typename TDummy = typename etl::enable_if<etl::is_random_iterator<TIterator>::value, void>::type>
00306       void assign(TIterator begin_, TIterator end_)
00307     {
00308       mbegin = etl::addressof(*begin_);
00309       mend = etl::addressof(*begin_) + std::distance(begin_, end_);
00310     }
00311 
00312     //*************************************************************************
00313     /// Assign from iterator and size.
00314     //*************************************************************************
00315     template <typename TIterator,
00316               typename TSize,
00317               typename TDummy = typename etl::enable_if<etl::is_random_iterator<TIterator>::value, void>::type>
00318       void assign(TIterator begin_, TSize size_)
00319     {
00320       mbegin = etl::addressof(*begin_);
00321       mend = etl::addressof(*begin_) + size_;
00322     }
00323 
00324     //*************************************************************************
00325     /// Returns a const reference to the indexed value.
00326     //*************************************************************************
00327     const_reference operator[](size_t i) const
00328     {
00329       return mbegin[i];
00330     }
00331 
00332     //*************************************************************************
00333     /// Returns a const reference to the indexed value.
00334     //*************************************************************************
00335     const_reference at(size_t i) const
00336     {
00337       ETL_ASSERT((mbegin != std::nullptr && mend != std::nullptr), ETL_ERROR(string_view_uninitialised));
00338       ETL_ASSERT(i < size(), ETL_ERROR(string_view_bounds));
00339       return mbegin[i];
00340     }
00341 
00342     //*************************************************************************
00343     /// Swaps with another basic_string_view.
00344     //*************************************************************************
00345     void swap(basic_string_view& other)
00346     {
00347       std::swap(mbegin, other.mbegin);
00348       std::swap(mend, other.mend);
00349     }
00350 
00351     //*************************************************************************
00352     /// Copies characters
00353     //*************************************************************************
00354     size_type copy(T* destination, size_type count, size_type position = 0) const
00355     {
00356       size_t n = 0;
00357 
00358       if (position < size())
00359       {
00360         n = std::min(count, size() - position);
00361 
00362         std::copy(mbegin + position, mbegin + position + n, destination);
00363       }
00364 
00365       return n;
00366     }
00367 
00368     //*************************************************************************
00369     /// Returns a substring
00370     //*************************************************************************
00371     basic_string_view substr(size_type position = 0, size_type count = npos) const
00372     {
00373       basic_string_view view;
00374 
00375       if (position < size())
00376       {
00377         size_t n = std::min(count, size() - position);
00378 
00379         view = basic_string_view(mbegin + position, mbegin + position + n);
00380       }
00381 
00382       return view;
00383     }
00384 
00385     //*************************************************************************
00386     /// Shrinks the view by moving its start forward.
00387     //*************************************************************************
00388     void remove_prefix(size_type n)
00389     {
00390       mbegin += n;
00391     }
00392 
00393     //*************************************************************************
00394     /// Shrinks the view by moving its end backward.
00395     //*************************************************************************
00396     void remove_suffix(size_type n)
00397     {
00398       mend -= n;
00399     }
00400 
00401     //*************************************************************************
00402     /// Compares two views
00403     //*************************************************************************
00404     int compare(basic_string_view<T, TTraits> view) const
00405     {
00406       return (*this == view) ? 0 : ((*this > view) ? 1 : -1);
00407     }
00408 
00409     int compare(size_type position, size_type count, basic_string_view view) const
00410     {
00411       return substr(position, count).compare(view);
00412     }
00413 
00414     int compare(size_type position1, size_type count1,
00415                 basic_string_view view,
00416                 size_type position2, size_type count2) const
00417     {
00418       return substr(position1, count1).compare(view.substr(position2, count2));
00419     }
00420 
00421     int compare(const T* text) const
00422     {
00423       return compare(etl::basic_string_view<T, TTraits>(text));
00424     }
00425 
00426     int compare(size_type position, size_type count, const T* text) const
00427     {
00428       return substr(position, count).compare(etl::basic_string_view<T, TTraits>(text));
00429     }
00430 
00431     int compare(size_type position, size_type count1, const T* text, size_type count2) const
00432     {
00433       return substr(position, count1).compare(etl::basic_string_view<T, TTraits>(text, count2));
00434     }
00435 
00436     //*************************************************************************
00437     /// Checks if the string view starts with the given prefix
00438     //*************************************************************************
00439     bool starts_with(etl::basic_string_view<T, TTraits> view) const
00440     {
00441       return (size() >= view.size()) &&
00442              (compare(0, view.size(), view) == 0);
00443     }
00444 
00445     bool starts_with(T c) const
00446     {
00447       return !empty() && (front() == c);
00448     }
00449 
00450     bool starts_with(const T* text) const
00451     {
00452       size_t lengthtext = TTraits::length(text);
00453 
00454       return (size() >= lengthtext) &&
00455              (compare(0, lengthtext, text) == 0);
00456     }
00457 
00458     //*************************************************************************
00459     /// Checks if the string view ends with the given suffix
00460     //*************************************************************************
00461     bool ends_with(etl::basic_string_view<T, TTraits> view) const
00462     {
00463       return (size() >= view.size()) &&
00464              (compare(size() - view.size(), npos, view) == 0);
00465     }
00466 
00467     bool ends_with(T c) const
00468     {
00469       return !empty() && (back() == c);
00470     }
00471 
00472     bool ends_with(const T* text) const
00473     {
00474       size_t lengthtext = TTraits::length(text);
00475       size_t lengthview = size();
00476 
00477       return (lengthview >= lengthtext) &&
00478              (compare(lengthview - lengthtext, lengthtext, text) == 0);
00479     }
00480 
00481     //*************************************************************************
00482     /// Find characters in the view
00483     //*************************************************************************
00484     size_type find(etl::basic_string_view<T, TTraits> view, size_type position = 0) const
00485     {
00486       if ((size() < view.size()))
00487       {
00488         return npos;
00489       }
00490 
00491       const_iterator iposition = std::search(begin() + position, end(), view.begin(), view.end());
00492 
00493       if (iposition == end())
00494       {
00495         return npos;
00496       }
00497       else
00498       {
00499         return std::distance(begin(), iposition);
00500       }
00501     }
00502 
00503     size_type find(T c, size_type position = 0) const
00504     {
00505       return find(etl::basic_string_view<T, TTraits>(&c, 1), position);
00506     }
00507 
00508     size_type find(const T* text, size_type position, size_type count) const
00509     {
00510       return find(etl::basic_string_view<T, TTraits>(text, count), position);
00511     }
00512 
00513     size_type find(const T* text, size_type position = 0) const
00514     {
00515       return find(etl::basic_string_view<T, TTraits>(text), position);
00516     }
00517 
00518     //*************************************************************************
00519     /// Find the last occurrence of a substring
00520     //*************************************************************************
00521     size_type rfind(etl::basic_string_view<T, TTraits> view, size_type position = npos) const
00522     {
00523       if ((size() < view.size()))
00524       {
00525         return npos;
00526       }
00527 
00528       position = std::min(position, size());
00529 
00530       const_iterator iposition = std::find_end(begin(),
00531                                                begin() + position,
00532                                                view.begin(),
00533                                                view.end());
00534 
00535       if (iposition == end())
00536       {
00537         return npos;
00538       }
00539       else
00540       {
00541         return std::distance(begin(), iposition);
00542       }
00543     }
00544 
00545     size_type rfind(T c, size_type position = npos) const
00546     {
00547       return rfind(etl::basic_string_view<T, TTraits>(&c, 1), position);
00548     }
00549 
00550     size_type rfind(const T* text, size_type position, size_type count) const
00551     {
00552       return rfind(etl::basic_string_view<T, TTraits>(text, count), position);
00553     }
00554 
00555     size_type rfind(const T* text, size_type position = npos) const
00556     {
00557       return rfind(etl::basic_string_view<T, TTraits>(text), position);
00558     }
00559 
00560     //*************************************************************************
00561     ///  Find first occurrence of characters
00562     //*************************************************************************
00563     size_type find_first_of(etl::basic_string_view<T, TTraits> view, size_type position = 0) const
00564     {
00565       const size_t lengthtext = size();
00566 
00567       if (position < lengthtext)
00568       {
00569         for (size_t i = position; i < lengthtext; ++i)
00570         {
00571           const size_t lengthview = view.size();
00572 
00573           for (size_t j = 0; j < lengthview; ++j)
00574           {
00575             if (mbegin[i] == view[j])
00576             {
00577               return i;
00578             }
00579           }
00580         }
00581       }
00582 
00583       return npos;
00584     }
00585 
00586     size_type find_first_of(T c, size_type position = 0) const
00587     {
00588       return find_first_of(etl::basic_string_view<T, TTraits>(&c, 1), position);
00589     }
00590 
00591     size_type find_first_of(const T* text, size_type position, size_type count) const
00592     {
00593       return find_first_of(etl::basic_string_view<T, TTraits>(text, count), position);
00594     }
00595 
00596     size_type find_first_of(const T* text, size_type position = 0) const
00597     {
00598       return find_first_of(etl::basic_string_view<T, TTraits>(text), position);
00599     }
00600 
00601     //*************************************************************************
00602     /// Find last occurrence of characters
00603     //*************************************************************************
00604     size_type find_last_of(etl::basic_string_view<T, TTraits> view, size_type position = npos) const
00605     {
00606       if (empty())
00607       {
00608         return npos;
00609       }
00610 
00611       position = std::min(position, size() - 1);
00612 
00613       const_reverse_iterator it = rbegin() + size() - position - 1;
00614 
00615       while (it != rend())
00616       {
00617         const size_t viewlength = view.size();
00618 
00619         for (size_t j = 0; j < viewlength; ++j)
00620         {
00621           if (mbegin[position] == view[j])
00622           {
00623             return position;
00624           }
00625         }
00626 
00627         ++it;
00628         --position;
00629       }
00630 
00631       return npos;
00632     }
00633 
00634     size_type find_last_of(T c, size_type position = npos) const
00635     {
00636       return find_last_of(etl::basic_string_view<T, TTraits>(&c, 1), position);;
00637     }
00638 
00639     size_type find_last_of(const T* text, size_type position, size_type count) const
00640     {
00641       return find_last_of(etl::basic_string_view<T, TTraits>(text, count), position);;
00642     }
00643 
00644     size_type find_last_of(const T* text, size_type position = npos) const
00645     {
00646       return find_last_of(etl::basic_string_view<T, TTraits>(text), position);;
00647     }
00648 
00649     //*************************************************************************
00650     /// Find first absence of characters
00651     //*************************************************************************
00652     size_type find_first_not_of(etl::basic_string_view<T, TTraits> view, size_type position = 0) const
00653     {
00654       const size_t lengthtext = size();
00655 
00656       if (position < lengthtext)
00657       {
00658         for (size_t i = position; i < lengthtext; ++i)
00659         {
00660           bool found = false;
00661 
00662           const size_t viewlength = view.size();
00663 
00664           for (size_t j = 0; j < viewlength; ++j)
00665           {
00666             if (mbegin[i] == view[j])
00667             {
00668               found = true;
00669             }
00670           }
00671 
00672           if (!found)
00673           {
00674             return i;
00675           }
00676         }
00677       }
00678 
00679       return npos;
00680     }
00681 
00682     size_type find_first_not_of(T c, size_type position = 0) const
00683     {
00684       return find_first_not_of(etl::basic_string_view<T, TTraits>(&c, 1), position);
00685     }
00686 
00687     size_type find_first_not_of(const T* text, size_type position, size_type count) const
00688     {
00689       return find_first_not_of(etl::basic_string_view<T, TTraits>(text, count), position);
00690     }
00691 
00692     size_type find_first_not_of(const T* text, size_type position = 0) const
00693     {
00694       return find_first_not_of(etl::basic_string_view<T, TTraits>(text), position);
00695     }
00696 
00697     //*************************************************************************
00698     /// Find last absence of characters
00699     //*************************************************************************
00700     size_type find_last_not_of(etl::basic_string_view<T, TTraits> view, size_type position = npos) const
00701     {
00702       if (empty())
00703       {
00704         return npos;
00705       }
00706 
00707       position = std::min(position, size() - 1);
00708 
00709       const_reverse_iterator it = rbegin() + size() - position - 1;
00710 
00711       while (it != rend())
00712       {
00713         bool found = false;
00714 
00715         const size_t viewlength = view.size();
00716 
00717         for (size_t j = 0; j < viewlength; ++j)
00718         {
00719           if (mbegin[position] == view[j])
00720           {
00721             found = true;
00722           }
00723         }
00724 
00725         if (!found)
00726         {
00727           return position;
00728         }
00729 
00730         ++it;
00731         --position;
00732       }
00733 
00734       return npos;
00735     }
00736 
00737     size_type find_last_not_of(T c, size_type position = npos) const
00738     {
00739       return find_last_not_of(etl::basic_string_view<T, TTraits>(&c, 1), position);;
00740     }
00741 
00742     size_type find_last_not_of(const T* text, size_type position, size_type count) const
00743     {
00744       return find_last_not_of(etl::basic_string_view<T, TTraits>(text, count), position);;
00745     }
00746 
00747     size_type find_last_not_of(const T* text, size_type position = npos) const
00748     {
00749       return find_last_not_of(etl::basic_string_view<T, TTraits>(text), position);;
00750     }
00751 
00752     //*************************************************************************
00753     /// Equality for array views.
00754     //*************************************************************************
00755     friend bool operator == (const etl::basic_string_view<T, TTraits>& lhs, const etl::basic_string_view<T, TTraits>& rhs)
00756     {
00757       return (lhs.size() == rhs.size()) &&
00758         std::equal(lhs.begin(), lhs.end(), rhs.begin());
00759     }
00760 
00761     //*************************************************************************
00762     /// Inequality for array views.
00763     //*************************************************************************
00764     friend bool operator != (const etl::basic_string_view<T, TTraits>& lhs, const etl::basic_string_view<T, TTraits>& rhs)
00765     {
00766       return !(lhs == rhs);
00767     }
00768 
00769     //*************************************************************************
00770     /// Less-than for array views.
00771     //*************************************************************************
00772     friend bool operator < (const etl::basic_string_view<T, TTraits>& lhs, const etl::basic_string_view<T, TTraits>& rhs)
00773     {
00774       return std::lexicographical_compare(lhs.begin(), lhs.end(), rhs.begin(), rhs.end());
00775     }
00776 
00777     //*************************************************************************
00778     /// Greater-than for array views.
00779     //*************************************************************************
00780     friend bool operator > (const etl::basic_string_view<T, TTraits>& lhs, const etl::basic_string_view<T, TTraits>& rhs)
00781     {
00782       return rhs < lhs;
00783     }
00784 
00785     //*************************************************************************
00786     /// Less-than-equal for array views.
00787     //*************************************************************************
00788     friend bool operator <= (const etl::basic_string_view<T, TTraits>& lhs, const etl::basic_string_view<T, TTraits>& rhs)
00789     {
00790       return !(lhs > rhs);
00791     }
00792 
00793     //*************************************************************************
00794     /// Greater-than-equal for array views.
00795     //*************************************************************************
00796     friend bool operator >= (const etl::basic_string_view<T, TTraits>& lhs, const etl::basic_string_view<T, TTraits>& rhs)
00797     {
00798       return !(lhs < rhs);
00799     }
00800 
00801   private:
00802 
00803     const T* mbegin;
00804     const T* mend;
00805   };
00806 
00807   typedef etl::basic_string_view<char>     string_view;
00808   typedef etl::basic_string_view<wchar_t>  wstring_view;
00809   typedef etl::basic_string_view<char16_t> u16string_view;
00810   typedef etl::basic_string_view<char32_t> u32string_view;
00811 
00812   //*************************************************************************
00813   /// Hash function.
00814   //*************************************************************************
00815 #if ETL_8BIT_SUPPORT
00816   template <>
00817   struct hash<etl::string_view>
00818   {
00819     size_t operator()(const etl::string_view& text) const
00820     {
00821       return etl::__private_hash__::generic_hash<size_t>(reinterpret_cast<const uint8_t*>(&text[0]),
00822                                                          reinterpret_cast<const uint8_t*>(&text[text.size()]));
00823     }
00824   };
00825 
00826   template <>
00827   struct hash<etl::wstring_view>
00828   {
00829     size_t operator()(const etl::wstring_view& text) const
00830     {
00831       return etl::__private_hash__::generic_hash<size_t>(reinterpret_cast<const uint8_t*>(&text[0]),
00832                                                          reinterpret_cast<const uint8_t*>(&text[text.size()]));
00833     }
00834   };
00835 
00836   template <>
00837   struct hash<etl::u16string_view>
00838   {
00839     size_t operator()(const etl::u16string_view& text) const
00840     {
00841       return etl::__private_hash__::generic_hash<size_t>(reinterpret_cast<const uint8_t*>(&text[0]),
00842                                                          reinterpret_cast<const uint8_t*>(&text[text.size()]));
00843     }
00844   };
00845 
00846   template <>
00847   struct hash<etl::u32string_view>
00848   {
00849     size_t operator()(const etl::u32string_view& text) const
00850     {
00851       return etl::__private_hash__::generic_hash<size_t>(reinterpret_cast<const uint8_t*>(&text[0]),
00852                                                          reinterpret_cast<const uint8_t*>(&text[text.size()]));
00853     }
00854   };
00855 #endif
00856 }
00857 
00858 //*************************************************************************
00859 /// Swaps the values.
00860 //*************************************************************************
00861 template <typename T, typename TTraits = etl::char_traits<T>>
00862 void swap(etl::basic_string_view<T, TTraits>& lhs, etl::basic_string_view<T, TTraits>& rhs)
00863 {
00864   lhs.swap(rhs);
00865 }
00866 
00867 #ifdef ETL_COMPILER_MICROSOFT
00868 #define min(a,b) (((a) < (b)) ? (a) : (b))
00869 #define max(a,b) (((a) > (b)) ? (a) : (b))
00870 #endif
00871 
00872 #undef ETL_FILE
00873 
00874 #endif
00875 
00876