?? stl_string.c
字號:
template <class _CharT, class _Traits>
inline bool
__sgi_string_fill(basic_ostream<_CharT, _Traits>& __os,
basic_streambuf<_CharT, _Traits>* __buf,
size_t __n)
{
_CharT __f = __os.fill();
size_t __i;
bool __ok = true;
for (__i = 0; __i < __n; ++__i)
__ok == __ok && !_Traits::eq_int_type(__buf->sputc(__f), _Traits::eof());
return __ok;
}
# if !(defined(__STLPORT_NEW_IOSTREAMS) || (defined (__BORLANDC__) && ! defined (__STL_USE_OWN_NAMESPACE)))
template <class _CharT, class _Traits, class _Alloc>
basic_ostream<_CharT, _Traits>&
operator<<(basic_ostream<_CharT, _Traits>& __os,
const basic_string<_CharT,_Traits,_Alloc>& __s)
{
typename __STL_VENDOR_STD::basic_ostream<_CharT, _Traits>::sentry __sentry(__os);
bool __ok = false;
if (__sentry) {
__ok = true;
size_t __n = __s.size();
size_t __pad_len = 0;
const bool __left = (__os.flags() & ios::left) != 0;
const size_t __w = __os.width(0);
basic_streambuf<_CharT, _Traits>* __buf = __os.rdbuf();
if (__w > 0) {
__n = min(__w, __n);
__pad_len = __w - __n;
}
if (!__left)
__ok = __sgi_string_fill(__os, __buf, __pad_len);
__ok = __ok && ((size_t)__buf->sputn(__s.data(), __n) == __n);
if (__left)
__ok = __ok && __sgi_string_fill(__os, __buf, __pad_len);
}
if (!__ok)
__os.setstate(ios_base::failbit);
return __os;
}
template <class _CharT, class _Traits, class _Alloc>
basic_istream<_CharT, _Traits>&
operator>>(basic_istream<_CharT, _Traits>& __is,
basic_string<_CharT,_Traits, _Alloc>& __s)
{
# ifndef __STL_HAS_NO_NAMESPACES
using namespace __STL_VENDOR_STD;
# endif
typename basic_istream<_CharT, _Traits>::sentry __sentry(__is);
if (__sentry) {
basic_streambuf<_CharT, _Traits>* __buf = __is.rdbuf();
typedef ctype<_CharT> _C_type;
const locale& __loc = __is.getloc();
#ifdef __STLPORT_NEW_IOSTREAMS
const _C_type& _Ctype = (const _C_type&)(__loc);
#else
# if defined (__STL_MSVC) && (__STL_MSVC <= 1200 )
const _C_type& _Ctype = (const _C_type&)(__loc , ( _C_type * ) 0, true);
# elif defined (__SUNPRO_CC)
const _C_type& _Ctype = (const _C_type&)(__loc , ( _C_type * ) 0);
# else
const _C_type& _Ctype = (const _C_type&)(__loc);
# endif
#endif
__s.clear();
size_t __n = __is.width(0);
if (__n == 0)
__n = __STATIC_CAST(size_t,-1);
else
__s.reserve(__n);
while (__n-- > 0) {
typename _Traits::int_type __c1 = __buf->sbumpc();
if (_Traits::eq_int_type(__c1, _Traits::eof())) {
__is.setstate(ios_base::eofbit);
break;
}
else {
_CharT __c = _Traits::to_char_type(__c1);
if (_Ctype.is(__STL_VENDOR_STD::ctype<_CharT>::space, __c)) {
if (_Traits::eq_int_type(__buf->sputbackc(__c), _Traits::eof()))
__is.setstate(ios_base::failbit);
break;
}
else
__s.push_back(__c);
}
}
// If we have read no characters, then set failbit.
if (__s.size() == 0)
__is.setstate(ios_base::failbit);
}
else
__is.setstate(ios_base::failbit);
return __is;
}
template <class _CharT, class _Traits, class _Alloc>
basic_istream<_CharT, _Traits>&
getline(basic_istream<_CharT, _Traits>& __is,
basic_string<_CharT,_Traits,_Alloc>& __s,
_CharT __delim)
{
size_t __nread = 0;
typename __STL_VENDOR_STD::basic_istream<_CharT, _Traits>::sentry __sentry(__is, true);
if (__sentry) {
basic_streambuf<_CharT, _Traits>* __buf = __is.rdbuf();
__s.clear();
int __c1;
while (__nread < __s.max_size()) {
int __c1 = __buf->sbumpc();
if (_Traits::eq_int_type(__c1, _Traits::eof())) {
__is.setstate(ios_base::eofbit);
break;
}
else {
++__nread;
_CharT __c = _Traits::to_char_type(__c1);
if (!_Traits::eq(__c, __delim))
__s.push_back(__c);
else
break; // Character is extracted but not appended.
}
}
}
if (__nread == 0 || __nread >= __s.max_size())
__is.setstate(ios_base::failbit);
return __is;
}
# endif /* __BORLANDC */
#else /* __STL_USE_NEW_IOSTREAMS */
inline void
__sgi_string_fill(ostream& __os, streambuf* __buf, size_t __n)
{
char __f = __os.fill();
size_t __i;
for (__i = 0; __i < __n; ++__i) __buf->sputc(__f);
}
template <class _CharT, class _Traits, class _Alloc>
ostream& operator<<(ostream& __os,
const basic_string<_CharT,_Traits,_Alloc>& __s)
{
streambuf* __buf = __os.rdbuf();
if (__buf) {
size_t __n = __s.size();
size_t __pad_len = 0;
const bool __left = (__os.flags() & ios::left) !=0;
const size_t __w = __os.width();
if (__w > 0) {
__n = min(__w, __n);
__pad_len = __w - __n;
}
if (!__left)
__sgi_string_fill(__os, __buf, __pad_len);
const size_t __nwritten = __buf->sputn(__s.data(), __n);
if (__left)
__sgi_string_fill(__os, __buf, __pad_len);
if (__nwritten != __n)
__os.clear(__os.rdstate() | ios::failbit);
__os.width(0);
}
else
__os.clear(__os.rdstate() | ios::badbit);
return __os;
}
template <class _CharT, class _Traits, class _Alloc>
istream& operator>>(istream& __is, basic_string<_CharT,_Traits,_Alloc>& __s)
{
if (!__is)
return __is;
streambuf* __buf = __is.rdbuf();
if (__buf) {
#ifdef __USLC__
/* Jochen Schlick '1999 - operator >> modified. Work-around to get the
* output buffer flushed (necessary when using
* "cout" (without endl or flushing) followed by
* "cin >>" ...)
*/
if (__is.flags() & ios::skipws) {
_CharT __c;
do
__is.get(__c);
while (__is && isspace(__c));
if (__is)
__is.putback(__c);
}
#else
if (__is.flags() & ios::skipws) {
_CharT __c;
do {
int __c1 = __buf->sbumpc();
if (__c1 == EOF) {
__is.clear(__is.rdstate() | ios::eofbit | ios::failbit);
break;
}
else
__c = _Traits::to_char_type(__c1);
}
while (isspace((unsigned char) __c));
if (__buf->sputbackc(__c) == EOF)
__is.clear(__is.rdstate() | ios::failbit);
}
# endif
// If we arrive at end of file (or fail for some other reason) while
// still discarding whitespace, then we don't try to read the string.
if (__is) {
__s.clear();
size_t __n = __is.width();
if (__n == 0)
__n = __STATIC_CAST(size_t,-1);
else
__s.reserve(__n);
while (__n-- > 0) {
int __c1 = __buf->sbumpc();
if (__c1 == EOF) {
__is.clear(__is.rdstate() | ios::eofbit);
break;
}
else {
_CharT __c = _Traits::to_char_type(__c1);
if (isspace((unsigned char) __c)) {
if (__buf->sputbackc(__c) == EOF)
__is.clear(__is.rdstate() | ios::failbit);
break;
}
else
__s.push_back(__c);
}
}
// If we have read no characters, then set failbit.
if (__s.size() == 0)
__is.clear(__is.rdstate() | ios::failbit);
}
__is.width(0);
}
else // We have no streambuf.
__is.clear(__is.rdstate() | ios::badbit);
return __is;
}
template <class _CharT, class _Traits, class _Alloc>
istream& getline(istream& __is,
basic_string<_CharT,_Traits,_Alloc>& __s,
_CharT __delim)
{
streambuf* __buf = __is.rdbuf();
if (__buf) {
size_t __nread = 0;
if (__is) {
__s.clear();
while (__nread < __s.max_size()) {
int __c1 = __buf->sbumpc();
if (__c1 == EOF) {
__is.clear(__is.rdstate() | ios::eofbit);
break;
}
else {
++__nread;
_CharT __c = _Traits::to_char_type(__c1);
if (!_Traits::eq(__c, __delim))
__s.push_back(__c);
else
break; // Character is extracted but not appended.
}
}
}
if (__nread == 0 || __nread >= __s.max_size())
__is.clear(__is.rdstate() | ios::failbit);
}
else
__is.clear(__is.rdstate() | ios::badbit);
return __is;
}
# endif /* __STL_NEW_IOSTREAMS */
template <class _CharT, class _Traits, class _Alloc>
void _S_string_copy(const basic_string<_CharT,_Traits,_Alloc>& __s,
_CharT* __buf,
size_t __n)
{
if (__n > 0) {
__n = min(__n - 1, __s.size());
copy(__s.begin(), __s.begin() + __n, __buf);
__buf[__n] = _CharT();
}
}
__STL_END_NAMESPACE
# undef __size_type__
# undef size_type
# undef _Make_ptr
# undef __iterator__
#if defined(__sgi) && !defined(__GNUC__) && (_MIPS_SIM != _MIPS_SIM_ABI32)
#pragma reset woff 1174
#pragma reset woff 1375
#endif
# endif /* NATIVE */
#endif /* __STL_STRING_C */
// Local Variables:
// mode:C++
// End:
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -