Closed lushao1231 closed 2 years ago
As a supplement, there is a code table for utf8 case conversion:
THX !will fix it ASAP.
Hi, function StrToLwrExt()
seems too long and we need to implement a seperate function StrToUppExt()
to handle upper cases. Besides, it still cannnot cover all conversions according to the StackOverflow Q&A you have pointed out. Here I provide another solution using boost.locale
:
#include <iostream>
#include <string>
#include <boost/locale.hpp>
int main() {
boost::locale::generator gen;
std::locale loc = gen("");
std::locale::global(loc);
std::string s;
s = "yo recuerdos. no. estoy recordando. su unos cuatro, cinco años atrás., me tocó! participar en una convocación. que habÍan mos hecho en méxico a fa";
std::cout << "Original string :" << s << std::endl;
std::cout << " Lower string :" << boost::locale::to_lower(s) << std::endl;
std::cout << " Upper string :" << boost::locale::to_upper(s) << std::endl;
}
compile
g++ test.cc -L /usr/lib/x86_64-linux-gnu/ -lboost_locale
output:
Original string :yo recuerdos. no. estoy recordando. su unos cuatro, cinco años atrás., me tocó! participar en una convocación. que habÍan mos hecho en méxico a fa
Lower string :yo recuerdos. no. estoy recordando. su unos cuatro, cinco años atrás., me tocó! participar en una convocación. que habían mos hecho en méxico a fa
Upper string :YO RECUERDOS. NO. ESTOY RECORDANDO. SU UNOS CUATRO, CINCO AÑOS ATRÁS., ME TOCÓ! PARTICIPAR EN UNA CONVOCACIÓN. QUE HABÍAN MOS HECHO EN MÉXICO A FA
that's a good point!
Another solution:
#include <iostream>
#include <string>
#include <locale>
#include <codecvt>
int main() {
std::locale loc("");
std::wstring_convert<std::codecvt_utf8<wchar_t>, wchar_t> converter;
std::string s = "GRÜSSEN grüßen ß yo recuerdos. no. estoy recordando. su unos cuatro, cinco años atrás., me tocó! participar en una convocación. que habÍan mos hecho en méxico a fa";
// string to wstring
std::wstring ws = converter.from_bytes(s);
// wstring to string
std::cout << "Original string :" << converter.to_bytes(ws) << std::endl;
for (auto &c : ws) {
c = std::tolower(c, loc);
}
// wstring to string
std::cout << " Lower string :" << converter.to_bytes(ws) << std::endl;
for (auto &c : ws) {
c = std::toupper(c, loc);
}
// wstring to string
std::cout << " Upper string :" << converter.to_bytes(ws) << std::endl;
}
output:
Original string :yo recuerdos. no. estoy recordando. su unos cuatro, cinco años atrás., me tocó! participar en una convocación. que habÍan mos hecho en méxico a fa
Lower string :yo recuerdos. no. estoy recordando. su unos cuatro, cinco años atrás., me tocó! participar en una convocación. que habían mos hecho en méxico a fa
Upper string :YO RECUERDOS. NO. ESTOY RECORDANDO. SU UNOS CUATRO, CINCO AÑOS ATRÁS., ME TOCÓ! PARTICIPAR EN UNA CONVOCACIÓN. QUE HABÍAN MOS HECHO EN MÉXICO A FA
Hi @xingchensong You have to manage exceptions for converter or else, you will get a crash from from_bytes() "If this wstring_convert object was constructed without a user-supplied wide-error string, throws [std::range_error] on conversion failure." Regards
Hi @xingchensong You have to manage exceptions for converter or else, you will get a crash from from_bytes() "If this wstring_convert object was constructed without a user-supplied wide-error string, throws [std::range_error] on conversion failure." Regards
Thx, could you make a PR for this?
Describe the bug Wenet outputs capitalized accented letters: e.g., yo recuerdos. no. estoy recordando. su unos cuatro, cinco aÑos atrÁs., me tocÓ! participar en una convocaciÓn. que habÍan mos hecho en mÉxico a fa
To Reproduce Steps to reproduce the behavior: Accented letters don't work in general. Sending spanish audio clips to wenet is one way to reproduce it.
Expected behavior yo recuerdos. no. estoy recordando. su unos cuatro, cinco años atrás., me tocó! participar en una convocación. que habÍan mos hecho en méxico a fa
Additional context a fix for this issue:
2 changes:
[ runtime/core/utils/string.cc ]
[ runtime/server/x86/CMakeLists.txt ]
2 new files:
[ runtime/core/utils/utf8_lower.h ]
[ runtime/core/utils/utf8_lower.cc ]