From b62668dc74343bc12e3e4f2d50ebba45eae3baef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=ADn=20Lucas=20Golini?= Date: Sun, 20 Oct 2024 13:15:45 -0300 Subject: [PATCH] Fix Linux build. --- include/eepp/core/string.hpp | 56 ++++------------------------- include/eepp/system/translator.hpp | 1 + src/eepp/core/string.cpp | 31 ++-------------- src/eepp/system/color.cpp | 7 ++-- src/tools/ecode/plugins/git/git.cpp | 8 ++--- 5 files changed, 16 insertions(+), 87 deletions(-) diff --git a/include/eepp/core/string.hpp b/include/eepp/core/string.hpp index df6ab3a22..87c280390 100644 --- a/include/eepp/core/string.hpp +++ b/include/eepp/core/string.hpp @@ -435,14 +435,10 @@ class EE_API String { **/ String(); - /** @brief Construct from a single ANSI character and a locale - ** The source character is converted to UTF-32 according - ** to the given locale. If you want to use the current global - ** locale, rather use the other constructor. + /** @brief Construct from a single ANSI character ** @param ansiChar ANSI character to convert - ** @param locale Locale to use for conversion **/ - String( char ansiChar, const std::locale& locale = std::locale() ); + String( char ansiChar ); #ifndef EE_NO_WIDECHAR /** @brief Construct from single wide character @@ -476,24 +472,6 @@ class EE_API String { **/ String( const std::string_view& utf8String ); - /** @brief Construct from a null-terminated C-style ANSI string and a locale - ** The source string is converted to UTF-32 according - ** to the given locale. If you want to use the current global - ** locale, rather use the other constructor. - ** @param ansiString ANSI string to convert - ** @param locale Locale to use for conversion - **/ - String( const char* ansiString, const std::locale& locale ); - - /** @brief Construct from an ANSI string and a locale - ** The source string is converted to UTF-32 according - ** to the given locale. If you want to use the current global - ** locale, rather use the other constructor. - ** @param ansiString ANSI string to convert - ** @param locale Locale to use for conversion - **/ - String( const std::string& ansiString, const std::locale& locale ); - #ifndef EE_NO_WIDECHAR /** @brief Construct from null-terminated C-style wide string ** @param wideString Wide string to convert @@ -545,19 +523,6 @@ class EE_API String { **/ operator std::string() const; - /** @brief Convert the unicode string to an ANSI string - ** The UTF-32 string is converted to an ANSI string in - ** the encoding defined by \a locale. If you want to use - ** the current global locale, see the other overload - ** of toAnsiString. - ** Characters that do not fit in the target encoding are - ** discarded from the returned string. - ** @param locale Locale to use for conversion - ** @return Converted ANSI string - ** @see toWideString, operator std::string - **/ - std::string toAnsiString( const std::locale& locale = std::locale() ) const; - #ifndef EE_NO_WIDECHAR /** @brief Convert the unicode string to a wide string ** Characters that do not fit in the target encoding are @@ -1010,28 +975,19 @@ EE::String is a utility string class defined mainly for convenience. It is a Unicode string (implemented using UTF-32), thus it can store any character in the world (european, chinese, arabic, hebrew, etc.). -It automatically handles conversions from/to ANSI and +It automatically handles conversions from/to UTF-8 and wide strings, so that you can work with standard string classes and still be compatible with functions taking a EE::String. @code EE::String s; -std::string s1 = s; // automatically converted to ANSI string +std::string s1 = s; // automatically converted to UTF-8 string String s2 = s; // automatically converted to wide string -s = "hello"; // automatically converted from ANSI string +s = "hello"; // automatically converted from UTF-8 string s = L"hello"; // automatically converted from wide string -s += 'a'; // automatically converted from ANSI string +s += 'a'; // automatically converted from UTF-8 string s += L'a'; // automatically converted from wide string @endcode -Conversions involving ANSI strings use the default user locale. However -it is possible to use a custom locale if necessary: -@code -std::locale locale; -EE::String s; -... -std::string s1 = s.toAnsiString(locale); -s = EE::String("hello", locale); -@endcode EE::String defines the most important functions of the standard std::string class: removing, random access, iterating, diff --git a/include/eepp/system/translator.hpp b/include/eepp/system/translator.hpp index 15e18adf2..4fe3f805b 100644 --- a/include/eepp/system/translator.hpp +++ b/include/eepp/system/translator.hpp @@ -2,6 +2,7 @@ #define EE_SYSTEM_STRINGLOCALERESOURCE_HPP #include +#include namespace pugi { class xml_node; diff --git a/src/eepp/core/string.cpp b/src/eepp/core/string.cpp index 6fcb50874..03b82c28e 100644 --- a/src/eepp/core/string.cpp +++ b/src/eepp/core/string.cpp @@ -1295,8 +1295,8 @@ void String::formatBuffer( char* Buffer, int BufferSize, const char* format, ... String::String() {} -String::String( char ansiChar, const std::locale& locale ) { - mString += Utf32::decodeAnsi( ansiChar, locale ); +String::String( char ansiChar ) { + mString += Utf32::decodeAnsi( ansiChar, std::locale() ); } #ifndef EE_NO_WIDECHAR @@ -1363,22 +1363,6 @@ String::String( const std::string_view& utf8String ) { Utf8::toUtf32( utf8String.begin() + skip, utf8String.end(), std::back_inserter( mString ) ); } -String::String( const char* ansiString, const std::locale& locale ) { - if ( ansiString ) { - std::size_t length = strlen( ansiString ); - if ( length > 0 ) { - mString.reserve( length + 1 ); - Utf32::fromAnsi( ansiString, ansiString + length, std::back_inserter( mString ), - locale ); - } - } -} - -String::String( const std::string& ansiString, const std::locale& locale ) { - mString.reserve( ansiString.length() + 1 ); - Utf32::fromAnsi( ansiString.begin(), ansiString.end(), std::back_inserter( mString ), locale ); -} - #ifndef EE_NO_WIDECHAR String::String( const wchar_t* wideString ) { if ( wideString ) { @@ -1502,17 +1486,6 @@ String::operator std::string() const { return toUtf8(); } -std::string String::toAnsiString( const std::locale& locale ) const { - // Prepare the output string - std::string output; - output.reserve( mString.length() + 1 ); - - // Convert - Utf32::toAnsi( mString.begin(), mString.end(), std::back_inserter( output ), 0, locale ); - - return output; -} - #ifndef EE_NO_WIDECHAR std::wstring String::toWideString() const { // Prepare the output string diff --git a/src/eepp/system/color.cpp b/src/eepp/system/color.cpp index 1580edea0..5683556bf 100644 --- a/src/eepp/system/color.cpp +++ b/src/eepp/system/color.cpp @@ -1,6 +1,7 @@ #include #include +#include #include #include #include @@ -606,8 +607,7 @@ Color Color::fromString( std::string str ) { Float alphaVal = 1; if ( functionString.getParameters().size() >= 4 ) { - if ( String::fromString( alphaVal, - functionString.getParameters().at( 3 ) ) ) { + if ( String::fromString( alphaVal, functionString.getParameters().at( 3 ) ) ) { alphaVal = eemax( eemin( 1.f, alphaVal ), 0.f ); } else { return Color::Transparent; @@ -663,8 +663,7 @@ Color Color::fromString( std::string str ) { Float alphaVal = 1; if ( functionString.getParameters().size() >= 4 ) { - if ( String::fromString( alphaVal, - functionString.getParameters().at( 3 ) ) ) { + if ( String::fromString( alphaVal, functionString.getParameters().at( 3 ) ) ) { alphaVal = eemax( eemin( 1.f, alphaVal ), 0.f ); } else { return Color::Transparent; diff --git a/src/tools/ecode/plugins/git/git.cpp b/src/tools/ecode/plugins/git/git.cpp index 6421465c4..12c61b38c 100644 --- a/src/tools/ecode/plugins/git/git.cpp +++ b/src/tools/ecode/plugins/git/git.cpp @@ -323,8 +323,8 @@ Git::CountResult Git::branchHistoryPosition( const std::string& localBranch, String::trimInPlace( buf ); auto results = String::split( buf, '\t' ); if ( results.size() == 2 ) { - int64_t behind = 0; - int64_t ahead = 0; + Int64 behind = 0; + Int64 ahead = 0; if ( String::fromString( ahead, results[0] ) && String::fromString( behind, results[1] ) ) { res.ahead = ahead; @@ -372,12 +372,12 @@ static void parseAheadBehind( std::string_view aheadBehind, Git::Branch& branch s = String::trim( s ); if ( String::startsWith( s, BEHIND ) ) { std::string numStr = std::string{ s.substr( BEHIND.size() ) }; - int64_t val = 0; + Int64 val = 0; if ( String::fromString( val, numStr ) ) branch.behind = val; } else if ( String::startsWith( s, AHEAD ) ) { std::string numStr = std::string{ s.substr( AHEAD.size() ) }; - int64_t val = 0; + Int64 val = 0; if ( String::fromString( val, numStr ) ) branch.ahead = val; }