Skip to content

Commit

Permalink
EditTextView: Fix redundant initialization (#380)
Browse files Browse the repository at this point in the history
無意味な変数初期化を行っているとcppcheckの指摘されたため修正します。

cppcheckのレポート
```
src/skeleton/editview.cpp:571:24: style: Redundant initialization for 'nlpos'. The initialized value is overwritten before it is read. [redundantInitialization]
        while( ( nlpos = text.rfind( "\n", rpos ) ) != std::string::npos )
                       ^
src/skeleton/editview.cpp:568:22: note: nlpos is initialized
        size_t nlpos = std::string::npos;
                     ^
src/skeleton/editview.cpp:571:24: note: nlpos is overwritten
        while( ( nlpos = text.rfind( "\n", rpos ) ) != std::string::npos )
                       ^
```
  • Loading branch information
ma8ma committed Jul 4, 2020
1 parent d8412ee commit 37427c5
Showing 1 changed file with 19 additions and 16 deletions.
35 changes: 19 additions & 16 deletions src/skeleton/editview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -561,25 +561,28 @@ void EditTextView::slot_convert_space()
}
else
{
size_t rpos = std::string::npos;
size_t nlpos = std::string::npos;
std::list<std::string> lines = MISC::get_lines( text );
for( std::string& line : lines ) {

// 改行前のスペースを取り除く
while( ( nlpos = text.rfind( "\n", rpos ) ) != std::string::npos )
{
if( nlpos == 0 ) break;
rpos = nlpos;
while( text[ rpos - 1 ] == ' ' ) rpos--;
text.erase( rpos, nlpos - rpos );
rpos--;
}
if( ! line.empty() ) {

// 行末のスペースを取り除く
line.erase( line.find_last_not_of( ' ' ) + 1 );

// 行頭のスペースを&nbsp;に変換する
if( line.front() == ' ' ) {
line.replace( 0, 1, "&nbsp;" );
}

// 最後のスペースを取り除く
rpos = text.length();
while( text[ rpos - 1 ] == ' ' ) rpos--;
text.erase( rpos, std::string::npos );
// 連続スペースを&nbsp;に変換する
converted.append( MISC::replace_str( line, " ", " &nbsp;" ) );
}

converted.push_back( '\n' );
}

converted = MISC::replace_str( text, " ", "&nbsp;" );
// 最後の改行を取り除く
converted.pop_back();
}

buffer->set_text( converted );
Expand Down

0 comments on commit 37427c5

Please sign in to comment.