9 #ifndef STK_UTIL_DIAG_String_h 10 #define STK_UTIL_DIAG_String_h 14 #include <stk_util/util/cistring.hpp> 19 typedef cistring Identifier;
20 typedef cistring ParamId;
94 struct char_simple_traits ;
96 struct char_label_traits ;
101 template<
typename T>
struct Precedence<T, T> {
typedef T Type ; };
109 struct Precedence<char_label_traits, char_simple_traits> {
110 typedef char_label_traits Type ;
132 template<
class CT1,
class CT2>
135 template<
class CT1,
class CT2>
138 template<
class CT1,
class CT2>
141 template<
class CT1,
class CT2>
144 template<
class CT1,
class CT2>
147 template<
class CT1,
class CT2>
158 bool operator< ( const StringBase<CT1> &,
const std::string & );
164 bool operator<= ( const StringBase<CT1> &,
const std::string & );
177 bool operator< ( const StringBase<CT1> &,
const char * );
183 bool operator<= ( const StringBase<CT1> &,
const char * );
196 bool operator< (const char *, const StringBase<CT1> & );
202 bool operator<= (const char *, const StringBase<CT1> & );
215 bool operator< (const std::string &, const StringBase<CT1> &);
221 bool operator<= (const std::string &, const StringBase<CT1> &);
246 namespace implementation {
251 enum { buf_len = 32 };
252 enum { off_len = buf_len - 1 };
253 enum { max_len = buf_len - 2 };
261 char small[ buf_len ];
267 const char * c_str()
const ;
271 char *
mem(
const char *,
size_t n );
281 typedef const char * const_iterator;
282 typedef char * iterator;
285 typedef CT traits_type ;
286 typedef char value_type ;
287 typedef size_t size_type ;
320 size_type size()
const;
321 size_type length()
const;
324 const_iterator begin()
const;
326 const_iterator end()
const;
339 StringBase<CT> & append(
const char *,
const typename StringBase<CT>::size_type );
348 const char* c_str()
const;
349 std::string s_str()
const ;
351 int compare(
const char * )
const ;
352 int compare(
const std::string & )
const ;
367 static size_t length(
const char * c1 );
374 static int compare(
const char * c1,
const char * c2 );
384 static size_t length(
const char * c1 );
387 static void convert(
char * c,
size_t n );
390 static int compare(
const char * c1,
const char * c2 );
397 {
return data.len() == 0 ; }
400 typename StringBase<CT>::size_type StringBase<CT>::length()
const 401 {
return data.len(); }
404 typename StringBase<CT>::size_type StringBase<CT>::size()
const 405 {
return data.len(); }
408 typename StringBase<CT>::iterator
409 StringBase<CT>::begin()
410 {
return data.c_str(); }
413 typename StringBase<CT>::const_iterator
414 StringBase<CT>::begin()
const 415 {
return data.c_str(); }
418 typename StringBase<CT>::iterator
419 StringBase<CT>::end()
420 {
return data.c_str() + data.len(); }
423 typename StringBase<CT>::const_iterator
424 StringBase<CT>::end()
const 425 {
return data.c_str() + data.len(); }
429 const char* StringBase<CT>::c_str()
const 430 {
return data.c_str(); }
433 std::string StringBase<CT>::s_str()
const 434 {
return std::string(c_str()) ; }
437 StringBase<CT>::~StringBase()
443 StringBase<CT>::StringBase() {}
447 StringBase<CT>::StringBase(
const StringBase<CT2> & cs )
449 const size_type n = cs.length();
450 traits_type::convert( data.mem(cs.c_str(), n), n );
454 StringBase<CT>::StringBase(
const std::string& cs )
456 const size_type n = cs.length();
457 traits_type::convert( data.mem(cs.c_str(), n), n );
461 StringBase<CT>::StringBase(
const char * cs,
typename StringBase<CT>::size_type n )
463 traits_type::convert( data.mem(cs, n), n );
468 StringBase<CT>::StringBase( It l_begin, It l_end )
470 traits_type::convert( data.mem(&(*l_begin), l_end - l_begin), l_end - l_begin );
474 StringBase<CT>::StringBase(
const char * cs )
476 const size_type n = traits_type::length(cs);
477 traits_type::convert( data.mem(cs, n), n );
481 StringBase<CT>::StringBase(
const StringBase & cs )
483 data.mem(cs.c_str(), cs.size());
490 StringBase<CT>::assign(
const char * cs,
const typename StringBase<CT>::size_type n )
492 traits_type::convert( data.mem(cs, n), n );
497 StringBase<CT> & StringBase<CT>::assign(
const char * cs )
498 {
return assign( cs, traits_type::length(cs) ); }
501 StringBase<CT> & StringBase<CT>::assign(
const std::string & cs )
502 {
return assign( cs.c_str(), cs.length() ); }
506 StringBase<CT> & StringBase<CT>::assign(
const StringBase<CT2> & cs )
507 {
return assign( cs.c_str(), cs.length() ); }
511 StringBase<CT>::operator= (
const StringBase & cs ) {
514 return assign( cs.c_str(), cs.length() );
520 StringBase<CT>::operator= (
const StringBase<CT2> & cs ) {
521 return assign( cs.c_str(), cs.length() );
526 StringBase<CT>::operator= (
const char * cs )
527 {
return assign( cs, traits_type::length(cs) ); }
531 StringBase<CT>::operator= (
const std::string& cs )
532 {
return assign( cs.c_str(), cs.length() ); }
538 StringBase<CT>::append(
const char * cs,
const typename StringBase<CT>::size_type n )
542 t.reserve(data.len() + n);
543 t.append(data.c_str())
545 traits_type::convert( data.mem(t.data(), t.length()), t.length());
551 StringBase<char_label_traits> &
552 StringBase<char_label_traits>::append(
const char * cs,
const StringBase<char_label_traits>::size_type n )
557 t.reserve(data.len() + n + 1);
558 t.append(data.c_str())
559 .append(data.len() == 0 ?
"" :
"_")
561 traits_type::convert( data.mem(t.data(), t.length()), t.length());
567 StringBase<CT> & StringBase<CT>::append(
const char * cs )
568 {
return append( cs, traits_type::length(cs) ); }
571 StringBase<CT> & StringBase<CT>::append(
const std::string & cs )
572 {
return append( cs.data(), cs.length() ); }
576 StringBase<CT> & StringBase<CT>::append(
const StringBase<CT2> & cs )
577 {
return append( cs.c_str(), cs.length() ); }
583 StringBase<CT>::operator+= (
const StringBase<CT2> & cs )
584 {
return append( cs.c_str(), cs.length() ); }
588 StringBase<CT>::operator+= (
const char * cs )
589 {
return append( cs, traits_type::length(cs) ); }
593 StringBase<CT>::operator+= (
const std::string& cs )
594 {
return append( cs.data(), cs.length() ); }
600 int StringBase<CT>::compare(
const StringBase<CT2> & cs )
const 602 typedef typename Precedence<CT, CT2>::Type Traits ;
603 return Traits::compare( c_str(), cs.c_str() );
607 int StringBase<CT>::compare(
const std::string & cs )
const 609 return CT::compare( c_str(), cs.c_str() );
613 int StringBase<CT>::compare(
const char * cs )
const 615 return CT::compare( c_str(), cs );
618 template<
class CT,
class CT2>
619 bool operator== (
const StringBase<CT> & lhs,
620 const StringBase<CT2> & rhs )
621 {
return lhs.compare(rhs) == 0 ; }
623 template<
class CT,
class CT2>
624 bool operator!= (
const StringBase<CT> & lhs,
625 const StringBase<CT2> & rhs )
626 {
return lhs.compare(rhs) != 0 ; }
628 template<
class CT,
class CT2>
629 bool operator< ( const StringBase<CT> & lhs,
630 const StringBase<CT2> & rhs )
631 {
return lhs.compare(rhs) < 0 ; }
633 template<
class CT,
class CT2>
634 bool operator<= ( const StringBase<CT> & lhs,
635 const StringBase<CT2> & rhs )
636 {
return lhs.compare(rhs) <= 0 ; }
638 template<
class CT,
class CT2>
639 bool operator> (
const StringBase<CT> & lhs,
640 const StringBase<CT2> & rhs )
641 {
return lhs.compare(rhs) > 0 ; }
643 template<
class CT,
class CT2>
644 bool operator>= (
const StringBase<CT> & lhs,
645 const StringBase<CT2> & rhs )
646 {
return lhs.compare(rhs) >= 0 ; }
650 bool operator== (
const StringBase<CT> & lhs,
651 const std::string & rhs )
652 {
return lhs.compare(rhs) == 0 ; }
655 bool operator!= (
const StringBase<CT> & lhs,
656 const std::string & rhs )
657 {
return lhs.compare(rhs) != 0 ; }
660 bool operator< ( const StringBase<CT> & lhs,
661 const std::string & rhs )
662 {
return lhs.compare(rhs) < 0 ; }
665 bool operator<= ( const StringBase<CT> & lhs,
666 const std::string & rhs )
667 {
return lhs.compare(rhs) <= 0 ; }
670 bool operator> (
const StringBase<CT> & lhs,
671 const std::string & rhs )
672 {
return lhs.compare(rhs) > 0 ; }
675 bool operator>= (
const StringBase<CT> & lhs,
676 const std::string & rhs )
677 {
return lhs.compare(rhs) >= 0 ; }
681 bool operator== (
const StringBase<CT> & lhs,
683 {
return lhs.compare(rhs) == 0 ; }
686 bool operator!= (
const StringBase<CT> & lhs,
688 {
return lhs.compare(rhs) != 0 ; }
691 bool operator< ( const StringBase<CT> & lhs,
693 {
return lhs.compare(rhs) < 0 ; }
696 bool operator<= ( const StringBase<CT> & lhs,
698 {
return lhs.compare(rhs) <= 0 ; }
701 bool operator> (
const StringBase<CT> & lhs,
703 {
return lhs.compare(rhs) > 0 ; }
706 bool operator>= (
const StringBase<CT> & lhs,
708 {
return lhs.compare(rhs) >= 0 ; }
712 bool operator== (
const std::string & lhs,
713 const StringBase<CT> & rhs)
714 {
return rhs.compare(lhs) == 0 ; }
717 bool operator!= (
const std::string & lhs,
718 const StringBase<CT> & rhs)
719 {
return rhs.compare(lhs) != 0 ; }
722 bool operator< (
const std::string & lhs,
723 const StringBase<CT> & rhs)
724 {
return rhs.compare(lhs) > 0 ; }
727 bool operator<= (
const std::string & lhs,
728 const StringBase<CT> & rhs)
729 {
return rhs.compare(lhs) >= 0 ; }
732 bool operator> (
const std::string & lhs,
733 const StringBase<CT> & rhs)
734 {
return rhs.compare(lhs) < 0 ; }
737 bool operator>= (
const std::string & lhs,
738 const StringBase<CT> & rhs)
739 {
return rhs.compare(lhs) <= 0 ; }
743 bool operator== (
const char * lhs,
744 const StringBase<CT> & rhs)
745 {
return rhs.compare(lhs) == 0 ; }
748 bool operator!= (
const char * lhs,
749 const StringBase<CT> & rhs)
750 {
return rhs.compare(lhs) != 0 ; }
753 bool operator< (
const char * lhs,
754 const StringBase<CT> & rhs)
755 {
return rhs.compare(lhs) > 0 ; }
758 bool operator<= (
const char * lhs,
759 const StringBase<CT> & rhs)
760 {
return rhs.compare(lhs) >= 0 ; }
763 bool operator> (
const char * lhs,
764 const StringBase<CT> & rhs)
765 {
return rhs.compare(lhs) < 0 ; }
768 bool operator>= (
const char * lhs,
769 const StringBase<CT> & rhs)
770 {
return rhs.compare(lhs) <= 0 ; }
774 template<
class CT,
class CT2>
776 operator+(
const StringBase<CT> &cs1,
const StringBase<CT2> &cs2) {
777 StringBase<CT> t(cs1);
778 t.append(cs2.c_str(), cs2.size());
784 operator+(
const StringBase<CT> &cs1,
const char *cs2) {
785 StringBase<CT> t(cs1);
792 operator+(
const StringBase<CT> &cs1,
const std::string &cs2) {
793 StringBase<CT> t(cs1);
794 t.append(cs2.c_str(), cs2.length());
800 operator+ (
const char *cs1,
const StringBase<CT> &cs2 ) {
801 StringBase<CT> t(cs1);
802 t.append(cs2.c_str(), cs2.length());
807 std::string operator+(
const std::string & lhs,
const StringBase<CT> & rhs ) {
808 std::string s( lhs );
return s.append( rhs.c_str(), rhs.length() );
817 #endif // USE_CISTRING 819 #endif // STK_UTIL_DIAG_String_h static size_t length(const char *c1)
static int compare(const char *c1, const char *c2)
static int compare(const char *c1, const char *c2)
char * mem(const char *, size_t n)
static size_t length(const char *c1)
static void convert(char *, size_t)
static void convert(char *c, size_t n)