| 3679 | }; |
| 3680 | |
| 3681 | class Text { |
| 3682 | public: |
| 3683 | Text( std::string const& _str, TextAttributes const& _attr = TextAttributes() ) |
| 3684 | : attr( _attr ) |
| 3685 | { |
| 3686 | std::string wrappableChars = " [({.,/|\\-"; |
| 3687 | std::size_t indent = _attr.initialIndent != std::string::npos |
| 3688 | ? _attr.initialIndent |
| 3689 | : _attr.indent; |
| 3690 | std::string remainder = _str; |
| 3691 | |
| 3692 | while( !remainder.empty() ) { |
| 3693 | if( lines.size() >= 1000 ) { |
| 3694 | lines.push_back( "... message truncated due to excessive size" ); |
| 3695 | return; |
| 3696 | } |
| 3697 | std::size_t tabPos = std::string::npos; |
| 3698 | std::size_t width = (std::min)( remainder.size(), _attr.width - indent ); |
| 3699 | std::size_t pos = remainder.find_first_of( '\n' ); |
| 3700 | if( pos <= width ) { |
| 3701 | width = pos; |
| 3702 | } |
| 3703 | pos = remainder.find_last_of( _attr.tabChar, width ); |
| 3704 | if( pos != std::string::npos ) { |
| 3705 | tabPos = pos; |
| 3706 | if( remainder[width] == '\n' ) |
| 3707 | width--; |
| 3708 | remainder = remainder.substr( 0, tabPos ) + remainder.substr( tabPos+1 ); |
| 3709 | } |
| 3710 | |
| 3711 | if( width == remainder.size() ) { |
| 3712 | spliceLine( indent, remainder, width ); |
| 3713 | } |
| 3714 | else if( remainder[width] == '\n' ) { |
| 3715 | spliceLine( indent, remainder, width ); |
| 3716 | if( width <= 1 || remainder.size() != 1 ) |
| 3717 | remainder = remainder.substr( 1 ); |
| 3718 | indent = _attr.indent; |
| 3719 | } |
| 3720 | else { |
| 3721 | pos = remainder.find_last_of( wrappableChars, width ); |
| 3722 | if( pos != std::string::npos && pos > 0 ) { |
| 3723 | spliceLine( indent, remainder, pos ); |
| 3724 | if( remainder[0] == ' ' ) |
| 3725 | remainder = remainder.substr( 1 ); |
| 3726 | } |
| 3727 | else { |
| 3728 | spliceLine( indent, remainder, width-1 ); |
| 3729 | lines.back() += "-"; |
| 3730 | } |
| 3731 | if( lines.size() == 1 ) |
| 3732 | indent = _attr.indent; |
| 3733 | if( tabPos != std::string::npos ) |
| 3734 | indent += tabPos; |
| 3735 | } |
| 3736 | } |
| 3737 | } |
| 3738 |
no test coverage detected