mirror of
https://github.com/blupi-games/planetblupi
synced 2024-12-30 10:15:36 +01:00
Try to reverse/restore properly non LTR textes
This commit is contained in:
parent
ce4cdbcab5
commit
68b6ae2a33
26
src/text.cxx
26
src/text.cxx
@ -18,9 +18,9 @@
|
|||||||
* along with this program. If not, see http://gnu.org/licenses
|
* along with this program. If not, see http://gnu.org/licenses
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <regex>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <regex>
|
|
||||||
|
|
||||||
#include <SDL_ttf.h>
|
#include <SDL_ttf.h>
|
||||||
|
|
||||||
@ -129,17 +129,25 @@ public:
|
|||||||
|
|
||||||
std::string ReverseLatinWords (const std::string & text)
|
std::string ReverseLatinWords (const std::string & text)
|
||||||
{
|
{
|
||||||
std::regex re("([a-zA-Z0-9]+)");
|
std::regex re ("([a-zA-Z0-9.,-=_ \t()]{2,})");
|
||||||
std::string out;
|
std::string out;
|
||||||
std::string::const_iterator it = text.cbegin(), end = text.cend();
|
std::string::const_iterator it = text.cbegin (), end = text.cend ();
|
||||||
for (std::smatch match; std::regex_search(it, end, match, re); it = match[0].second)
|
for (std::smatch match; std::regex_search (it, end, match, re);
|
||||||
|
it = match[0].second)
|
||||||
{
|
{
|
||||||
out += match.prefix();
|
out += match.prefix ();
|
||||||
auto substr = match.str();
|
auto substr = match.str ();
|
||||||
std::reverse(substr.begin (), substr.end ());
|
std::reverse (substr.begin (), substr.end ());
|
||||||
|
std::replace (substr.begin (), substr.end (), '(', '$');
|
||||||
|
std::replace (substr.begin (), substr.end (), ')', '(');
|
||||||
|
std::replace (substr.begin (), substr.end (), '$', ')');
|
||||||
|
if (substr.back () == ' ' && substr.at (0) != ' ')
|
||||||
|
substr = ' ' + substr.substr (0, substr.length () - 1);
|
||||||
|
else if (substr.back () != ' ' && substr.at (0) == ' ')
|
||||||
|
substr = substr.substr (1) + ' ';
|
||||||
out += substr;
|
out += substr;
|
||||||
}
|
}
|
||||||
out.append(it, end);
|
out.append (it, end);
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user