From 73b46a72486780f049ada9d9fbde6d3ba8e49940 Mon Sep 17 00:00:00 2001 From: Marshall Clow Date: Tue, 10 Dec 2013 19:25:49 +0000 Subject: [PATCH] Refactored a bunch of duplicated code in . Made a new routine called __put_character_sequence, and made nine places call it. git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@196951 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/ostream | 242 +++++------------------------------------------- 1 file changed, 24 insertions(+), 218 deletions(-) diff --git a/include/ostream b/include/ostream index 041314ac..20587a1d 100644 --- a/include/ostream +++ b/include/ostream @@ -729,7 +729,8 @@ basic_ostream<_CharT, _Traits>::operator<<(const void* __n) template basic_ostream<_CharT, _Traits>& -operator<<(basic_ostream<_CharT, _Traits>& __os, _CharT __c) +__put_character_sequence(basic_ostream<_CharT, _Traits>& __os, + const _CharT* __str, size_t __len) { #ifndef _LIBCPP_NO_EXCEPTIONS try @@ -740,11 +741,11 @@ operator<<(basic_ostream<_CharT, _Traits>& __os, _CharT __c) { typedef ostreambuf_iterator<_CharT, _Traits> _Ip; if (__pad_and_output(_Ip(__os), - &__c, + __str, (__os.flags() & ios_base::adjustfield) == ios_base::left ? - &__c + 1 : - &__c, - &__c + 1, + __str + __len : + __str, + __str + __len, __os, __os.fill()).failed()) __os.setstate(ios_base::badbit | ios_base::failbit); @@ -759,6 +760,14 @@ operator<<(basic_ostream<_CharT, _Traits>& __os, _CharT __c) return __os; } + +template +basic_ostream<_CharT, _Traits>& +operator<<(basic_ostream<_CharT, _Traits>& __os, _CharT __c) +{ + return _VSTD::__put_character_sequence(__os, &__c, 1); +} + template basic_ostream<_CharT, _Traits>& operator<<(basic_ostream<_CharT, _Traits>& __os, char __cn) @@ -796,129 +805,28 @@ template basic_ostream& operator<<(basic_ostream& __os, char __c) { -#ifndef _LIBCPP_NO_EXCEPTIONS - try - { -#endif // _LIBCPP_NO_EXCEPTIONS - typename basic_ostream::sentry __s(__os); - if (__s) - { - typedef ostreambuf_iterator _Ip; - if (__pad_and_output(_Ip(__os), - &__c, - (__os.flags() & ios_base::adjustfield) == ios_base::left ? - &__c + 1 : - &__c, - &__c + 1, - __os, - __os.fill()).failed()) - __os.setstate(ios_base::badbit | ios_base::failbit); - } -#ifndef _LIBCPP_NO_EXCEPTIONS - } - catch (...) - { - __os.__set_badbit_and_consider_rethrow(); - } -#endif // _LIBCPP_NO_EXCEPTIONS - return __os; + return _VSTD::__put_character_sequence(__os, &__c, 1); } template basic_ostream& operator<<(basic_ostream& __os, signed char __c) { -#ifndef _LIBCPP_NO_EXCEPTIONS - try - { -#endif // _LIBCPP_NO_EXCEPTIONS - typename basic_ostream::sentry __s(__os); - if (__s) - { - typedef ostreambuf_iterator _Ip; - if (__pad_and_output(_Ip(__os), - (char*)&__c, - (__os.flags() & ios_base::adjustfield) == ios_base::left ? - (char*)&__c + 1 : - (char*)&__c, - (char*)&__c + 1, - __os, - __os.fill()).failed()) - __os.setstate(ios_base::badbit | ios_base::failbit); - } -#ifndef _LIBCPP_NO_EXCEPTIONS - } - catch (...) - { - __os.__set_badbit_and_consider_rethrow(); - } -#endif // _LIBCPP_NO_EXCEPTIONS - return __os; + return _VSTD::__put_character_sequence(__os, (char *) &__c, 1); } template basic_ostream& operator<<(basic_ostream& __os, unsigned char __c) { -#ifndef _LIBCPP_NO_EXCEPTIONS - try - { -#endif // _LIBCPP_NO_EXCEPTIONS - typename basic_ostream::sentry __s(__os); - if (__s) - { - typedef ostreambuf_iterator _Ip; - if (__pad_and_output(_Ip(__os), - (char*)&__c, - (__os.flags() & ios_base::adjustfield) == ios_base::left ? - (char*)&__c + 1 : - (char*)&__c, - (char*)&__c + 1, - __os, - __os.fill()).failed()) - __os.setstate(ios_base::badbit | ios_base::failbit); - } -#ifndef _LIBCPP_NO_EXCEPTIONS - } - catch (...) - { - __os.__set_badbit_and_consider_rethrow(); - } -#endif // _LIBCPP_NO_EXCEPTIONS - return __os; + return _VSTD::__put_character_sequence(__os, (char *) &__c, 1); } template basic_ostream<_CharT, _Traits>& operator<<(basic_ostream<_CharT, _Traits>& __os, const _CharT* __str) { -#ifndef _LIBCPP_NO_EXCEPTIONS - try - { -#endif // _LIBCPP_NO_EXCEPTIONS - typename basic_ostream<_CharT, _Traits>::sentry __s(__os); - if (__s) - { - typedef ostreambuf_iterator<_CharT, _Traits> _Ip; - size_t __len = _Traits::length(__str); - if (__pad_and_output(_Ip(__os), - __str, - (__os.flags() & ios_base::adjustfield) == ios_base::left ? - __str + __len : - __str, - __str + __len, - __os, - __os.fill()).failed()) - __os.setstate(ios_base::badbit | ios_base::failbit); - } -#ifndef _LIBCPP_NO_EXCEPTIONS - } - catch (...) - { - __os.__set_badbit_and_consider_rethrow(); - } -#endif // _LIBCPP_NO_EXCEPTIONS - return __os; + return _VSTD::__put_character_sequence(__os, __str, _Traits::length(__str)); } template @@ -971,99 +879,23 @@ template basic_ostream& operator<<(basic_ostream& __os, const char* __str) { -#ifndef _LIBCPP_NO_EXCEPTIONS - try - { -#endif // _LIBCPP_NO_EXCEPTIONS - typename basic_ostream::sentry __s(__os); - if (__s) - { - typedef ostreambuf_iterator _Ip; - size_t __len = _Traits::length(__str); - if (__pad_and_output(_Ip(__os), - __str, - (__os.flags() & ios_base::adjustfield) == ios_base::left ? - __str + __len : - __str, - __str + __len, - __os, - __os.fill()).failed()) - __os.setstate(ios_base::badbit | ios_base::failbit); - } -#ifndef _LIBCPP_NO_EXCEPTIONS - } - catch (...) - { - __os.__set_badbit_and_consider_rethrow(); - } -#endif // _LIBCPP_NO_EXCEPTIONS - return __os; + return _VSTD::__put_character_sequence(__os, __str, _Traits::length(__str)); } template basic_ostream& operator<<(basic_ostream& __os, const signed char* __str) { -#ifndef _LIBCPP_NO_EXCEPTIONS - try - { -#endif // _LIBCPP_NO_EXCEPTIONS - typename basic_ostream::sentry __s(__os); - if (__s) - { - typedef ostreambuf_iterator _Ip; - size_t __len = _Traits::length((const char*)__str); - if (__pad_and_output(_Ip(__os), - (const char*)__str, - (__os.flags() & ios_base::adjustfield) == ios_base::left ? - (const char*)__str + __len : - (const char*)__str, - (const char*)__str + __len, - __os, - __os.fill()).failed()) - __os.setstate(ios_base::badbit | ios_base::failbit); - } -#ifndef _LIBCPP_NO_EXCEPTIONS - } - catch (...) - { - __os.__set_badbit_and_consider_rethrow(); - } -#endif // _LIBCPP_NO_EXCEPTIONS - return __os; + const char *__s = (const char *) __str; + return _VSTD::__put_character_sequence(__os, __s, _Traits::length(__s)); } template basic_ostream& operator<<(basic_ostream& __os, const unsigned char* __str) { -#ifndef _LIBCPP_NO_EXCEPTIONS - try - { -#endif // _LIBCPP_NO_EXCEPTIONS - typename basic_ostream::sentry __s(__os); - if (__s) - { - typedef ostreambuf_iterator _Ip; - size_t __len = _Traits::length((const char*)__str); - if (__pad_and_output(_Ip(__os), - (const char*)__str, - (__os.flags() & ios_base::adjustfield) == ios_base::left ? - (const char*)__str + __len : - (const char*)__str, - (const char*)__str + __len, - __os, - __os.fill()).failed()) - __os.setstate(ios_base::badbit | ios_base::failbit); - } -#ifndef _LIBCPP_NO_EXCEPTIONS - } - catch (...) - { - __os.__set_badbit_and_consider_rethrow(); - } -#endif // _LIBCPP_NO_EXCEPTIONS - return __os; + const char *__s = (const char *) __str; + return _VSTD::__put_character_sequence(__os, __s, _Traits::length(__s)); } template @@ -1233,33 +1065,7 @@ basic_ostream<_CharT, _Traits>& operator<<(basic_ostream<_CharT, _Traits>& __os, const basic_string<_CharT, _Traits, _Allocator>& __str) { -#ifndef _LIBCPP_NO_EXCEPTIONS - try - { -#endif // _LIBCPP_NO_EXCEPTIONS - typename basic_ostream<_CharT, _Traits>::sentry __s(__os); - if (__s) - { - typedef ostreambuf_iterator<_CharT, _Traits> _Ip; - size_t __len = __str.size(); - if (__pad_and_output(_Ip(__os), - __str.data(), - (__os.flags() & ios_base::adjustfield) == ios_base::left ? - __str.data() + __len : - __str.data(), - __str.data() + __len, - __os, - __os.fill()).failed()) - __os.setstate(ios_base::badbit | ios_base::failbit); - } -#ifndef _LIBCPP_NO_EXCEPTIONS - } - catch (...) - { - __os.__set_badbit_and_consider_rethrow(); - } -#endif // _LIBCPP_NO_EXCEPTIONS - return __os; + return _VSTD::__put_character_sequence(__os, __str.data(), __str.size()); } template