Advertisement
Guest User

Untitled

a guest
Jun 26th, 2017
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.79 KB | None | 0 0
  1. void Unaccentify(std::wstring& str)
  2. {
  3.     static std::map<TCHAR, TCHAR> unaccentMap;
  4.     static bool init = false;
  5.     if (!init)
  6.     {
  7.         unaccentMap.insert(std::pair<TCHAR,TCHAR>(_T('à'),_T('a')));
  8.         unaccentMap.insert(std::pair<TCHAR,TCHAR>(_T('é'),_T('e')));
  9.         unaccentMap.insert(std::pair<TCHAR,TCHAR>(_T('ë'),_T('e')));
  10.         unaccentMap.insert(std::pair<TCHAR,TCHAR>(_T('ù'),_T('u')));
  11.         // ....
  12.         init = true;
  13.     }
  14.    
  15.     std::map<TCHAR, TCHAR>::iterator mapEnd = unaccentMap.end();
  16.     for (std::wstring::iterator it = str.begin(), end = str.end(); it != end; ++it)
  17.     {
  18.         std::map<TCHAR, TCHAR>::iterator mapIt = unaccentMap.find(*it);
  19.         if ( mapIt != mapEnd)
  20.         {
  21.             *it = mapIt->second;
  22.         }
  23.     }
  24. }
  25.  
  26. void main()
  27. {
  28.     std::wstring str = _T("De l'été à Noël où va-t-on?");
  29.     Unaccentify(str);
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement