Changeset 2e0256b in mainline


Ignore:
Timestamp:
2018-07-05T21:41:19Z (6 years ago)
Author:
Dzejrou <dzejrou@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
f5a77a00
Parents:
4ff55d2
git-author:
Dzejrou <dzejrou@…> (2017-12-17 14:56:56)
git-committer:
Dzejrou <dzejrou@…> (2018-07-05 21:41:19)
Message:

cpp: moved string extractors and inserters to their own internal header to avoid circular dependencies, added padding to string extractor, implemented std::getline and fixed formatted string i/o

Location:
uspace/lib/cpp/include
Files:
1 added
2 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/cpp/include/impl/string.hpp

    r4ff55d2 r2e0256b  
    18571857
    18581858    /**
    1859      * 21.4.8.9, inserters and extractors:
    1860      */
    1861 
    1862     template<class Char, class Traits, class Allocator>
    1863     basic_istream<Char, Traits>& operator>>(basic_istream<Char, Traits>& is,
    1864                                             basic_string<Char, Traits, Allocator>& str)
    1865     {
    1866         using sentry = typename basic_istream<Char, Traits>::sentry;
    1867         sentry sen{is, true};
    1868 
    1869         if (sen)
    1870         {
    1871             str.erase();
    1872 
    1873             auto max_size = is.width();
    1874             if (max_size == 0)
    1875                 max_size = static_cast<decltype(max_size)>(str.max_size());
    1876 
    1877             decltype(is.width()) i{};
    1878             for(; i < max_size; ++i)
    1879             {
    1880                 auto ic = is.rdbuf()->sgetc();
    1881                 if (Traits::eq_int_type(ic, Traits::eof()))
    1882                     break;
    1883 
    1884                 auto c = Traits::to_char_type(ic);
    1885                 if(isspace(c, is.getloc()))
    1886                     break;
    1887 
    1888                 str.append(1, c);
    1889                 is.rdbuf()->sbumpc();
    1890             }
    1891         }
    1892 
    1893         return is;
    1894     }
    1895 
    1896     template<class Char, class Traits, class Allocator>
    1897     basic_ostream<Char, Traits>& operator<<(basic_ostream<Char, Traits>& os,
    1898                                             basic_string<Char, Traits, Allocator>& str)
    1899     {
    1900         // TODO: determine padding as described in 27.7.3.6.1
    1901         using sentry = typename basic_ostream<Char, Traits>::sentry;
    1902         sentry sen{os};
    1903 
    1904         if (sen)
    1905         {
    1906             auto size = str.size();
    1907             if (size < static_cast<decltype(size)>(os.width()))
    1908                 size = os.width();
    1909 
    1910             os.rdbuf()->sputn(str.data(), size);
    1911             os.width(0);
    1912         }
    1913 
    1914         return os;
    1915     }
    1916 
    1917     /**
    19181859     * 21.5, numeric conversions:
    19191860     */
  • uspace/lib/cpp/include/string

    r4ff55d2 r2e0256b  
    2828
    2929#include <impl/string.hpp>
     30#include <internal/string.hpp>
Note: See TracChangeset for help on using the changeset viewer.