Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use wide chars in remove_punctuations #78552

Merged
merged 1 commit into from
Dec 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions src/output.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1516,14 +1516,15 @@ std::string trim_trailing_punctuations( const std::string_view s )
} );
}

std::string remove_punctuations( const std::string_view s )
std::string remove_punctuations( const std::string &s )
{
std::string result;
std::remove_copy_if( s.begin(), s.end(), std::back_inserter( result ),
[]( unsigned char ch ) {
return std::ispunct( ch ) && ch != '_';
std::wstring ws = utf8_to_wstr( s );
std::wstring result;
std::remove_copy_if( ws.begin(), ws.end(), std::back_inserter( result ),
[]( wchar_t ch ) {
return std::iswpunct( ch ) && ch != '_';
} );
return result;
return wstr_to_utf8( result );
}

using char_t = std::string::value_type;
Expand Down
2 changes: 1 addition & 1 deletion src/output.h
Original file line number Diff line number Diff line change
Expand Up @@ -626,7 +626,7 @@ std::string trim( std::string_view s );
// Removes trailing periods and exclamation marks.
std::string trim_trailing_punctuations( std::string_view s );
// Removes all punctuation except underscore.
std::string remove_punctuations( std::string_view s );
std::string remove_punctuations( const std::string &s );
// Converts the string to upper case.
std::string to_upper_case( const std::string &s );

Expand Down
Loading